Slide 1

Slide 1 text

CONFIGURING ALL CONFIGURING ALL THE THINGS! THE THINGS! By Oliver Davies (@opdavies)

Slide 2

Slide 2 text

CONFIGURATION MANAGEMENT CONFIGURATION MANAGEMENT DRUPAL 8 DRUPAL 8

Slide 3

Slide 3 text

Web Developer, System Administrator Senior Developer at Microserve Part-time freelancer Acquia certified Drupal 8 Grand Master Drupal 7 and 8 core contributor @opdavies www.oliverdavies.uk

Slide 4

Slide 4 text

WHAT IS WHAT IS CONFIGURATION? CONFIGURATION?

Slide 5

Slide 5 text

WHAT IS CONFIGURATION? WHAT IS CONFIGURATION? Site settings (site name, front page path) Content types URL alias patterns API keys Date formats Which modules are enabled Block placements Field configuration and storage Paragraphs Image styles Taxonomy vocabularies User roles and permissions Views

Slide 6

Slide 6 text

THE CONFIGURATION MANAGEMENT THE CONFIGURATION MANAGEMENT INITIATIVE INITIATIVE

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

FEATURES FEATURES IN CORE IN CORE

Slide 9

Slide 9 text

FEATURES FEATURES IN CORE IN CORE

Slide 10

Slide 10 text

USING USING CONFIGURATION CONFIGURATION

Slide 11

Slide 11 text

Slide 12

Slide 12 text

get('page.front');

Slide 13

Slide 13 text

config = $config_factory->get('system.site'); } public function index() { $result = $this->config->get('page.front'); ... } }

Slide 14

Slide 14 text

IMPORTING AND EXPORTING IMPORTING AND EXPORTING CONFIGURATION CONFIGURATION

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

$ drush config-export $ drush config-import

Slide 20

Slide 20 text

$ drush config:export $ drush config:import

Slide 21

Slide 21 text

$ drupal config:export $ drupal config:export:single $ drupal config:import

Slide 22

Slide 22 text

Slide 23

Slide 23 text

Slide 24

Slide 24 text

DEMO DEMO

Slide 25

Slide 25 text

OVERRIDING OVERRIDING CONFIGURATION CONFIGURATION

Slide 26

Slide 26 text

Slide 27

Slide 27 text

Slide 28

Slide 28 text

SPLITTING SPLITTING CONFIGURATION CONFIGURATION

Slide 29

Slide 29 text

DGO.TO/ DGO.TO/CONFIG_SPLIT CONFIG_SPLIT

Slide 30

Slide 30 text

CONFIGURATION SPLIT CONFIGURATION SPLIT Different configuration directories One per 'split' Configuration per environment Active split set in settings.php

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

Slide 34

Slide 34 text

IGNORING IGNORING CONFIGURATION CONFIGURATION

Slide 35

Slide 35 text

DGO.TO/ DGO.TO/CONFIG_IGNORE CONFIG_IGNORE

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

ADDING CONFIGURATION TO YOUR ADDING CONFIGURATION TO YOUR CUSTOM MODULES CUSTOM MODULES

Slide 38

Slide 38 text

# config/install/override_node_options.settings.yml general_permissions: true specific_permissions: true

Slide 39

Slide 39 text

# config/schema/override_node_options.schema.yml override_node_options.settings: type: config_object label: 'Override Node Options settings' mapping: general_permissions: type: boolean label: 'Use general permissions.' specific_permissions: type: boolean label: 'Use content type specific permissions.'

Slide 40

Slide 40 text

// src/Form/SettingsForm.php class SettingsForm extends ConfigFormBase { ... public function buildForm(array $form, FormStateInterface $form_state) { $form = parent::buildForm($form, $form_state); $config = $this->config('override_node_options.settings'); $form['general_permissions'] = [ '#type' => 'checkbox', '#title' => $this->t('General permissions, across all node types'), '#default_value' => $config->get('general_permissions'), ]; $form['specific_permissions'] = [ '#type' => 'checkbox', '#title' => $this->t('Specific permissions, for each individual node type'), '#default_value' => $config->get('specific_permissions'), ]; return $form; } ... }

Slide 41

Slide 41 text

// src/Form/SettingsForm.php class SettingsForm extends ConfigFormBase { ... public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); $this->config('override_node_options.settings') ->set('general_permissions', $form_state->getValue('general_permissions')) ->set('specific_permissions', $form_state->getValue('specific_permissions')) ->save(TRUE); } }

Slide 42

Slide 42 text

// src/NodePermissions.php class NodePermissions { ... public function nodeTypePermissions() { $permissions = []; $config = \Drupal::config('override_node_options.settings'); if ($config->get('general_permissions')) { $this->addGeneralPermissions($permissions); } if ($config->get('specific_permissions')) { $this->addSpecificPermissions($permissions); } return $permissions; } ...

Slide 43

Slide 43 text

INSTALLING FROM AN EXISTING INSTALLING FROM AN EXISTING CONFIGURATION CONFIGURATION

Slide 44

Slide 44 text

DGO.TO/ DGO.TO/CONFIG_INSTALLER CONFIG_INSTALLER

Slide 45

Slide 45 text

The Configuration Installer project provides a means to install a Drupal 8 site using existing configuration. This is not a module, Configuration Installer is an installation profile that loads configuration from a specified folder to 'install' the site. This is not a real installation profile either, it helps to install a real installation profile (e.g. minimal) along with an existing set of configuration

Slide 46

Slide 46 text

CMI CMI 2.0 2.0

Slide 47

Slide 47 text

Drupal 8's built-in config system is a HUGE step forward. However, now that the community has a couple of years of building Drupal 8 sites behind them, various limitations have surfaced: various common workflows are not natively supported; core's config APIs have missing functionality. While many of these problems have contrib workarounds, often these solutions can conflict with one another, and there's no one set of best practices that works for all

Slide 48

Slide 48 text

DGO.TO/ DGO.TO/CMI2 CMI2

Slide 49

Slide 49 text

QUESTIONS? QUESTIONS?

Slide 50

Slide 50 text

THANKS! THANKS! @OPDAVIES @OPDAVIES WWW.OLIVERDAVIES.UK WWW.OLIVERDAVIES.UK