Top Banner
49

DDAY2014 - Features per Drupal 8

Jul 13, 2015

Download

Technology

drupalday
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: DDAY2014 - Features per Drupal 8

From Drupal 7 to Drupal 8

Features vs. ConfigurationManagement

Andrea [email protected]

Antonio De [email protected]

0

Page 2: DDAY2014 - Features per Drupal 8

Nuvole

a 100% Drupal company

Page 3: DDAY2014 - Features per Drupal 8

✈ Our Distributed Team

Italy Belgium CzechRepublic

Page 4: DDAY2014 - Features per Drupal 8

ὄ� Our Clients

Page 5: DDAY2014 - Features per Drupal 8

Ὃ� Our Projects

International organisations

Institutions

Fast delivery: several developers working simultaneouslyon the same site

Frequent configuration changes: need for safe updates

Page 6: DDAY2014 - Features per Drupal 8

Challenges We Face

Remote collaboration on site development

Keeping track of all configuration changes duringdevelopment

Pushing upgrades to production sites

Page 7: DDAY2014 - Features per Drupal 8

Chapter 1

ἱ� ἱ� ἱ� ἱ� ἱ�The Evolution of

Code-Driven Developmentin Drupal 8

Page 8: DDAY2014 - Features per Drupal 8

� The long march to a "code-driven" Drupal

Historically, Drupal has kept both configuration andcontent in the same database. Every time you click in the administrative interface, no record is kept.

Drupal 6: Features appears, with the possibility to exportconfiguration to PHP code

Drupal 7: Features support is mature, but still relying onthird parties and incomplete

Drupal 8: Configuration and content are separated,configuration is text-based

Page 9: DDAY2014 - Features per Drupal 8

The database-driven

workflow disadvantages

Default in Drupal 6 and Drupal 7 (core)

Standard approach: you click, you save, Drupal saves todatabase and forgets

Bad: Mixing configuration and content

Bad: Losing track of configuration changes

Theoretically still possible in Drupal 8!

Page 10: DDAY2014 - Features per Drupal 8

The Features-driven

workflow disadvantages

A structural flaw: to package configuration into modules,you need to make it exportable to "code"

Features is very good for packaging, not as good forexporting; but there's no packaging without exporting

Not everything is exportable/traceable

You must "whitelist" elements to be tracked: you neverhave the whole site under control

Page 11: DDAY2014 - Features per Drupal 8

Code-driven is not just

Features

It’s a global technical choice

For example, it includes makefiles and profiles, stillapplicable in D8

Keywords: text-based configuration, traceability,repeatability, reuse

Page 12: DDAY2014 - Features per Drupal 8

Ἲ�New in Drupal 8

Configuration Management

Page 13: DDAY2014 - Features per Drupal 8

Ἲ�A guided example of

Configuration Management

Page 14: DDAY2014 - Features per Drupal 8

Ἲ�Reference Use Case

Modify the configuration of a production site:

Keeping the site online all the time.

Developing/testing the new configuration on adevelopment copy.

Exporting the configuration changes from developmentand importing them into production.

Page 15: DDAY2014 - Features per Drupal 8

Ἲ� Step 1 of 6

Clone Site to Dev

Production

Install Site

Full backup:Database

Full Drupal tree

Files

Development

Restore the backup

Page 16: DDAY2014 - Features per Drupal 8

Ἲ� Step 2 of 6

Modify Configuration

Production

Site operates normally:new users

new content

Development

Page 17: DDAY2014 - Features per Drupal 8

Ἲ� Step 3 of 6

Export Configuration

Production

Site operates normally:new users

new content

Development

Page 18: DDAY2014 - Features per Drupal 8

Ἲ� Step 4 of 6

Import into Staging

Production Development

Page 19: DDAY2014 - Features per Drupal 8

Ἲ� Step 5 of 6

Review Changes

Production Development

Page 20: DDAY2014 - Features per Drupal 8

Ἲ� Step 6 of 6

Apply Changes

Production Development

Page 21: DDAY2014 - Features per Drupal 8

How this would haveworked in Drupal 7

Clone site to development environment

Create a feature exporting the site name variable

Development: update the feature

Transfer the feature to Production

Production: enable/revert the feature

Page 22: DDAY2014 - Features per Drupal 8

drushDRUpal SHell: everybody loves!

Drupal 8 ⇔ drush 7

Both not stable yet

A new installation method: composer

Page 23: DDAY2014 - Features per Drupal 8

Ἲ� Step 3 of 6 — Drush Style

Export Configuration

Development

$ drush config-exportThe current contents of your export directory(sites/default/files/config_H6raw/staging) will be deleted. (y/n): yConfiguration successfully exported to [success]sites/default/files/config_H6raw/staging.

Page 24: DDAY2014 - Features per Drupal 8

Ἲ� Step 5 of 6 — Drush Style

Review Changes

Production

$ drush config-import --preview=diffConfiguration successfully exported to /tmp/drush_tmp_xy. [success]diff -u /tmp/drush_tmp_xy/system.site.yml sites/.../staging/system.site.yml--- /tmp/drush_tmp_xy/system.site.yml+++ sites/default/files/config_H6raw/staging/system.site.yml@@ -1,5 +1,5 @@ uuid: ca04efa4-51bf-4d12-8b00-e7b244b97aef-name: 'Drupal 8'+name: 'Amsterdam - alpha15' mail: [email protected] slogan: '' page:Import the listed configuration changes? (y/n):

