diff --git a/configuration.module b/configuration.module index cf0bd5d..8936b60 100644 --- a/configuration.module +++ b/configuration.module @@ -39,6 +39,7 @@ function configuration_configuration_handlers() { 'menu' => '\Drupal\configuration\Config\MenuConfiguration', 'menu_link' => '\Drupal\configuration\Config\MenuLinkConfiguration', 'ctools' => '\Drupal\configuration\Config\CtoolsConfiguration', + 'entity' => '\Drupal\configuration\Config\EntityApiConfiguration', 'views' => '\Drupal\configuration\Config\ViewConfiguration', 'strongarm' => '\Drupal\configuration\Config\StrongarmConfiguration', 'page_manager' => '\Drupal\configuration\Config\PageManagerHandlerConfiguration', diff --git a/lib/Drupal/configuration/Config/EntityApiConfiguration.php b/lib/Drupal/configuration/Config/EntityApiConfiguration.php index 91916d5..730d72b 100644 --- a/lib/Drupal/configuration/Config/EntityApiConfiguration.php +++ b/lib/Drupal/configuration/Config/EntityApiConfiguration.php @@ -33,6 +33,13 @@ class EntityApiConfiguration extends Configuration { } /** + * Overrides Drupal\configuration\Config\Configuration::getStorageSystem(). + */ + static protected function getStorageSystem($component) { + return '\Drupal\configuration\Storage\StorageEntityApi'; + } + + /** * Overrides Drupal\configuration\Config\Configuration::getStorageInstance(). */ static protected function getStorageInstance($component) { @@ -54,9 +61,13 @@ class EntityApiConfiguration extends Configuration { * Overrides Drupal\configuration\Config\Configuration::getComponentHumanName(). */ static public function getComponentHumanName($component, $plural = FALSE) { - module_load_include('inc', 'entity', 'entity.features'); - $components = entity_features_api(); - return $components[$component]['name']; + $entity_info = entity_crud_get_info(); + if ($plural && !empty($entity_info[$component]['plural_label'])) { + return $entity_info[$component]['plural_label']; + } + else { + return $entity_info[$component]['label']; + } } /** @@ -70,18 +81,12 @@ class EntityApiConfiguration extends Configuration { * Overrides Drupal\configuration\Config\Configuration::supportedComponents(). */ static public function supportedComponents() { - if (!static::isActive()) { - return array(); - } - - module_load_include('inc', 'entity', 'entity.features'); - $components = entity_features_api(); - $supported = array(); - foreach ($components as $component => $info) { - $supported[] = $component; + foreach (entity_crud_get_info() as $type => $info) { + if (!empty($info['exportable'])) { + $supported[] = $type; + } } - return $supported; } @@ -89,19 +94,11 @@ class EntityApiConfiguration extends Configuration { * Overrides Drupal\configuration\Config\Configuration::getAllIdentifiers(). */ public static function getAllIdentifiers($component) { - $identifiers = array(); - $items = entity_features_export_options($component); - foreach ($items as $key => $label) { - $identifiers[$key] = $label; + $options = array(); + foreach (entity_load_multiple_by_name($component, FALSE) as $name => $entity) { + $options[$name] = entity_label($component, $entity); } - return $identifiers; - } - - /** - * Overrides Drupal\configuration\Config\Configuration::getStorageSystem(). - */ - static protected function getStorageSystem($component) { - return '\Drupal\configuration\Storage\StorageEntityApi'; + return $options; } /** @@ -119,28 +116,22 @@ class EntityApiConfiguration extends Configuration { * Implements Drupal\configuration\Config\Configuration::prepareBuild(). */ public function prepareBuild() { - module_load_include('inc', 'entity', 'entity.features'); - $components = entity_features_api(); - $default_hook = $components[$this->getComponent()]['default_hook']; - $export = array(); - $info = entity_features_export_render('configuration', array($this->getIdentifier()), $export, $this->getComponent()); - $code = $info[$default_hook]; - $this->data = array('function' => $this->getIdentifier(), 'code' => $code); - return $this->data; + $entity_type = $this->getComponent(); + $this->data = entity_load_single($entity_type, $this->getIdentifier()); + return $this; } /** * Implements Drupal\configuration\Config\Configuration::saveToActiveStore(). */ public function saveToActiveStore(ConfigIteratorSettings &$settings) { - /*ctools_include('export'); - $object = ctools_export_crud_load($this->getComponent(), $this->getIdentifier()); - if ($object) { - ctools_export_crud_delete($this->getComponent(), $object); + $entity = $this->getData(); + $entity_type = $this->getComponent(); + if ($original = entity_load_single($entity_type, $this->getIdentifier())) { + entity_delete($entity_type, $this->getIdentifier()); } - $data = $this->getData(); - $data->export_type = NULL; - ctools_export_crud_save($this->getComponent(), $data); - $settings->addInfo('imported', $this->getUniqueId());*/ + + $entity->save(); + $settings->addInfo('imported', $this->getUniqueId()); } } diff --git a/lib/Drupal/configuration/Storage/StorageEntityApi.php b/lib/Drupal/configuration/Storage/StorageEntityApi.php index d54abe9..70715ae 100644 --- a/lib/Drupal/configuration/Storage/StorageEntityApi.php +++ b/lib/Drupal/configuration/Storage/StorageEntityApi.php @@ -11,14 +11,23 @@ use Drupal\configuration\Storage\StoragePhp; class StorageEntityApi extends StoragePHP { + // The class that storages the data of the configuration + protected $entity_type; + + public function __construct($entity_type) { + parent::__construct(); + $this->entity_type = $entity_type; + } + /** * Saves the configuration object into the DataStore. */ public function getDataToSave() { + $filename = $this->filename; $export = '$api = ' . $this->export($this->api_version) . ";\n\n"; - $export .= 'function ' . $this->data['function'] . '() {' . "\n" . $this->data['code'] . "\n}\n\n"; + $export .= '$data = entity_import(\'' . $this->entity_type . "', '" . addcslashes(entity_export($this->entity_type, $this->data, ' '), '\\\'') . "');\n\n"; $export .= '$dependencies = ' . $this->export($this->dependencies) . ";\n\n"; $export .= '$optional = ' . $this->export($this->optional_configurations) . ";\n\n"; $export .= '$modules = ' . $this->export($this->required_modules) . ";";