View source
<?php
namespace Drupal\Core\Config\Entity;
use Drupal\Core\Config\ConfigManagerInterface;
use Drupal\Core\Entity\EntityManagerInterface;
trait ConfigDependencyDeleteFormTrait {
protected abstract function t($string, array $args = array(), array $options = array());
protected function addDependencyListsToForm(array &$form, $type, array $names, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager) {
$dependent_entities = $config_manager
->getConfigEntitiesToChangeOnDependencyRemoval($type, $names);
$entity_types = array();
$form['entity_updates'] = array(
'#type' => 'details',
'#title' => $this
->t('Configuration updates'),
'#description' => $this
->t('The listed configuration will be updated.'),
'#open' => TRUE,
'#access' => FALSE,
);
foreach ($dependent_entities['update'] as $entity) {
$entity_type_id = $entity
->getEntityTypeId();
if (!isset($form['entity_updates'][$entity_type_id])) {
$entity_type = $entity_manager
->getDefinition($entity_type_id);
$label = $entity_type
->getLabel();
$entity_types[$entity_type_id] = $label;
$form['entity_updates'][$entity_type_id] = array(
'#theme' => 'item_list',
'#title' => $label,
'#items' => array(),
);
}
$form['entity_updates'][$entity_type_id]['#items'][$entity
->id()] = $entity
->label() ?: $entity
->id();
}
if (!empty($dependent_entities['update'])) {
$form['entity_updates']['#access'] = TRUE;
asort($entity_types, SORT_FLAG_CASE);
$weight = 0;
foreach ($entity_types as $entity_type_id => $label) {
$form['entity_updates'][$entity_type_id]['#weight'] = $weight;
ksort($form['entity_updates'][$entity_type_id]['#items'], SORT_FLAG_CASE);
$weight++;
}
}
$form['entity_deletes'] = array(
'#type' => 'details',
'#title' => $this
->t('Configuration deletions'),
'#description' => $this
->t('The listed configuration will be deleted.'),
'#open' => TRUE,
'#access' => FALSE,
);
foreach ($dependent_entities['delete'] as $entity) {
$entity_type_id = $entity
->getEntityTypeId();
if (!isset($form['entity_deletes'][$entity_type_id])) {
$entity_type = $entity_manager
->getDefinition($entity_type_id);
$label = $entity_type
->getLabel();
$entity_types[$entity_type_id] = $label;
$form['entity_deletes'][$entity_type_id] = array(
'#theme' => 'item_list',
'#title' => $label,
'#items' => array(),
);
}
$form['entity_deletes'][$entity_type_id]['#items'][$entity
->id()] = $entity
->label() ?: $entity
->id();
}
if (!empty($dependent_entities['delete'])) {
$form['entity_deletes']['#access'] = TRUE;
asort($entity_types, SORT_FLAG_CASE);
$weight = 0;
foreach ($entity_types as $entity_type_id => $label) {
if (isset($form['entity_deletes'][$entity_type_id])) {
$form['entity_deletes'][$entity_type_id]['#weight'] = $weight;
ksort($form['entity_deletes'][$entity_type_id]['#items'], SORT_FLAG_CASE);
$weight++;
}
}
}
}
}