Page 25: DDAY2014 - Features per Drupal 8

Chapter 2

Inner workings of

Configuration Managementand Features

Page 26: DDAY2014 - Features per Drupal 8

Use case

Features

A collection of logicallyrelated Drupal elements

Packaged into PHP code,using hooks

Exportability is aprecondition to packaging

Configuration Management

Reference for the whole siteconfiguration, development to

production

Page 27: DDAY2014 - Features per Drupal 8

Ὄ� Configuration format

PHP

Imperative

InterpretedCan break site if corrupted

Located in folders formodules

Treated as modules

YAML

Declarative

ParsedCannot break anything if corrupted

Located in specific foldersfor config

Treated as data (like Rules'JSON in D7)

Page 28: DDAY2014 - Features per Drupal 8

Support

Optional

Modules must offer supportfor Features

No guarantees

Mandatory

Core configuration

The only way to supplyconfiguration

Page 29: DDAY2014 - Features per Drupal 8

ὒ� Configuration andmodules

Drupal 7

Features are specialmodules

Once a Feature is enabled,its configuration is trackedforever

Drupal 8

Modules provide initialvalues

In this sense, every moduleis a Feature

Configuration is decoupledfrom modules afterinstallation

Page 30: DDAY2014 - Features per Drupal 8

Components selection

Drupal 7

Explicitly listed in info file

Rest is not tracked

Drupal 8

All configuration is tracked

Configuration is saved perconfig entity

Can be individuallyimported/exported

Config synchronisationrequires all files to bepresent (missing = deleted)

Page 31: DDAY2014 - Features per Drupal 8

Configuration staging

Drupal 7

Feature states: normal,overridden, needs review

Operations: featuresupdate/revert

Diff available

Drupal 8

Active store and stagingstore (multiple storespossible)

Operations: import andexport

Diff available

Page 32: DDAY2014 - Features per Drupal 8

Drush workflow

Drupal 7

drush features-update

drush features-revert

Drupal 8 (with drush 7.x-dev)

drush cex

drush cim

Page 33: DDAY2014 - Features per Drupal 8

Ἴ� ⚽Cross-site compatibility

Drupal 7

Write once, deployanywhere

A feature is ready to bedeployed on multiple sites

Drupal 8

Specific to multipleinstances (dev, prod) of thesame site

This is the CMI use case

Configuration Managementrelies on UUIDs

Page 34: DDAY2014 - Features per Drupal 8

Ὁ�Boundaries of configuration

Drupal 7

Entities through entity api,CTools plugins

Variables with Strongarm

Content withfeatures_uuidMenu links, custom andcontrib modules can beproblematic

Drupal 8

Configuration

Content

State

All clearly defined

Page 35: DDAY2014 - Features per Drupal 8

� � �Features done right?

Drupal 7

Not optimal

A bit "forced" at times sinceit is not native in Drupal 7

Drupal 8

Clean

Native

Not as powerful asD7+Features yet

Page 36: DDAY2014 - Features per Drupal 8

Chapter 3

How to build

Re-usable components

Page 37: DDAY2014 - Features per Drupal 8

Contrib module:

Configuration development

1. Automated import of configuration files into the activestorage.

2. Automated export of configuration objects into files.

https://www.drupal.org/project/config_devel

Page 38: DDAY2014 - Features per Drupal 8

config_devel & drush

nuvole_article.info.yml

config_devel: - field.instance.node.article.field_image - field.storage.node.field_image - node.type.article

drush

$ drush config-devel-export-module nuvole_article

Page 39: DDAY2014 - Features per Drupal 8

Features 8.x-3.x

Goes back to the core mission of Features: packagefunctionality for re-use.

No more project specific features!

Under development in sandbox

Page 40: DDAY2014 - Features per Drupal 8

Other considerations

config_devel can also “import” configuration, onlyimportant during development of a re-usable feature

Room for another drush extension that re-installs thedefault config.

Page 41: DDAY2014 - Features per Drupal 8

Chapter 4

Ἱ�Configuration Management

For Developers

Page 42: DDAY2014 - Features per Drupal 8

An overview

Page 43: DDAY2014 - Features per Drupal 8

⇆ API import

The Config namespace configuration must always beimported/exported through the API, never edit the files!

The filesystem is not a good option, and this is the reasonfor Drupal 8 to store the active config in database bydefault:

Performance

Safety

Security

Page 44: DDAY2014 - Features per Drupal 8

⚙Configurables in Drupal 8

ConfigEntityBase class

Two namespaces: one for config, one for content

Page 45: DDAY2014 - Features per Drupal 8

⚙Working with configuration

Reading and writing configuration

// Get site name. $site_name = \Drupal::config('system.site')->get('name');// Set site name.\Drupal::config('system.site')->set('name', 'My site')->save();

⛼variable_get() and variable_set() died.

Page 46: DDAY2014 - Features per Drupal 8

⚙Information about the

system state

instance-specific? (e.g., last cron run) → state

configuration? (e.g., site mail) → config

Site = filesystem + content + configuration + state

Page 47: DDAY2014 - Features per Drupal 8

⚙Working with states

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);

Page 48: DDAY2014 - Features per Drupal 8

⚙Overriding "on the fly"

The $conf array is still available as $configUseful in settings.local.php: Differentiate development and production environment

Page 49: DDAY2014 - Features per Drupal 8

ὄ�Thank you!