SlideShare a Scribd company logo
1 of 24
Download to read offline
Configuration entities
in Drupal 8.
Eugene Kulishov Adyax 2015
What we will speak about?
●
Innovations in Entity Api.
●
Configuration manager in Drupal 8
●
Examples of use of configuration entities
●
Creation of custom Config Entity on the
example of Config Pages module
Types of information in Drupal 8
Content State Session Configuration
Config API Configuration Entity API
Status of modules
Site name
Content types
Image styles
Configuration entities in Drupal 8
●
Views
●
Fields
●
Content types
●
Image styles
●
Display settings
●
Blocks
●
Role
●
Taxonomy vocabulary
●
Date format
●
Comment type
●
Text format
●
Date format
Configuration Manager interface
Configuration Manager interface
YAML format structure
node.type.page.yml
uuid: a0025874-17ec-4ad2-a300-0af31a8a462b
langcode: en
status: true
dependencies: { }
name: 'Basic page'
type: page
description: 'Use <em>basic pages</em> for your static
content, such as an ''About us'' page.'
help: ''
new_revision: false
preview_mode: 1
display_submitted: false
Configuration installation
File:
core.entity_view_mode.comment.simple_comment.yml
langcode: en
status: false
dependencies:
module:
- comment
id: comment.simple_comment
label: 'My simple comment'
targetEntityType: comment
cache: true
Config API code examples
<?php
// Get data from config.
$config = Drupal::config('system.site');
// Instance of DrupalCoreConfigImmutableConfig
$front_page = $config->get('page.front');
// /user/login
$front_page = Drupal::config('system.site')->get('page.front');
// /user/login
// Save data to config.
$config = Drupal::service('config.factory')
->getEditable('system.site');
// Instance of DrupalCoreConfigConfig
$config->set('page.front', 'new-front-page');
$config->save();
Main stages of creation
●
Definition of scheme and interface
●
Basic defenition of the class
●
We expand opportunities: add listing of
object, add CRUD forms
●
Removing of configuration entity
Schema of Configuration entity
File: config_pages.schema.yml
config_pages.type.*:
type: config_entity
label: 'Config page type settings'
mapping:
id:
type: string
label: 'ID'
label:
type: label
label: 'Label'
Basic definition of the class
File: ConfigPagesType.php
namespace Drupalconfig_pagesEntity;
use DrupalCoreConfigEntityConfigEntityBundleBase;
/**
* @ConfigEntityType(
* id = "config_pages_type",
* admin_permission = "administer config_pages types",
* label = @Translation("Config page type"),
* config_prefix = "type",
* entity_keys = {
* "id" = "id",
* "label" = "label",
* "context" = "context",
* "menu" = "menu"
* },
* )
*/
class ConfigPagesType extends ConfigEntityBundleBase implements ConfigPagesTypeInterface {
/**
* The config page type ID.
*/
protected $id;
/**
* The config page type label.
*/
protected $label;
}
Listing of Config Entity
File: ConfigPagesType.php
* handlers = {
* "list_builder" =
* "Drupalconfig_pagesConfigPagesTypeListBuilder"
* },
File: config_pages.routing.yml
entity.config_pages_type.collection:
path: '/admin/structure/config_pages/types'
defaults:
_entity_list: 'config_pages_type'
_title: 'Config Pages Types'
requirements:
_permission: 'administer config_pages entity'
ConfigPagesTypeListBuilder class
<?php
namespace Drupalconfig_pages;
use DrupalCoreConfigEntityConfigEntityListBuilder;
use DrupalCoreEntityEntityInterface;
/**
* Defines a class to build a listing of custom config page type entities.
*/
class ConfigPagesTypeListBuilder extends ConfigEntityListBuilder {
/**
* Changes list of operation.
*/
public function getDefaultOperations(EntityInterface $entity) {...}
/**
* Changes for header
*/
public function buildHeader() {...}
/**
* Changes for row.
*/
public function buildRow(EntityInterface $entity) {...}
/**
* {@inheritdoc}
*/
protected function getTitle() {...}
}
Listing of ConfigPagesType objects
Path: /admin/structure/config_pages/types
Management forms of Config Entity
●
Creating a new class ConfigPagesTypeForm,
describing the form
●
Add class to definition of Configuration Entity
●
Add new route to config_pages.routing.yml
●
Add new local action for adding new Configuration
object
ConfigPagesTypeForm class
File: ConfigPagesTypeForm.php
namespace Drupalconfig_pages;
use DrupalCoreEntityEntityForm;
use DrupalCoreEntityEntityTypeInterface;
use DrupalCoreFormFormStateInterface;
/**
* Base form for config_pages edit forms.
*/
class ConfigPagesTypeForm extends EntityForm {
/**
* Required routes rebuild.
*/
protected $routesRebuildRequired = FALSE;
/**
* Form definition.
*/
public function form(array $form, FormStateInterface $form_state) {...}
/**
* Form validation.
*/
public function validateForm(array &$form, FormStateInterface $form_state) {...}
/**
* Form save.
*/
public function save(array $form, FormStateInterface $form_state) {...}
}
Annotation of Configuration Entity
* handlers = {
* "form" = {
* "default" = "Drupalconfig_pagesConfigPagesTypeForm",
* "add" = "Drupalconfig_pagesConfigPagesTypeForm",
* "edit" = "Drupalconfig_pagesConfigPagesTypeForm",
* "delete" =
* "Drupalconfig_pagesFormConfigPagesTypeDeleteForm"
* },
* "list_builder" =
* "Drupalconfig_pagesConfigPagesTypeListBuilder"
* },
Routes with forms
File: config_pages.routing.yml
entity.config_pages_type.edit_form:
path: '/admin/structure/config_pages/types/manage/{config_pages_type}'
defaults:
_entity_form: 'config_pages_type.edit'
_title: 'Edit'
requirements:
_entity_access: 'config_pages_type.update'
options:
_admin_route: TRUE
entity.config_pages_type.delete_form:
path: '/admin/structure/config_pages/types/manage/{config_pages_type}/delete'
defaults:
_entity_form: 'config_pages_type.delete'
_title: 'Delete'
requirements:
_entity_access: 'config_pages_type.delete'
options:
_admin_route: TRUE
Edit Form example
Path: admin/structure/config_pages/types/manage/my_custom_page
Local action add
File: config_pages.links.action.yml
config_pages_type_add:
route_name: config_pages.type_add
title: 'Add config page'
appears_on:
- entity.config_pages_type.collection
Listing of configuration objects
Path: /admin/structure/config_pages/types
Configuration API Code examples
<?php
$config_name = 'config_pages.type.my_custom_page';
$config = Drupal::service('config.factory')
->getEditable($config_name);
// Instance of DrupalCoreConfigConfig
$config = Drupal::config($config_name);
// Instance of DrupalCoreConfigImmutableConfig
$object =
Drupalconfig_pagesEntityConfigPagesType::load('my_custom
_page');
Thanks!

More Related Content

What's hot

Introduction to ZendX jQuery
Introduction to ZendX jQueryIntroduction to ZendX jQuery
Introduction to ZendX jQuery
dennisdc
 
Twitter bootstrap
Twitter bootstrapTwitter bootstrap
Twitter bootstrap
dennisdc
 

What's hot (20)

Migrating to-Drupal-8 by Bryan Manalo
Migrating to-Drupal-8 by Bryan ManaloMigrating to-Drupal-8 by Bryan Manalo
Migrating to-Drupal-8 by Bryan Manalo
 
Drupal 8: Entities
Drupal 8: EntitiesDrupal 8: Entities
Drupal 8: Entities
 
Introducing jQuery
Introducing jQueryIntroducing jQuery
Introducing jQuery
 
JQuery
JQueryJQuery
JQuery
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Introduction to ZendX jQuery
Introduction to ZendX jQueryIntroduction to ZendX jQuery
Introduction to ZendX jQuery
 
Css Selectors
Css SelectorsCss Selectors
Css Selectors
 
Web internship Yii Framework
Web internship  Yii FrameworkWeb internship  Yii Framework
Web internship Yii Framework
 
Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)Intro to IndexedDB (Beta)
Intro to IndexedDB (Beta)
 
