This document discusses configuration entities in Drupal 8. It provides examples of using the configuration manager interface to manage configuration objects like content types, image styles, and blocks through YAML files. It also demonstrates how to create a custom configuration entity type called ConfigPagesType with its own schema, class definition, listing builder, and forms for adding and editing entities of that type.
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
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
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() {...}
}
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) {...}
}