protected ConfigDependencyDeleteFormTrait::addDependencyListsToForm(array &$form, $type, array $names, ConfigManagerInterface $config_manager, EntityManagerInterface $entity_manager)
Adds form elements to list affected configuration entities.
Parameters
array $form: The form array to add elements to.
string $type: The type of dependency being checked. Either 'module', 'theme', 'config' or 'content'.
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.
\Drupal\Core\Config\ConfigManagerInterface $config_manager: The config manager.
\Drupal\Core\Entity\EntityManagerInterface $entity_manager: The entity manager.
See also
\Drupal\Core\Config\ConfigManagerInterface::getConfigEntitiesToChangeOnDependencyRemoval()
File
- core/lib/Drupal/Core/Config/Entity/ConfigDependencyDeleteFormTrait.php, line 41
Class
- ConfigDependencyDeleteFormTrait
- Lists affected configuration entities by a dependency removal.
Namespace
Drupal\Core\Config\Entity
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | protected function addDependencyListsToForm( array & $form , $type , array $names , ConfigManagerInterface $config_manager , EntityManagerInterface $entity_manager ) { // Get the dependent entities. $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 ) { /** @var \Drupal\Core\Config\Entity\ConfigEntityInterface $entity */ $entity_type_id = $entity ->getEntityTypeId(); if (!isset( $form [ 'entity_updates' ][ $entity_type_id ])) { $entity_type = $entity_manager ->getDefinition( $entity_type_id ); // Store the ID and label to sort the entity types and entities later. $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; // Add a weight key to the entity type sections. asort( $entity_types , SORT_FLAG_CASE); $weight = 0; foreach ( $entity_types as $entity_type_id => $label ) { $form [ 'entity_updates' ][ $entity_type_id ][ '#weight' ] = $weight ; // Sort the list of entity labels alphabetically. 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 ); // Store the ID and label to sort the entity types and entities later. $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; // Add a weight key to the entity type sections. 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 ; // Sort the list of entity labels alphabetically. ksort( $form [ 'entity_deletes' ][ $entity_type_id ][ '#items' ], SORT_FLAG_CASE); $weight ++; } } } } |
Please login to continue.