Twitter bootstrap
Twitter bootstrapTwitter bootstrap
Twitter bootstrap
 
Angular Restmod (english version)
Angular Restmod (english version)Angular Restmod (english version)
Angular Restmod (english version)
 
Jquery Basics
Jquery BasicsJquery Basics
Jquery Basics
 
Drupal Field API. Practical usage
Drupal Field API. Practical usageDrupal Field API. Practical usage
Drupal Field API. Practical usage
 
Field api.From d7 to d8
Field api.From d7 to d8Field api.From d7 to d8
Field api.From d7 to d8
 
Drupal Development
Drupal DevelopmentDrupal Development
Drupal Development
 
Yii in action
Yii in actionYii in action
Yii in action
 
Java script
Java scriptJava script
Java script
 
Drupal 8: Forms
Drupal 8: FormsDrupal 8: Forms
Drupal 8: Forms
 
AngularJS Directives
AngularJS DirectivesAngularJS Directives
AngularJS Directives
 
"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин"Android Data Binding в массы" Михаил Анохин
"Android Data Binding в массы" Михаил Анохин
 

Similar to Configuration Entities in Drupal 8

C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
cummings49
 
Asp Net Advance Topics
Asp Net Advance TopicsAsp Net Advance Topics
Asp Net Advance Topics
Ali Taki
 

