Олексій Калініченко — configuration management in drupal8

15
Configuration Management in Drupal8 What configuration is, and what other types of information exist in Drupal 8: Configuration, Content, Session, State.

Upload: ledc-2016

Post on 22-Jan-2017

47 views

Category:

Internet


0 download

TRANSCRIPT

Page 1: Олексій Калініченко — Configuration Management in Drupal8

Configuration Management in Drupal8

What configuration is, and what other types of information exist in Drupal 8:

Configuration, Content, Session, State.

Page 2: Олексій Калініченко — Configuration Management in Drupal8

LvivDrupalCamp2016 Oleksiy Kalinichenko

CTO @ InternetDevels https://www.facebook.com/oleksiy.kalinichenkoSkype: AexCheckerMail: [email protected]

Page 3: Олексій Калініченко — Configuration Management in Drupal8

An introduction● Configuration is the information about your site that is not content and is

meant to be more permanent, such as the name of your site, the content types, fields, and views you have defined.

● Content is the information meant to be displayed on your site, such as articles, basic pages, images, files, and so on.

● Session is the information about an individual user's interactions with the site, such as whether they are logged in.

● State is information of a temporary nature about the current state of your site. Examples include the time when Cron was last run, whether node access permissions need rebuilding, and so on.

Page 4: Олексій Калініченко — Configuration Management in Drupal8

https://en.wikipedia.org/wiki/Configuration_management

Page 5: Олексій Калініченко — Configuration Management in Drupal8

Why manage configuration?● It's simple to explain why configuration that is only saved in the database is

bad. You can't keep track of any changes (who made what change, and when); it's hard to work with a group of people (you simply can't get their changes without using their SQL dump, and using their dump would delete your work); and, if you build something on a development environment, how do you get it to the live site? You get the gist. We want our configuration in files, and Drupal 8 gives us just that.

● Before Drupal 8, a variety of methods were used to transport configuration from one environment to another — for example, from a development environment to a production environment.

Page 6: Олексій Калініченко — Configuration Management in Drupal8

Meaningful commit messagesCommit messages are a very important part of your code documentation when working with version control. When looking for something that was done in the past, you will first scan through the commit messages, as shown in the following screenshot:

Page 7: Олексій Калініченко — Configuration Management in Drupal8

Meaningful branchesTickets that require a lot of work should be worked on in a separate branch. When you name that branch, make sure you use your ticket ID at the beginning—for instance, 1234-publications , as shown in the following screenshot:

Page 8: Олексій Калініченко — Configuration Management in Drupal8

A look back at Drupal 7● Manual Configuration Management

● The hook_install()/hook_update_N() function

● The Features module

● Storing configuration variables in settings.php

Page 9: Олексій Калініченко — Configuration Management in Drupal8

Drupal 8's Take on Configuration Management

Page 10: Олексій Калініченко — Configuration Management in Drupal8

Config files

Page 11: Олексій Калініченко — Configuration Management in Drupal8

Learning the difference between active and staging directories#services.yml (file name)services:

# Override configuration storage.config.storage:

class: Drupal\Core\Config\CachedStoragearguments: ['@config.storage.active', '@cache.config']

config.storage.active:# Use file storage for active configuration.alias: config.storage.file

Page 12: Олексій Калініченко — Configuration Management in Drupal8

The Configuration Management APIDrupal 7, system.admin.inc:

<?php// The status message depends on whether an admin // theme is currently in use: a value of 0 means the admin // theme is set to be the default theme.

$admin_theme = variable_get('admin_theme', 0);

...

// Set the default theme.variable_set('theme_default', $theme);

?>

Drupal 8:

<?php// The status message depends on whether an admin theme // is currently in use: a value of 0 means the admin theme is // set to be the default theme.

$admin_theme = \Drupal::config('system.theme')->get('admin');

...

// Set the default theme.\Drupal::configFactory()

->getEditable('system.theme')->set('default', $theme)->save();

?>

Page 13: Олексій Калініченко — Configuration Management in Drupal8

Best practices<?php

\Drupal::configFactory()->getEditable('system.theme')->set('admin', 'seven')->save();

\Drupal::configFactory()->getEditable('system.theme')->set('default', 'bartik')->save();

?>

<?php// Load the editable configuration object.$config = \Drupal::configFactory

->getEditable('system.theme');

// Set value of first configuration item.$config->set('admin', 'seven');

// Set another value.$config->set('default', 'bartik');

// Save changes back to configuration storage.$config->save();

?>

Page 14: Олексій Калініченко — Configuration Management in Drupal8

Overriding the configuration#services.yml

cm_example.config_factory_override:class: Drupal\cm_example\Config\ExampleConfigFactoryOverridearguments: ['@config.storage', '@event_dispatcher', '@config.typed']tags: - { name: config.factory.override, priority: 10 }

/** * Provides custom overrides for the configuration factory. */class ExampleConfigFactoryOverride implements ConfigFactoryOverrideInterface { public function loadOverrides($names) {

$overrides = array(); if (in_array('system.site', $names)) { $overrides['system.site'] = ['name' => 'Customized site name'];

}return $overrides;

}….