D8 Config Split - pierregermain/MyDrupal GitHub Wiki

Config Split

Usa Config Split para manejar configuraciones entre sites y entornos.

Más info:

Dependencias

Config Split 1.7:

  • drush9 (no drush 10)
  • drupal/config_filter version 8.x-1.7+2-dev (no 2.2.0)

el composer json, sus require se quedan asi

        "drupal/config_filter": "1.x-dev",
        "drupal/config_split": "^1.7",

Primeros pasos

En este apartado explico cómo exportar todas las configuraciones a default y a continuación cóömo crear un split.

1. Exportar default

Exportar todo hacia "default" con drush cex (sin tener ningún split activado). Sólo debemos tener activado las cosas que van a estar activas en TODOS los sites.

2. Instalar config split

Instalar config split

3. Crear un split

Crear un split en modo desactivado.

Dicho split al hacer drush cex va quedar exportado cómo config_split.config_split.misplit.yml

Importante: Al split default le vamos a poner un peso de -1 para que los demas splits sobre escriban default.

4. Configurar el split:

Complete Split

Exporta a mi split las configuraciones seleccionadas. Usado por ejemplo para el módulo devel. Si en mi split devel esta activado => va estar activado si el split está activado.

En el yml file se queda tal que así para el caso de módulos:

module: {  }

Para el caso de configuraciones individuales se queda en el siguiente registro:

blacklist: { }

Una vez realizado el drush cex se te queda asi:

module:
  devel: 0
theme: {  }
blacklist: {  }
graylist:
  - system.site
graylist_dependents:

Ejemplo: Quiero activar un módulo en un split

Pasos:

  1. Instala el módulo
  2. Haz el complete split para dicho módulo desde la UI. Mira que esté bien configurado cada split. Por ejemplo si quiero activar Views UI en mi split llamado Local, me voy a Config Split UI, abro el Split Local y activo el check de Views UI en la parte del Complete Split.
  3. Haz drush cex. El módulo sólo debe estar activo para el split que seleccionaste. Cool!

Conditional Split

Sólo exporta a mi split si he cambiado la configuración que está seleccionada. Usado por ejemplo para system.site.yml

Esto en el yml file se queda registrado en el siguiente registro:

graylist: {  }

5. Crear carpetas

El split está desactivado. Lo activaremos por el settings.php

Creamos las carpetas de los splits en nuestro sistema de ficheros

6. Weight

Podemos asignar un peso a cada split para que se ejecuten en orden. Así el que mas peso tenga se ejecutará más tarde y será el que más tenga

Estructura de las carpetas de configuración

Primero creamos la estructura de las carpetas

config
├── environments (Folder for environments split)
│   └── (???) base (Folder for base configurations shared between all sites)
│   └── local (Specific configurations for local environment shared between all sites.)
└── sites
    ├── mysite.es (Specific configurations for mysite.es site)
    ├── mysite.valencia (Specific configurations for mysite.valencia site)
    └── base (Base configurations shared between all sites)

Importante: Cuando vayas a /admin/config/development/configuration/config-split todos los splits deben estar "Inactive".

Lo que hacemos es activar cada configuración desde el settings.php

Activar una configuración pragmáticamente

Cada sites o entorno tiene su propio settings.php donde poder activar / desactivar configuraciones (splits) al antojo:

Por ejemplo para activar el split de dev en el settings.php debemos tener la siguiente línea:

$config['config_split.config_split.dev']['status'] = TRUE;

Cuando limpies las cachés verás en la pantalla de administración del config split "active (overriden)" para la configuración que hayas activado desde el settings.php

Ejemplo: Configuraciones para Live

En Live solemos tener webforms y formularios custom. Estos no los queremos exportar en configuraciones.

Para que ciertas configuraciones se excluyan podemos crear un split llamada "excluded".

Desde la UI le decimos:

  • que "files to exclude / greylist" sea webform.webform.* y contact.form.*
  • no checkamos "Include dependent configuration for graylist"
  • si checkamos " Split graylist only when different"

Para activar el split llamado "excluded" metemos en el settings la siguiente línea:

$config['config_split.config_split.excluded']['status'] = TRUE;

En Live, ahora para hacer import de las configs se haría así:

drush cex #debería ignorar los excluded y meterlos al folder "excluded"
drush cim #debería ignorar los excluded al importar

Si en local creas nuevos webforms y tienes el split "exluded" no activado podrás importar dichos webforms en Live.

Crear una nueva configuración

Imaginemos que tenemos las siguientes carpetas creadas:

├── sync
    └── base
    └── admin

Imaginemos que queremos crear una nueva configuración para "admin". Desde la UI de config Split le damos a "+Add Configuration Split Setting". Valores a ser rellenados antes de guardar:

Label: admin
Active: Debe estar desactivado
Folder: ../config/sync/admin

Una vez guardado, nos vamos al settings.php y activamos la configuración agregando:

$config['config_split.config_split.admin']['status'] = TRUE;

Ahora, si borras las cachés tendrás que ver en la UI de config split para admin el valor "active (overriden)"

Base Configurations

This is where lives the main configurations.

It corresponds to:

  • the base configurations shared between all sites
  • the "common" sync directory of a Drupal site (see variable $config_directories['sync'])

Site Specific Configurations

  • Specific configurations per site are handle with Config Split module.

  • Each site has its own "split" if necessary. To activate it, on the settings.php check that the split is active:

    $config['config_split.config_split.mysplit']['status'] = TRUE;
    

Environment Specific Configurations

  • Specific configurations per environment are handle with Config Split module.

  • Each environment has its own "split" if necessary. To activate it, on the settings.php check that the split is active:

    $config['config_split.config_split.mysplit']['status'] = TRUE;
    

Ignored Configurations

  • To allow the client to contribute some specific part, the concerned configurations are ignored using the Config Ignore module.

  • If you need default values to be installed you need to have the configuration yml file placed in the synchronization directory and you need to commit it.

  • If this file is ignored by Config Ignore module it will be installed only during the module installation with drush cim.

  • During the module installation process, the files under mymodule/config are ignored, only the files under the sync directory are taken into account.

Examples

I Added a field shared by all sites

Just do as you usually do!

  • Add your field on a site
  • Export the config drush --uri=mysite config:export
  • The configuration files should be on the base configurations folder config/sync/base

Added a field shared by all sites with different default values according to the site

If you want to add a field shared by all sites with different default values according to the site. We talk about default values without translation.

This will be a little bit more complicated:

  • Add your field on a site: do not set the default value for the moment or set a default value that could be shared between all sites.
  • Export the config drush --uri=mysite config:export
  • The configuration files should be on the base configurations folder config/sync/base
  • For the site that needs a specific default value:
    • Update the config split configuration for the concerned site: add the concerned configurations files to the black list.
    • Update the default value of your field
    • Export the config drush --uri=mysite config:export
    • The configuration files should be on the site specific configurations folder config/sync/mysite. The config split configuration should be on the base configurations folder config/sync/base

Enabled a module for all sites

  • Enable the module on a site
  • Export the config drush --uri=mysite config:export
  • The configuration files should be on the base configurations folder config/sync/base
  • Import the config for the others sites
  • For each site run:
    $ drush --uri=mysite locale-check
    $ drush --uri=mysite locale-update
    $ drush --uri=mysite config:export
    
  • If you have finished just import the config for each site to be sure all sites are correctly synchronized.