Content | Configuration | State | |
---|---|---|---|
author: | editors, users, REST | site builders, developers | drupal, scripts etc |
env: | live/production site | development site | independent |
example: | nodes, terms, users | node types, views, site name | last cron run |
config
core module.standard
installation profile.YAML
files, one per configuration object.system.site.yml
uuid: d1329a45-acab-4599-bce9-972d6707b1e6
name: 'Drupal 8'
mail: [email protected]
slogan: ''
page:
403: ''
404: ''
front: /node
admin_compact_mode: false
weight_select_max: 100
langcode: en
default_langcode: en
_core:
default_config_hash: yXadRE77Va-G6dxhd2kPYapAvbnSvTF6hO4oXiOEynI
The active store is in the database by default.
The sync store is in the filesystem.
sites/default/settings.php
$config_directories = array(
CONFIG_SYNC_DIRECTORY => '/directory/outside/webroot',
);
Configure it so that it is git-versioned and protected.
core.entity_view_display.node.article.default.yml
dependencies:
config:
- field.field.node.article.body
- field.field.node.article.comment
- field.field.node.article.field_image
- field.field.node.article.field_tags
- node.type.article
module:
- comment
- image
- text
- user
config/install
sub-directory.config/optional
directory.views.schema.yml
(from Views module)
...
views.view.*:
type: config_entity
label: 'View'
Meaning: a module can provide a default view in a file named views.view.frontpage.yml
.
Files with this naming pattern (views.view.*
) are installed only if/when
the Views module is enabled.
Site operates normally:
Site operates normally:
$ drush cex
Differences of the active config to the export directory:
Collection Config Operation
system.site update
The .yml files in your export directory (config/sync) will be deleted and replaced with the active config. (y/n):
Then $ git commit && git push
$ git pull
Development goes on normally.
$ drush config-import --preview=diff
Only in config/sync: .htaccess
...
uuid: d1329a45-acab-4599-bce9-972d6707b1e6
-name: 'localhost'
+name: 'Drupal 8'
mail: [email protected]
slogan: ''
page:
Import the listed configuration changes? (y/n):
Development goes on normally.
$ drush cim
Collection Config Operation
system.site update
Import the listed configuration changes? (y/n):
Development goes on normally.
Configuration items, as seen from PHP, can be either:
\Drupal\Core\Config\ConfigBase
\Drupal\Core\Config\Entity\ConfigEntityBase
$config = \Drupal::config('system.site');
$config = \Drupal::configFactory()->getEditable('system.site');
$conf
array is still available as $config
settings.local.php
:
$config['system.logging']['error_level'] = 'verbose';
$config
or GUI) overrides it.
$config['system.site']['name'] = 'New title';
$original = \Drupal::config('system.site')->getOriginal('name', FALSE);
// Returns "Drupal 8".
$overridden = \Drupal::config('system.site')->get('name');
// Returns "New title".
Reading and writing states
// Get last cron run timestamp.
$time = \Drupal::state()->get('system.cron_last');
// Set cron run timestamp.
\Drupal::state()->set('system.cron_last', REQUEST_TIME);
config/development/configuration/features
rather than under structure.Project A
Production
Staging
Development
← features →
Project B
Production
Staging
Development
config_installer
profile available.$ drush config-export
$ git add && git commit
$ drush config-export
$ git push
$ git add && git commit
$ git push
!*?$*(%!)
$ git pull
$ drush config-import
$ drush config-export
master
branch.drush updatedb
.drush cim
.drush entup
.Important: the order must be respected.
An issue on d.o will enforce it.
Note: this assumes no configuration changes on production.
Options for developer's sanity:
settings.php
in production:
$settings['config_readonly'] = TRUE;
devel
module only in development environment.\Drupal\Core\Config\Importer\MissingContentEvent
.
/**
* Executes an update which is intended to update data, like entities.
*
* These updates are executed after all hook_update_N() implementations.
* At this stage Drupal is already fully repaired so you can use any API
* as you wish.
*/
function hook_post_update_NAME(&$sandbox) {}
config_installer: install site from existing config.
config_readonly: locks any configuration changes via UI.
config_update: report changes between original and active config of a module.
config_devel: module helps with developing configuration.
config_tools: automatically commit config changes to git.
features: bundle config for re-use on different site, ideal for distributions.