Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function calculateDependencies()
 {
     $dependencies = parent::calculateDependencies();
     // Ensure that we don't add dependencies for placeholders.
     // @todo Use a method to check for tokens in
     //   https://www.drupal.org/node/2396607.
     if (strpos($this->options['target'], '{{') === FALSE) {
         if ($entity = $this->entityManager->loadEntityByConfigTarget($this->entityType, $this->options['target'])) {
             $dependencies[$this->entityManager->getDefinition($this->entityType)->getConfigDependencyKey()][] = $entity->getConfigDependencyName();
         }
     }
     return $dependencies;
 }
Ejemplo n.º 2
0
 /**
  * Calls an entity's onDependencyRemoval() method.
  *
  * A helper method to call onDependencyRemoval() with the correct list of
  * affected entities. This list should only contain dependencies on the
  * entity. Configuration and content entity dependencies will be converted
  * into entity objects.
  *
  * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
  *   The entity to call onDependencyRemoval() on.
  * @param \Drupal\Core\Config\Entity\ConfigEntityInterface[] $dependent_entities
  *   The list of dependent configuration entities.
  * @param string $type
  *   The type of dependency being checked. Either 'module', 'theme', 'config'
  *   or 'content'.
  * @param array $names
  *   The specific names to check. If $type equals 'module' or 'theme' then it
  *   should be a list of module names or theme names. In the case of 'config'
  *   or 'content' it should be a list of configuration dependency names.
  *
  * @return bool
  *   TRUE if the entity has changed as a result of calling the
  *   onDependencyRemoval() method, FALSE if not.
  */
 protected function callOnDependencyRemoval(ConfigEntityInterface $entity, array $dependent_entities, $type, array $names)
 {
     $entity_dependencies = $entity->getDependencies();
     if (empty($entity_dependencies)) {
         // No dependent entities nothing to do.
         return FALSE;
     }
     $affected_dependencies = array('config' => array(), 'content' => array(), 'module' => array(), 'theme' => array());
     // Work out if any of the entity's dependencies are going to be affected.
     if (isset($entity_dependencies[$type])) {
         // Work out which dependencies the entity has in common with the provided
         // $type and $names.
         $affected_dependencies[$type] = array_intersect($entity_dependencies[$type], $names);
         // If the dependencies are entities we need to convert them into objects.
         if ($type == 'config' || $type == 'content') {
             $affected_dependencies[$type] = array_map(function ($name) use($type) {
                 if ($type == 'config') {
                     return $this->loadConfigEntityByName($name);
                 } else {
                     // Ignore the bundle.
                     list($entity_type_id, , $uuid) = explode(':', $name);
                     return $this->entityManager->loadEntityByConfigTarget($entity_type_id, $uuid);
                 }
             }, $affected_dependencies[$type]);
         }
     }
     // Merge any other configuration entities into the list of affected
     // dependencies if necessary.
     if (isset($entity_dependencies['config'])) {
         foreach ($dependent_entities as $dependent_entity) {
             if (in_array($dependent_entity->getConfigDependencyName(), $entity_dependencies['config'])) {
                 $affected_dependencies['config'][] = $dependent_entity;
             }
         }
     }
     // Key the entity arrays by config dependency name to make searching easy.
     foreach (['config', 'content'] as $dependency_type) {
         $affected_dependencies[$dependency_type] = array_combine(array_map(function ($entity) {
             return $entity->getConfigDependencyName();
         }, $affected_dependencies[$dependency_type]), $affected_dependencies[$dependency_type]);
     }
     // Inform the entity.
     return $entity->onDependencyRemoval($affected_dependencies);
 }
Ejemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function loadEntityByConfigTarget($entity_type_id, $target)
 {
     return $this->entityManager->loadEntityByConfigTarget($entity_type_id, $target);
 }