本文整理汇总了PHP中Drupal\Core\Config\Entity\ConfigEntityInterface::onDependencyRemoval方法的典型用法代码示例。如果您正苦于以下问题:PHP ConfigEntityInterface::onDependencyRemoval方法的具体用法?PHP ConfigEntityInterface::onDependencyRemoval怎么用?PHP ConfigEntityInterface::onDependencyRemoval使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Drupal\Core\Config\Entity\ConfigEntityInterface
的用法示例。
在下文中一共展示了ConfigEntityInterface::onDependencyRemoval方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callOnDependencyRemoval
/**
* 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);
}