Skip to content

Instantly share code, notes, and snippets.

So I think that we're breaking an important principle here... that config should return the data in an identical format to what you provided. At Barcelona @merlinofchaos said that CMI should be a dumb as possible and I think that here we are breaking that maxim.
Just because FAPI returns everything as strings is not a reason to go ahead here. We can leave all the simple config as strings if we want or we can use the schema (if available) to save typed config. But config entities should be allowed to save their data in the types stored on the object.
<?php
$context = new \Drupal\Core\Config\Context\ConfigContext($this->event_dispatcher);
$context->set('locale.language', WHATEVER_LANGCODE);
$this->configFactory->enterContext($context);
@alexpott
alexpott / gist:5161620
Created March 14, 2013 14:10
Array to object conversion...
+function field_create_field(array $field) {
+ $field = entity_create('field_entity', $field);
+ $field->save();
return $field;
}
@alexpott
alexpott / gist:5161576
Created March 14, 2013 14:04
Field CMI moving from objects to arrays...
function hook_field_attach_purge(\Drupal\Core\Entity\EntityInterface $entity, $field, $instance) {
// find the corresponding data in mymodule and purge it
- if ($entity->entityType() == 'node' && $field->field_name == 'my_field_name') {
+ if ($entity->entityType() == 'node' && $field['field_name'] == 'my_field_name') {
mymodule_remove_mydata($entity->nid);
}
}
@alexpott
alexpott / gist:3589386
Created September 1, 2012 22:21
drush breaking due to config.canonical
Fatal error: Uncaught exception 'Exception' with message 'The configuration directory type <em class="placeholder">active</em> does not exist.' in /Users/alex/dev/sites/drupal8alt.dev/core/includes/bootstrap.inc on line 496
Exception: The configuration directory type <em class="placeholder">active</em> does not exist. in /Users/alex/dev/sites/drupal8alt.dev/core/includes/bootstrap.inc on line 496
Call Stack:
0.0004 709584 1. {main}() /Users/alex/dev/drush5/drush.php:0
0.0152 5153000 2. drush_main() /Users/alex/dev/drush5/drush.php:14
0.0608 12112608 3. _drush_bootstrap_and_dispatch() /Users/alex/dev/drush5/drush.php:59
0.0779 12123136 4. drush_dispatch() /Users/alex/dev/drush5/drush.php:90
0.1052 12142080 5. call_user_func_array() /Users/alex/dev/drush5/includes/command.inc:165