Similar to Configuration Entities in Drupal 8 (20)

Config management
Config managementConfig management
Config management
 
Webform and Drupal 8
Webform and Drupal 8Webform and Drupal 8
Webform and Drupal 8
 
C# .NET Developer Portfolio
C# .NET Developer PortfolioC# .NET Developer Portfolio
C# .NET Developer Portfolio
 
Django Vs Rails
Django Vs RailsDjango Vs Rails
Django Vs Rails
 
KAAccessControl
KAAccessControlKAAccessControl
KAAccessControl
 
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and SimpleDrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
DrupalJam 2018 - Maintaining a Drupal Module: Keep It Small and Simple
 
Олексій Калініченко — Configuration Management in Drupal8
Олексій Калініченко — Configuration Management in Drupal8Олексій Калініченко — Configuration Management in Drupal8
Олексій Калініченко — Configuration Management in Drupal8
 
Drupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.comDrupal 7 entities & TextbookMadness.com
Drupal 7 entities & TextbookMadness.com
 
8 things to know about theming in drupal 8
8 things to know about theming in drupal 88 things to know about theming in drupal 8
8 things to know about theming in drupal 8
 
Odoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo FrameworkOdoo Experience 2018 - Develop an App with the Odoo Framework
Odoo Experience 2018 - Develop an App with the Odoo Framework
 
Customizing User Profiles
Customizing User ProfilesCustomizing User Profiles
Customizing User Profiles
 
Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes Drupal 7 Theming - Behind the scenes
Drupal 7 Theming - Behind the scenes
 
Drupal 8 Hooks
Drupal 8 HooksDrupal 8 Hooks
Drupal 8 Hooks
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Drupal 8 configuration management
Drupal 8 configuration managementDrupal 8 configuration management
Drupal 8 configuration management
 
Rapid Prototyping with PEAR
Rapid Prototyping with PEARRapid Prototyping with PEAR
Rapid Prototyping with PEAR
 
Asp Net Advance Topics
Asp Net Advance TopicsAsp Net Advance Topics
Asp Net Advance Topics
 
Drupal 8 Services
Drupal 8 ServicesDrupal 8 Services
Drupal 8 Services
 
Django cheat sheet
Django cheat sheetDjango cheat sheet
Django cheat sheet
 

Recently uploaded

Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Monica Sydney
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
JOHNBEBONYAP1
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Monica Sydney
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
F
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Monica Sydney
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
ydyuyu
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
pxcywzqs
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
ayvbos
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
ydyuyu
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
ayvbos
 

Recently uploaded (20)

2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
2nd Solid Symposium: Solid Pods vs Personal Knowledge Graphs
 
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
best call girls in Hyderabad Finest Escorts Service 📞 9352988975 📞 Available ...
 
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girlsRussian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
Russian Call girls in Abu Dhabi 0508644382 Abu Dhabi Call girls
 
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdfpdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
pdfcoffee.com_business-ethics-q3m7-pdf-free.pdf
 
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu DhabiAbu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
Abu Dhabi Escorts Service 0508644382 Escorts in Abu Dhabi
 
