annotate core/lib/Drupal/Core/Config/ConfigManager.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children 7a779792577d
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\Config;
Chris@0 4
Chris@0 5 use Drupal\Component\Diff\Diff;
Chris@0 6 use Drupal\Core\Config\Entity\ConfigDependencyManager;
Chris@0 7 use Drupal\Core\Config\Entity\ConfigEntityInterface;
Chris@0 8 use Drupal\Core\Config\Entity\ConfigEntityTypeInterface;
Chris@0 9 use Drupal\Core\Entity\EntityManagerInterface;
Chris@0 10 use Drupal\Core\Entity\EntityTypeInterface;
Chris@0 11 use Drupal\Core\Serialization\Yaml;
Chris@0 12 use Drupal\Core\StringTranslation\StringTranslationTrait;
Chris@0 13 use Drupal\Core\StringTranslation\TranslationInterface;
Chris@0 14 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Chris@0 15
Chris@0 16 /**
Chris@0 17 * The ConfigManager provides helper functions for the configuration system.
Chris@0 18 */
Chris@0 19 class ConfigManager implements ConfigManagerInterface {
Chris@0 20 use StringTranslationTrait;
Chris@0 21
Chris@0 22 /**
Chris@0 23 * The entity manager.
Chris@0 24 *
Chris@0 25 * @var \Drupal\Core\Entity\EntityManagerInterface
Chris@0 26 */
Chris@0 27 protected $entityManager;
Chris@0 28
Chris@0 29 /**
Chris@0 30 * The configuration factory.
Chris@0 31 *
Chris@0 32 * @var \Drupal\Core\Config\ConfigFactoryInterface
Chris@0 33 */
Chris@0 34 protected $configFactory;
Chris@0 35
Chris@0 36 /**
Chris@0 37 * The typed config manager.
Chris@0 38 *
Chris@0 39 * @var \Drupal\Core\Config\TypedConfigManagerInterface
Chris@0 40 */
Chris@0 41 protected $typedConfigManager;
Chris@0 42
Chris@0 43 /**
Chris@0 44 * The active configuration storage.
Chris@0 45 *
Chris@0 46 * @var \Drupal\Core\Config\StorageInterface
Chris@0 47 */
Chris@0 48 protected $activeStorage;
Chris@0 49
Chris@0 50 /**
Chris@0 51 * The event dispatcher.
Chris@0 52 *
Chris@0 53 * @var \Symfony\Component\EventDispatcher\EventDispatcherInterface
Chris@0 54 */
Chris@0 55 protected $eventDispatcher;
Chris@0 56
Chris@0 57 /**
Chris@0 58 * The configuration collection info.
Chris@0 59 *
Chris@0 60 * @var \Drupal\Core\Config\ConfigCollectionInfo
Chris@0 61 */
Chris@0 62 protected $configCollectionInfo;
Chris@0 63
Chris@0 64 /**
Chris@0 65 * The configuration storages keyed by collection name.
Chris@0 66 *
Chris@0 67 * @var \Drupal\Core\Config\StorageInterface[]
Chris@0 68 */
Chris@0 69 protected $storages;
Chris@0 70
Chris@0 71 /**
Chris@0 72 * Creates ConfigManager objects.
Chris@0 73 *
Chris@0 74 * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
Chris@0 75 * The entity manager.
Chris@0 76 * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
Chris@0 77 * The configuration factory.
Chris@0 78 * @param \Drupal\Core\Config\TypedConfigManagerInterface $typed_config_manager
Chris@0 79 * The typed config manager.
Chris@0 80 * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
Chris@0 81 * The string translation service.
Chris@0 82 * @param \Drupal\Core\Config\StorageInterface $active_storage
Chris@0 83 * The active configuration storage.
Chris@0 84 * @param \Symfony\Component\EventDispatcher\EventDispatcherInterface $event_dispatcher
Chris@0 85 * The event dispatcher.
Chris@0 86 */
Chris@0 87 public function __construct(EntityManagerInterface $entity_manager, ConfigFactoryInterface $config_factory, TypedConfigManagerInterface $typed_config_manager, TranslationInterface $string_translation, StorageInterface $active_storage, EventDispatcherInterface $event_dispatcher) {
Chris@0 88 $this->entityManager = $entity_manager;
Chris@0 89 $this->configFactory = $config_factory;
Chris@0 90 $this->typedConfigManager = $typed_config_manager;
Chris@0 91 $this->stringTranslation = $string_translation;
Chris@0 92 $this->activeStorage = $active_storage;
Chris@0 93 $this->eventDispatcher = $event_dispatcher;
Chris@0 94 }
Chris@0 95
Chris@0 96 /**
Chris@0 97 * {@inheritdoc}
Chris@0 98 */
Chris@0 99 public function getEntityTypeIdByName($name) {
Chris@0 100 $entities = array_filter($this->entityManager->getDefinitions(), function (EntityTypeInterface $entity_type) use ($name) {
Chris@0 101 return ($entity_type instanceof ConfigEntityTypeInterface && $config_prefix = $entity_type->getConfigPrefix()) && strpos($name, $config_prefix . '.') === 0;
Chris@0 102 });
Chris@0 103 return key($entities);
Chris@0 104 }
Chris@0 105
Chris@0 106 /**
Chris@0 107 * {@inheritdoc}
Chris@0 108 */
Chris@0 109 public function loadConfigEntityByName($name) {
Chris@0 110 $entity_type_id = $this->getEntityTypeIdByName($name);
Chris@0 111 if ($entity_type_id) {
Chris@0 112 $entity_type = $this->entityManager->getDefinition($entity_type_id);
Chris@0 113 $id = substr($name, strlen($entity_type->getConfigPrefix()) + 1);
Chris@0 114 return $this->entityManager->getStorage($entity_type_id)->load($id);
Chris@0 115 }
Chris@0 116 return NULL;
Chris@0 117 }
Chris@0 118
Chris@0 119 /**
Chris@0 120 * {@inheritdoc}
Chris@0 121 */
Chris@0 122 public function getEntityManager() {
Chris@0 123 return $this->entityManager;
Chris@0 124 }
Chris@0 125
Chris@0 126 /**
Chris@0 127 * {@inheritdoc}
Chris@0 128 */
Chris@0 129 public function getConfigFactory() {
Chris@0 130 return $this->configFactory;
Chris@0 131 }
Chris@0 132
Chris@0 133 /**
Chris@0 134 * {@inheritdoc}
Chris@0 135 */
Chris@0 136 public function diff(StorageInterface $source_storage, StorageInterface $target_storage, $source_name, $target_name = NULL, $collection = StorageInterface::DEFAULT_COLLECTION) {
Chris@0 137 if ($collection != StorageInterface::DEFAULT_COLLECTION) {
Chris@0 138 $source_storage = $source_storage->createCollection($collection);
Chris@0 139 $target_storage = $target_storage->createCollection($collection);
Chris@0 140 }
Chris@0 141 if (!isset($target_name)) {
Chris@0 142 $target_name = $source_name;
Chris@0 143 }
Chris@0 144 // The output should show configuration object differences formatted as YAML.
Chris@0 145 // But the configuration is not necessarily stored in files. Therefore, they
Chris@0 146 // need to be read and parsed, and lastly, dumped into YAML strings.
Chris@0 147 $source_data = explode("\n", Yaml::encode($source_storage->read($source_name)));
Chris@0 148 $target_data = explode("\n", Yaml::encode($target_storage->read($target_name)));
Chris@0 149
Chris@0 150 // Check for new or removed files.
Chris@0 151 if ($source_data === ['false']) {
Chris@0 152 // Added file.
Chris@0 153 // Cast the result of t() to a string, as the diff engine doesn't know
Chris@0 154 // about objects.
Chris@0 155 $source_data = [(string) $this->t('File added')];
Chris@0 156 }
Chris@0 157 if ($target_data === ['false']) {
Chris@0 158 // Deleted file.
Chris@0 159 // Cast the result of t() to a string, as the diff engine doesn't know
Chris@0 160 // about objects.
Chris@0 161 $target_data = [(string) $this->t('File removed')];
Chris@0 162 }
Chris@0 163
Chris@0 164 return new Diff($source_data, $target_data);
Chris@0 165 }
Chris@0 166
Chris@0 167 /**
Chris@0 168 * {@inheritdoc}
Chris@0 169 */
Chris@0 170 public function createSnapshot(StorageInterface $source_storage, StorageInterface $snapshot_storage) {
Chris@0 171 // Empty the snapshot of all configuration.
Chris@0 172 $snapshot_storage->deleteAll();
Chris@0 173 foreach ($snapshot_storage->getAllCollectionNames() as $collection) {
Chris@0 174 $snapshot_collection = $snapshot_storage->createCollection($collection);
Chris@0 175 $snapshot_collection->deleteAll();
Chris@0 176 }
Chris@0 177 foreach ($source_storage->listAll() as $name) {
Chris@0 178 $snapshot_storage->write($name, $source_storage->read($name));
Chris@0 179 }
Chris@0 180 // Copy collections as well.
Chris@0 181 foreach ($source_storage->getAllCollectionNames() as $collection) {
Chris@0 182 $source_collection = $source_storage->createCollection($collection);
Chris@0 183 $snapshot_collection = $snapshot_storage->createCollection($collection);
Chris@0 184 foreach ($source_collection->listAll() as $name) {
Chris@0 185 $snapshot_collection->write($name, $source_collection->read($name));
Chris@0 186 }
Chris@0 187 }
Chris@0 188 }
Chris@0 189
Chris@0 190 /**
Chris@0 191 * {@inheritdoc}
Chris@0 192 */
Chris@0 193 public function uninstall($type, $name) {
Chris@0 194 $entities = $this->getConfigEntitiesToChangeOnDependencyRemoval($type, [$name], FALSE);
Chris@0 195 // Fix all dependent configuration entities.
Chris@0 196 /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */
Chris@0 197 foreach ($entities['update'] as $entity) {
Chris@0 198 $entity->save();
Chris@0 199 }
Chris@0 200 // Remove all dependent configuration entities.
Chris@0 201 foreach ($entities['delete'] as $entity) {
Chris@0 202 $entity->setUninstalling(TRUE);
Chris@0 203 $entity->delete();
Chris@0 204 }
Chris@0 205
Chris@0 206 $config_names = $this->configFactory->listAll($name . '.');
Chris@0 207 foreach ($config_names as $config_name) {
Chris@0 208 $this->configFactory->getEditable($config_name)->delete();
Chris@0 209 }
Chris@0 210
Chris@0 211 // Remove any matching configuration from collections.
Chris@0 212 foreach ($this->activeStorage->getAllCollectionNames() as $collection) {
Chris@0 213 $collection_storage = $this->activeStorage->createCollection($collection);
Chris@0 214 $collection_storage->deleteAll($name . '.');
Chris@0 215 }
Chris@0 216
Chris@0 217 $schema_dir = drupal_get_path($type, $name) . '/' . InstallStorage::CONFIG_SCHEMA_DIRECTORY;
Chris@0 218 if (is_dir($schema_dir)) {
Chris@0 219 // Refresh the schema cache if uninstalling an extension that provides
Chris@0 220 // configuration schema.
Chris@0 221 $this->typedConfigManager->clearCachedDefinitions();
Chris@0 222 }
Chris@0 223 }
Chris@0 224
Chris@0 225 /**
Chris@0 226 * {@inheritdoc}
Chris@0 227 */
Chris@0 228 public function getConfigDependencyManager() {
Chris@0 229 $dependency_manager = new ConfigDependencyManager();
Chris@0 230 // Read all configuration using the factory. This ensures that multiple
Chris@0 231 // deletes during the same request benefit from the static cache. Using the
Chris@0 232 // factory also ensures configuration entity dependency discovery has no
Chris@0 233 // dependencies on the config entity classes. Assume data with UUID is a
Chris@0 234 // config entity. Only configuration entities can be depended on so we can
Chris@0 235 // ignore everything else.
Chris@0 236 $data = array_map(function ($config) {
Chris@0 237 $data = $config->get();
Chris@0 238 if (isset($data['uuid'])) {
Chris@0 239 return $data;
Chris@0 240 }
Chris@0 241 return FALSE;
Chris@0 242 }, $this->configFactory->loadMultiple($this->activeStorage->listAll()));
Chris@0 243 $dependency_manager->setData(array_filter($data));
Chris@0 244 return $dependency_manager;
Chris@0 245 }
Chris@0 246
Chris@0 247 /**
Chris@0 248 * {@inheritdoc}
Chris@0 249 */
Chris@0 250 public function findConfigEntityDependents($type, array $names, ConfigDependencyManager $dependency_manager = NULL) {
Chris@0 251 if (!$dependency_manager) {
Chris@0 252 $dependency_manager = $this->getConfigDependencyManager();
Chris@0 253 }
Chris@0 254 $dependencies = [];
Chris@0 255 foreach ($names as $name) {
Chris@0 256 $dependencies = array_merge($dependencies, $dependency_manager->getDependentEntities($type, $name));
Chris@0 257 }
Chris@0 258 return $dependencies;
Chris@0 259 }
Chris@0 260
Chris@0 261 /**
Chris@0 262 * {@inheritdoc}
Chris@0 263 */
Chris@0 264 public function findConfigEntityDependentsAsEntities($type, array $names, ConfigDependencyManager $dependency_manager = NULL) {
Chris@0 265 $dependencies = $this->findConfigEntityDependents($type, $names, $dependency_manager);
Chris@0 266 $entities = [];
Chris@0 267 $definitions = $this->entityManager->getDefinitions();
Chris@0 268 foreach ($dependencies as $config_name => $dependency) {
Chris@0 269 // Group by entity type to efficient load entities using
Chris@0 270 // \Drupal\Core\Entity\EntityStorageInterface::loadMultiple().
Chris@0 271 $entity_type_id = $this->getEntityTypeIdByName($config_name);
Chris@0 272 // It is possible that a non-configuration entity will be returned if a
Chris@0 273 // simple configuration object has a UUID key. This would occur if the
Chris@0 274 // dependents of the system module are calculated since system.site has
Chris@0 275 // a UUID key.
Chris@0 276 if ($entity_type_id) {
Chris@0 277 $id = substr($config_name, strlen($definitions[$entity_type_id]->getConfigPrefix()) + 1);
Chris@0 278 $entities[$entity_type_id][] = $id;
Chris@0 279 }
Chris@0 280 }
Chris@0 281 $entities_to_return = [];
Chris@0 282 foreach ($entities as $entity_type_id => $entities_to_load) {
Chris@0 283 $storage = $this->entityManager->getStorage($entity_type_id);
Chris@0 284 // Remove the keys since there are potential ID clashes from different
Chris@0 285 // configuration entity types.
Chris@0 286 $entities_to_return = array_merge($entities_to_return, array_values($storage->loadMultiple($entities_to_load)));
Chris@0 287 }
Chris@0 288 return $entities_to_return;
Chris@0 289 }
Chris@0 290
Chris@0 291 /**
Chris@0 292 * {@inheritdoc}
Chris@0 293 */
Chris@0 294 public function getConfigEntitiesToChangeOnDependencyRemoval($type, array $names, $dry_run = TRUE) {
Chris@0 295 // Determine the current list of dependent configuration entities and set up
Chris@0 296 // initial values.
Chris@0 297 $dependency_manager = $this->getConfigDependencyManager();
Chris@0 298 $dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager);
Chris@0 299 $original_dependencies = $dependents;
Chris@0 300 $delete_uuids = [];
Chris@0 301
Chris@0 302 $return = [
Chris@0 303 'update' => [],
Chris@0 304 'delete' => [],
Chris@0 305 'unchanged' => [],
Chris@0 306 ];
Chris@0 307
Chris@0 308 // Create a map of UUIDs to $original_dependencies key so that we can remove
Chris@0 309 // fixed dependencies.
Chris@0 310 $uuid_map = [];
Chris@0 311 foreach ($original_dependencies as $key => $entity) {
Chris@0 312 $uuid_map[$entity->uuid()] = $key;
Chris@0 313 }
Chris@0 314
Chris@0 315 // Try to fix any dependencies and find out what will happen to the
Chris@0 316 // dependency graph. Entities are processed in the order of most dependent
Chris@0 317 // first. For example, this ensures that Menu UI third party dependencies on
Chris@0 318 // node types are fixed before processing the node type's other
Chris@0 319 // dependencies.
Chris@0 320 while ($dependent = array_pop($dependents)) {
Chris@0 321 /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $dependent */
Chris@0 322 if ($dry_run) {
Chris@0 323 // Clone the entity so any changes do not change any static caches.
Chris@0 324 $dependent = clone $dependent;
Chris@0 325 }
Chris@0 326 $fixed = FALSE;
Chris@0 327 if ($this->callOnDependencyRemoval($dependent, $original_dependencies, $type, $names)) {
Chris@0 328 // Recalculate dependencies and update the dependency graph data.
Chris@0 329 $dependent->calculateDependencies();
Chris@0 330 $dependency_manager->updateData($dependent->getConfigDependencyName(), $dependent->getDependencies());
Chris@0 331 // Based on the updated data rebuild the list of dependents. This will
Chris@0 332 // remove entities that are no longer dependent after the recalculation.
Chris@0 333 $dependents = $this->findConfigEntityDependentsAsEntities($type, $names, $dependency_manager);
Chris@0 334 // Remove any entities that we've already marked for deletion.
Chris@0 335 $dependents = array_filter($dependents, function ($dependent) use ($delete_uuids) {
Chris@0 336 return !in_array($dependent->uuid(), $delete_uuids);
Chris@0 337 });
Chris@0 338 // Ensure that the dependency has actually been fixed. It is possible
Chris@0 339 // that the dependent has multiple dependencies that cause it to be in
Chris@0 340 // the dependency chain.
Chris@0 341 $fixed = TRUE;
Chris@0 342 foreach ($dependents as $key => $entity) {
Chris@0 343 if ($entity->uuid() == $dependent->uuid()) {
Chris@0 344 $fixed = FALSE;
Chris@0 345 unset($dependents[$key]);
Chris@0 346 break;
Chris@0 347 }
Chris@0 348 }
Chris@0 349 if ($fixed) {
Chris@0 350 // Remove the fixed dependency from the list of original dependencies.
Chris@0 351 unset($original_dependencies[$uuid_map[$dependent->uuid()]]);
Chris@0 352 $return['update'][] = $dependent;
Chris@0 353 }
Chris@0 354 }
Chris@0 355 // If the entity cannot be fixed then it has to be deleted.
Chris@0 356 if (!$fixed) {
Chris@0 357 $delete_uuids[] = $dependent->uuid();
Chris@0 358 // Deletes should occur in the order of the least dependent first. For
Chris@0 359 // example, this ensures that fields are removed before field storages.
Chris@0 360 array_unshift($return['delete'], $dependent);
Chris@0 361 }
Chris@0 362 }
Chris@0 363 // Use the lists of UUIDs to filter the original list to work out which
Chris@0 364 // configuration entities are unchanged.
Chris@0 365 $return['unchanged'] = array_filter($original_dependencies, function ($dependent) use ($delete_uuids) {
Chris@0 366 return !(in_array($dependent->uuid(), $delete_uuids));
Chris@0 367 });
Chris@0 368
Chris@0 369 return $return;
Chris@0 370 }
Chris@0 371
Chris@0 372 /**
Chris@0 373 * {@inheritdoc}
Chris@0 374 */
Chris@0 375 public function getConfigCollectionInfo() {
Chris@0 376 if (!isset($this->configCollectionInfo)) {
Chris@0 377 $this->configCollectionInfo = new ConfigCollectionInfo();
Chris@0 378 $this->eventDispatcher->dispatch(ConfigEvents::COLLECTION_INFO, $this->configCollectionInfo);
Chris@0 379 }
Chris@0 380 return $this->configCollectionInfo;
Chris@0 381 }
Chris@0 382
Chris@0 383 /**
Chris@0 384 * Calls an entity's onDependencyRemoval() method.
Chris@0 385 *
Chris@0 386 * A helper method to call onDependencyRemoval() with the correct list of
Chris@0 387 * affected entities. This list should only contain dependencies on the
Chris@0 388 * entity. Configuration and content entity dependencies will be converted
Chris@0 389 * into entity objects.
Chris@0 390 *
Chris@0 391 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
Chris@0 392 * The entity to call onDependencyRemoval() on.
Chris@0 393 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface[] $dependent_entities
Chris@0 394 * The list of dependent configuration entities.
Chris@0 395 * @param string $type
Chris@0 396 * The type of dependency being checked. Either 'module', 'theme', 'config'
Chris@0 397 * or 'content'.
Chris@0 398 * @param array $names
Chris@0 399 * The specific names to check. If $type equals 'module' or 'theme' then it
Chris@0 400 * should be a list of module names or theme names. In the case of 'config'
Chris@0 401 * or 'content' it should be a list of configuration dependency names.
Chris@0 402 *
Chris@0 403 * @return bool
Chris@0 404 * TRUE if the entity has changed as a result of calling the
Chris@0 405 * onDependencyRemoval() method, FALSE if not.
Chris@0 406 */
Chris@0 407 protected function callOnDependencyRemoval(ConfigEntityInterface $entity, array $dependent_entities, $type, array $names) {
Chris@0 408 $entity_dependencies = $entity->getDependencies();
Chris@0 409 if (empty($entity_dependencies)) {
Chris@0 410 // No dependent entities nothing to do.
Chris@0 411 return FALSE;
Chris@0 412 }
Chris@0 413
Chris@0 414 $affected_dependencies = [
Chris@0 415 'config' => [],
Chris@0 416 'content' => [],
Chris@0 417 'module' => [],
Chris@0 418 'theme' => [],
Chris@0 419 ];
Chris@0 420
Chris@0 421 // Work out if any of the entity's dependencies are going to be affected.
Chris@0 422 if (isset($entity_dependencies[$type])) {
Chris@0 423 // Work out which dependencies the entity has in common with the provided
Chris@0 424 // $type and $names.
Chris@0 425 $affected_dependencies[$type] = array_intersect($entity_dependencies[$type], $names);
Chris@0 426
Chris@0 427 // If the dependencies are entities we need to convert them into objects.
Chris@0 428 if ($type == 'config' || $type == 'content') {
Chris@0 429 $affected_dependencies[$type] = array_map(function ($name) use ($type) {
Chris@0 430 if ($type == 'config') {
Chris@0 431 return $this->loadConfigEntityByName($name);
Chris@0 432 }
Chris@0 433 else {
Chris@0 434 // Ignore the bundle.
Chris@0 435 list($entity_type_id,, $uuid) = explode(':', $name);
Chris@0 436 return $this->entityManager->loadEntityByConfigTarget($entity_type_id, $uuid);
Chris@0 437 }
Chris@0 438 }, $affected_dependencies[$type]);
Chris@0 439 }
Chris@0 440 }
Chris@0 441
Chris@0 442 // Merge any other configuration entities into the list of affected
Chris@0 443 // dependencies if necessary.
Chris@0 444 if (isset($entity_dependencies['config'])) {
Chris@0 445 foreach ($dependent_entities as $dependent_entity) {
Chris@0 446 if (in_array($dependent_entity->getConfigDependencyName(), $entity_dependencies['config'])) {
Chris@0 447 $affected_dependencies['config'][] = $dependent_entity;
Chris@0 448 }
Chris@0 449 }
Chris@0 450 }
Chris@0 451
Chris@0 452 // Key the entity arrays by config dependency name to make searching easy.
Chris@0 453 foreach (['config', 'content'] as $dependency_type) {
Chris@0 454 $affected_dependencies[$dependency_type] = array_combine(
Chris@0 455 array_map(function ($entity) {
Chris@0 456 return $entity->getConfigDependencyName();
Chris@0 457 }, $affected_dependencies[$dependency_type]),
Chris@0 458 $affected_dependencies[$dependency_type]
Chris@0 459 );
Chris@0 460 }
Chris@0 461
Chris@0 462 // Inform the entity.
Chris@0 463 return $entity->onDependencyRemoval($affected_dependencies);
Chris@0 464 }
Chris@0 465
Chris@0 466 /**
Chris@0 467 * {@inheritdoc}
Chris@0 468 */
Chris@0 469 public function findMissingContentDependencies() {
Chris@0 470 $content_dependencies = [];
Chris@0 471 $missing_dependencies = [];
Chris@0 472 foreach ($this->activeStorage->readMultiple($this->activeStorage->listAll()) as $config_data) {
Chris@0 473 if (isset($config_data['dependencies']['content'])) {
Chris@0 474 $content_dependencies = array_merge($content_dependencies, $config_data['dependencies']['content']);
Chris@0 475 }
Chris@0 476 if (isset($config_data['dependencies']['enforced']['content'])) {
Chris@0 477 $content_dependencies = array_merge($content_dependencies, $config_data['dependencies']['enforced']['content']);
Chris@0 478 }
Chris@0 479 }
Chris@0 480 foreach (array_unique($content_dependencies) as $content_dependency) {
Chris@0 481 // Format of the dependency is entity_type:bundle:uuid.
Chris@0 482 list($entity_type, $bundle, $uuid) = explode(':', $content_dependency, 3);
Chris@0 483 if (!$this->entityManager->loadEntityByUuid($entity_type, $uuid)) {
Chris@0 484 $missing_dependencies[$uuid] = [
Chris@0 485 'entity_type' => $entity_type,
Chris@0 486 'bundle' => $bundle,
Chris@0 487 'uuid' => $uuid,
Chris@0 488 ];
Chris@0 489 }
Chris@0 490 }
Chris@0 491 return $missing_dependencies;
Chris@0 492 }
Chris@0 493
Chris@0 494 }