Upload
alexander-tkachev
View
183
Download
1
Tags:
Embed Size (px)
Citation preview
Background: types of information
• Content
• Session
• State
• Configuration
• Simple Configuration
• Configuration Entities
Directories are empty by default. Active configuration is stored in the database for security and speed reasons.
Where configuration lives
How to move under Git: simplest way -> remove "/files" best practice -> outside Drupal root
// file: settings.php
$config_directories['active'] = 'sites/default/files/config_XXXX/active'; $config_directories['staging'] = 'sites/default/files/config_XXXX/staging';
# file: system.site.yml
uuid: c78fd9aa-b327-4514-9d00-bc72a1f40f27 name: 'My cool site' mail: [email protected] slogan: 'Drupal 8 rules!' page: 403: '' 404: '' front: node admin_compact_mode: false weight_select_max: 100 langcode: en
The same with Drush
$ drush config-export The current contents of your export directory (sites/default/config_XXXX/staging) will be deleted. (y/n): y Configuration successfully exported to sites/default/config_XXXX/staging. [success]
$ drush config-import Collection Config Operation system.site update Import the listed configuration changes? (y/n): y The configuration was imported successfully. [success]
# file: system.site.yml
uuid: c78fd9aa-b327-4514-9d00-bc72a1f40f27 name: 'My cool site' mail: [email protected] slogan: 'Drupal 8 rules!' page: 403: '' 404: '' front: node admin_compact_mode: false weight_select_max: 100 langcode: en
$config = \Drupal::config('system.site'); // Instance of Drupal\Core\Config\Config $front_page = $config->get('page.front'); // 'node'
$config = \Drupal::config('system.site'); // Instance of Drupal\Core\Config\Config $front_page = $config->get('page.front'); // 'node' $page_settings = $config->get('page'); // array(// '403' => '',// '404' => '',// 'front' => 'node',// )
$config = \Drupal::config('system.site'); // Instance of Drupal\Core\Config\Config $front_page = $config->get('page.front'); // 'node' $page_settings = $config->get('page'); // array(// '403' => '',// '404' => '',// 'front' => 'node',// ) $config->set('page.front', 'my-front-page'); $config->save();
your_module config install your_module.settings.yml views.view.my_cool_view.yml
Module/theme defaults
Configuration override levels:
1. settings.php
2. modules:
• overrides are provided by services tagged as config.factory.override (implementing ConfigFactoryOverrideInterface)
Get raw (not overridden) data:
1. ConfigFormBase::config() \Drupal::config()
2. Config::getRawData()
3. \Drupal::configFactory()->setOverrideState(FALSE);
React on simple config changes:
• ConfigEvents(SAVE, DELETE, IMPORT etc.)
• hook_config_import_steps_alter() (for complicated workflows like fields)
# file: core/modules/system/config/install/system.maintenance.yml message: '@site is currently under maintenance. We should be back shortly. Thank you for your patience.' langcode: en
# file: core/modules/system/config/install/system.maintenance.yml message: '@site is currently under maintenance. We should be back shortly. Thank you for your patience.' langcode: en # file: core/modules/system/config/schema/system.schema.yml system.maintenance: type: mapping label: 'Maintenance mode' mapping: message: type: text label: 'Message to display when in maintenance mode' langcode: type: string label: 'Default language'
# file: core/modules/system/config/install/system.maintenance.yml message: '@site is currently under maintenance. We should be back shortly. Thank you for your patience.' langcode: en # file: core/modules/system/config/schema/system.schema.yml system.maintenance: type: mapping label: 'Maintenance mode' mapping: message: type: text label: 'Message to display when in maintenance mode' langcode: type: string label: 'Default language' # file: core/config/schema/core.data_types.schema.yml text: type: string label: 'Text' translatable: true # ... string: class: '\Drupal\Core\TypedData\Plugin\DataType\String' label: 'String'
# file: core/modules/system/config/install/system.maintenance.yml message: '@site is currently under maintenance. We should be back shortly. Thank you for your patience.' langcode: en # file: core/modules/system/config/schema/system.schema.yml system.maintenance: type: mapping label: 'Maintenance mode' mapping: message: type: text label: 'Message to display when in maintenance mode' langcode: type: string label: 'Default language' # file: core/config/schema/core.data_types.schema.yml text: type: string label: 'Text' translatable: true # ... string: class: '\Drupal\Core\TypedData\Plugin\DataType\String' label: 'String'
# file: core/modules/system/config/install/system.maintenance.yml message: '@site is currently under maintenance. We should be back shortly. Thank you for your patience.' langcode: en # file: core/modules/system/config/schema/system.schema.yml system.maintenance: type: mapping label: 'Maintenance mode' mapping: message: type: text label: 'Message to display when in maintenance mode' langcode: type: string label: 'Default language' # file: core/config/schema/core.data_types.schema.yml text: type: string label: 'Text' translatable: true # ... string: class: '\Drupal\Core\TypedData\Plugin\DataType\String' label: 'String'
Modules:
https://www.drupal.org/project/config_tools
https://www.drupal.org/project/config_devel
https://www.drupal.org/project/config_readonly
https://www.drupal.org/project/config_inspector
Вопросы?
Leksat@AmazeeLabs*DrupalCampMsk2014
• This presentation http://bit.ly/d8-configuration
• Configuration API docshttps://www.drupal.org/developing/api/8/configuration
• Drupal core updateshttps://groups.drupal.org/core/updates