一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理一比一原版奥兹学院毕业证如何办理
一比一原版奥兹学院毕业证如何办理
 
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi EscortsIndian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
Indian Escort in Abu DHabi 0508644382 Abu Dhabi Escorts
 
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
APNIC Policy Roundup, presented by Sunny Chendi at the 5th ICANN APAC-TWNIC E...
 
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查在线制作约克大学毕业证(yu毕业证)在读证明认证可查
在线制作约克大学毕业证(yu毕业证)在读证明认证可查
 
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
一比一原版(Offer)康考迪亚大学毕业证学位证靠谱定制
 
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
一比一原版(Flinders毕业证书)弗林德斯大学毕业证原件一模一样
 
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
20240510 QFM016 Irresponsible AI Reading List April 2024.pdf
 
APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53APNIC Updates presented by Paul Wilson at ARIN 53
APNIC Updates presented by Paul Wilson at ARIN 53
 
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime BalliaBallia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
Ballia Escorts Service Girl ^ 9332606886, WhatsApp Anytime Ballia
 
Best SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency DallasBest SEO Services Company in Dallas | Best SEO Agency Dallas
Best SEO Services Company in Dallas | Best SEO Agency Dallas
 
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency""Boost Your Digital Presence: Partner with a Leading SEO Agency"
"Boost Your Digital Presence: Partner with a Leading SEO Agency"
 
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call GirlsMira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
Mira Road Housewife Call Girls 07506202331, Nalasopara Call Girls
 
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
原版制作美国爱荷华大学毕业证(iowa毕业证书)学位证网上存档可查
 
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
call girls in Anand Vihar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
一比一原版(Curtin毕业证书)科廷大学毕业证原件一模一样
 

