2. who are we?
Kristof De Jaeger
@swentel
co-maintainer of Field API
Lead maintainer of Display Suite
Developer @ Wunderkraut
Friday 16 August 13
3. who are we?
Gábor Hojtsy
@gaborhojtsy
Multilingual Initiative owner
Long time Drupal Core contributor
Number one employee @ Acquia
Friday 16 August 13
6. What problems are we
trying to solve?
• Variable soup
Live
Save
textSetting 1
Setting 2 label
Database Database
Dev
TEST
test test test test
test test test test
test test test test
test test
node/4admin/config/foo
Welcome
This is real
content on the
live site that end
users are viewing
node/4
Save
old textSetting 1
Setting 2 label
admin/config/foo
Friday 16 August 13
7. Live
Save
textSetting 1
Setting 2 label
Database Database
Dev
TEST
test test test test
test test test test
test test test test
test test
node/4admin/config/foo
Welcome
This is real
content on the
live site that end
users are viewing
node/4
Save
old textSetting 1
Setting 2 label
admin/config/foo
Danger!
Want to bring over configuration
changes from dev, but not
overwrite live content!
What problems are we
trying to solve?
Friday 16 August 13
8. What problems are we
trying to solve?
variable_set()/variable_get()
ctools_export_object()/
ctools_export_load_object()
db_select()/db_update()/
db_delete()
$conf[...];
hook_update_N()
drush fu
http://www.flickr.com/photos/bean/322616749
napkins
Friday 16 August 13
10. The solution
• Files using theYAML specification
• Active and staging directory
• Cached in the database using a standard
cache interface
Friday 16 August 13
26. • system_settings_form is dead
• add your own submit callback
• you are responsible for saving configuration
• ship with default configuration file
simple settings
Friday 16 August 13
34. */
class Category extends ConfigEntityBase {
/**
* The category ID.
*/
public $id;
/**
* The category UUID.
*/
public $uuid;
/**
* The category label.
*/
public $label;
/**
* List of recipient e-mail addresses.
*/
public $recipients = array();
/**
* An auto-reply message to send to the message author.
*/
public $reply = '';
/**
* Weight of this category (used for sorting).
*/
public $weight = 0;
}
Friday 16 August 13
51. class ConfigGlobalOverrideSubscriber implements
EventSubscriberInterface {
static function getSubscribedEvents() {
$events['config.init'][] = array('configInit',
30);
return $events;
}
public function configInit(ConfigEvent $event) {
global $conf;
$config = $event->getConfig();
if (isset($conf[$config->getName()])) {
$config->setOverride($conf[$config->getName()]);
}
}
}
Global overrides
Friday 16 August 13
52. Break out of contexts
// Enter the override-free context, so we can ensure no
overrides are applied.
config_context_enter('config.context.free');
// Get system site maintenance message text from the original
config.
$message = config('system.maintenance')->get('message');
// Leave the override-free context.
config_context_leave();
Friday 16 August 13
53. Get into contexts
// Enter a user specific context.
$context = config_context_enter("DrupaluserUserConfigContext");
// Set the account to use on the context.
$context->setAccount($account);
$mail_config = config('user.mail');
// Do stuff...
config_context_leave();
Friday 16 August 13
59. Basic data types for configuration
undefined:
label: 'Undefined'
class: 'DrupalCoreConfigSchemaProperty'
mapping:
label: Mapping
class: 'DrupalCoreConfigSchemaMapping'
sequence:
label: Sequence
class: 'DrupalCoreConfigSchemaSequence'
Friday 16 August 13
60. Simple extended data types
# Human readable string that must be plain text and editable
with a text field.
label:
type: string
label: 'Label'
# Internal Drupal path
path:
type: string
label: 'Path'
# Human readable string that can contain multiple lines of text
or HTML.
text:
type: string
label: 'Text'
Friday 16 August 13
61. Complex extended data type
# Mail text with subject and body parts.
mail:
type: mapping
label: "Mail"
mapping:
"subject":
type: text
label: "Subject"
"body":
type: text
label: "Body"
Friday 16 August 13
65. Advice for module
developers
• Config key names should have meaning
• Use config entities instead of tables
• Include config schema
Friday 16 August 13