FeaturesConfigDependencyManager.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace Drupal\features;
  3. use Drupal\Core\Config\Entity\ConfigDependencyManager;
  4. use Drupal\Core\Config\Entity\ConfigEntityDependency;
  5. /**
  6. * Class FeaturesConfigDependencyManager
  7. * @package Drupal\features
  8. */
  9. class FeaturesConfigDependencyManager extends ConfigDependencyManager{
  10. protected $sorted_graph;
  11. /**
  12. * {@inheritdoc}
  13. */
  14. public function getDependentEntities($type, $name) {
  15. $dependent_entities = array();
  16. $entities_to_check = array();
  17. if ($type == 'config') {
  18. $entities_to_check[] = $name;
  19. }
  20. else {
  21. if ($type == 'module' || $type == 'theme' || $type == 'content') {
  22. $dependent_entities = array_filter($this->data, function (ConfigEntityDependency $entity) use ($type, $name) {
  23. return $entity->hasDependency($type, $name);
  24. });
  25. }
  26. // If checking content, module, or theme dependencies, discover which
  27. // entities are dependent on the entities that have a direct dependency.
  28. foreach ($dependent_entities as $entity) {
  29. $entities_to_check[] = $entity->getConfigDependencyName();
  30. }
  31. }
  32. $dependencies = array_merge($this->createGraphConfigEntityDependencies($entities_to_check), $dependent_entities);
  33. if (!$this->sorted_graph) {
  34. // Sort dependencies in the reverse order of the graph. So the least
  35. // dependent is at the top. For example, this ensures that fields are
  36. // always after field storages. This is because field storages need to be
  37. // created before a field.
  38. $this->sorted_graph = $this->getGraph();
  39. uasort($this->sorted_graph, array($this, 'sortGraph'));
  40. }
  41. return array_replace(array_intersect_key($this->sorted_graph, $dependencies), $dependencies);
  42. }
  43. /**
  44. * {@inheritdoc}
  45. */
  46. public function setData(array $data) {
  47. parent::setData($data);
  48. $this->sorted_graph = NULL;
  49. return $this;
  50. }
  51. }