Configuration Entities in Drupal 8

  • 1. Configuration entities in Drupal 8. Eugene Kulishov Adyax 2015
  • 2. What we will speak about? ● Innovations in Entity Api. ● Configuration manager in Drupal 8 ● Examples of use of configuration entities ● Creation of custom Config Entity on the example of Config Pages module
  • 3. Types of information in Drupal 8 Content State Session Configuration Config API Configuration Entity API Status of modules Site name Content types Image styles
  • 4. Configuration entities in Drupal 8 ● Views ● Fields ● Content types ● Image styles ● Display settings ● Blocks ● Role ● Taxonomy vocabulary ● Date format ● Comment type ● Text format ● Date format
  • 7. YAML format structure node.type.page.yml uuid: a0025874-17ec-4ad2-a300-0af31a8a462b langcode: en status: true dependencies: { } name: 'Basic page' type: page description: 'Use <em>basic pages</em> for your static content, such as an ''About us'' page.' help: '' new_revision: false preview_mode: 1 display_submitted: false
  • 8. Configuration installation File: core.entity_view_mode.comment.simple_comment.yml langcode: en status: false dependencies: module: - comment id: comment.simple_comment label: 'My simple comment' targetEntityType: comment cache: true
  • 9. Config API code examples <?php // Get data from config. $config = Drupal::config('system.site'); // Instance of DrupalCoreConfigImmutableConfig $front_page = $config->get('page.front'); // /user/login $front_page = Drupal::config('system.site')->get('page.front'); // /user/login // Save data to config. $config = Drupal::service('config.factory') ->getEditable('system.site'); // Instance of DrupalCoreConfigConfig $config->set('page.front', 'new-front-page'); $config->save();
  • 10. Main stages of creation ● Definition of scheme and interface ● Basic defenition of the class ● We expand opportunities: add listing of object, add CRUD forms ● Removing of configuration entity
  • 11. Schema of Configuration entity File: config_pages.schema.yml config_pages.type.*: type: config_entity label: 'Config page type settings' mapping: id: type: string label: 'ID' label: type: label label: 'Label'
  • 12. Basic definition of the class File: ConfigPagesType.php namespace Drupalconfig_pagesEntity; use DrupalCoreConfigEntityConfigEntityBundleBase; /** * @ConfigEntityType( * id = "config_pages_type", * admin_permission = "administer config_pages types", * label = @Translation("Config page type"), * config_prefix = "type", * entity_keys = { * "id" = "id", * "label" = "label", * "context" = "context", * "menu" = "menu" * }, * ) */ class ConfigPagesType extends ConfigEntityBundleBase implements ConfigPagesTypeInterface { /** * The config page type ID. */ protected $id; /** * The config page type label. */ protected $label; }
  • 13. Listing of Config Entity File: ConfigPagesType.php * handlers = { * "list_builder" = * "Drupalconfig_pagesConfigPagesTypeListBuilder" * }, File: config_pages.routing.yml entity.config_pages_type.collection: path: '/admin/structure/config_pages/types' defaults: _entity_list: 'config_pages_type' _title: 'Config Pages Types' requirements: _permission: 'administer config_pages entity'
  • 14. ConfigPagesTypeListBuilder class <?php namespace Drupalconfig_pages; use DrupalCoreConfigEntityConfigEntityListBuilder; use DrupalCoreEntityEntityInterface; /** * Defines a class to build a listing of custom config page type entities. */ class ConfigPagesTypeListBuilder extends ConfigEntityListBuilder { /** * Changes list of operation. */ public function getDefaultOperations(EntityInterface $entity) {...} /** * Changes for header */ public function buildHeader() {...} /** * Changes for row. */ public function buildRow(EntityInterface $entity) {...} /** * {@inheritdoc} */ protected function getTitle() {...} }
  • 15. Listing of ConfigPagesType objects Path: /admin/structure/config_pages/types
  • 16. Management forms of Config Entity ● Creating a new class ConfigPagesTypeForm, describing the form ● Add class to definition of Configuration Entity ● Add new route to config_pages.routing.yml ● Add new local action for adding new Configuration object
  • 17. ConfigPagesTypeForm class File: ConfigPagesTypeForm.php namespace Drupalconfig_pages; use DrupalCoreEntityEntityForm; use DrupalCoreEntityEntityTypeInterface; use DrupalCoreFormFormStateInterface; /** * Base form for config_pages edit forms. */ class ConfigPagesTypeForm extends EntityForm { /** * Required routes rebuild. */ protected $routesRebuildRequired = FALSE; /** * Form definition. */ public function form(array $form, FormStateInterface $form_state) {...} /** * Form validation. */ public function validateForm(array &$form, FormStateInterface $form_state) {...} /** * Form save. */ public function save(array $form, FormStateInterface $form_state) {...} }
  • 18. Annotation of Configuration Entity * handlers = { * "form" = { * "default" = "Drupalconfig_pagesConfigPagesTypeForm", * "add" = "Drupalconfig_pagesConfigPagesTypeForm", * "edit" = "Drupalconfig_pagesConfigPagesTypeForm", * "delete" = * "Drupalconfig_pagesFormConfigPagesTypeDeleteForm" * }, * "list_builder" = * "Drupalconfig_pagesConfigPagesTypeListBuilder" * },
  • 19. Routes with forms File: config_pages.routing.yml entity.config_pages_type.edit_form: path: '/admin/structure/config_pages/types/manage/{config_pages_type}' defaults: _entity_form: 'config_pages_type.edit' _title: 'Edit' requirements: _entity_access: 'config_pages_type.update' options: _admin_route: TRUE entity.config_pages_type.delete_form: path: '/admin/structure/config_pages/types/manage/{config_pages_type}/delete' defaults: _entity_form: 'config_pages_type.delete' _title: 'Delete' requirements: _entity_access: 'config_pages_type.delete' options: _admin_route: TRUE
  • 20. Edit Form example Path: admin/structure/config_pages/types/manage/my_custom_page
  • 21. Local action add File: config_pages.links.action.yml config_pages_type_add: route_name: config_pages.type_add title: 'Add config page' appears_on: - entity.config_pages_type.collection
  • 22. Listing of configuration objects Path: /admin/structure/config_pages/types
  • 23. Configuration API Code examples <?php $config_name = 'config_pages.type.my_custom_page'; $config = Drupal::service('config.factory') ->getEditable($config_name); // Instance of DrupalCoreConfigConfig $config = Drupal::config($config_name); // Instance of DrupalCoreConfigImmutableConfig $object = Drupalconfig_pagesEntityConfigPagesType::load('my_custom _page');