diff --git a/core/lib/Drupal/Core/Config/ConfigImporterEvent.php b/core/lib/Drupal/Core/Config/ConfigImporterEvent.php index caef42e..393f3a1 100644 --- a/core/lib/Drupal/Core/Config/ConfigImporterEvent.php +++ b/core/lib/Drupal/Core/Config/ConfigImporterEvent.php @@ -37,4 +37,23 @@ public function getConfigImporter() { return $this->configImporter; } + /** + * Gets the list of differences that will be imported. + * + * @param string $op + * (optional) A change operation. Either delete, create or update. If + * supplied the returned list will be limited to this operation. + * @param string $collection + * (optional) The collection to get the changelist for. Defaults to the + * default collection. + * + * @return array + * An array of config changes that are yet to be imported. + * + * @see \Drupal\Core\Config\StorageComparerInterface::getChangelist() + */ + public function getChangelist($op = NULL, $collection = StorageInterface::DEFAULT_COLLECTION) { + return $this->configImporter->getStorageComparer()->getChangelist($op, $collection); + } + } diff --git a/core/lib/Drupal/Core/Entity/Event/BundleConfigImportValidate.php b/core/lib/Drupal/Core/Entity/Event/BundleConfigImportValidate.php index cabb240..9a970e8 100644 --- a/core/lib/Drupal/Core/Entity/Event/BundleConfigImportValidate.php +++ b/core/lib/Drupal/Core/Entity/Event/BundleConfigImportValidate.php @@ -46,30 +46,29 @@ public function __construct(ConfigManagerInterface $config_manager, EntityManage } /** - * Checks that a bundle defined by a configuration entity is not in use. + * Ensures bundles that will be deleted are not in use. * * @param ConfigImporterEvent $event * The config import event. */ public function onConfigImporterValidate(ConfigImporterEvent $event) { - $deletes = $event->getConfigImporter()->getStorageComparer()->getChangelist('delete'); - foreach ($deletes as $config_name) { - // Get the config entity type id if we are going to delete a config - // entity. + foreach ($event->getChangelist('delete') as $config_name) { + // Get the config entity type ID. This also ensure we are dealing with a + // configuration entity. $entity_type_id = $this->configManager->getEntityTypeIdByName($config_name); if ($entity_type_id && ($entity_type = $this->entityManager->getDefinition($entity_type_id))) { - // What is this entity type a bundle of. + // Is this entity type define a bundle of another entity type. if ($bundle_of = $entity_type->getBundleOf()) { // Work out if there are entities with this bundle. $bundle_of_entity_type = $this->entityManager->getDefinition($bundle_of); - $id = ConfigEntityStorage::getIDFromConfigName($config_name, $entity_type->getConfigPrefix()); + $bundle_id = ConfigEntityStorage::getIDFromConfigName($config_name, $entity_type->getConfigPrefix()); $entity_query = $this->entityManager->getStorage($bundle_of)->getQuery(); - $entities = $entity_query->condition($bundle_of_entity_type->getKey('bundle'), $id) + $entities = $entity_query->condition($bundle_of_entity_type->getKey('bundle'), $bundle_id) ->accessCheck(FALSE) ->range(0, 1) ->execute(); if (!empty($entities)) { - $entity = $this->entityManager->getStorage($entity_type_id)->load($id); + $entity = $this->entityManager->getStorage($entity_type_id)->load($bundle_id); $event->getConfigImporter()->logError($this->t('There are entities of type %entity_type and %bundle_label %bundle existing. These need to be deleted before importing.', array('%entity_type' => $bundle_of_entity_type->getLabel(), '%bundle_label' => $bundle_of_entity_type->getBundleLabel(), '%bundle' => $entity->label()))); } }