b7a66e32f01272bf57764f6b9d7262c80f551b9f
[yaffs-website] / web / core / lib / Drupal / Core / Entity / EntityDeleteForm.php
1 <?php
2
3 namespace Drupal\Core\Entity;
4
5 use Drupal\Core\Config\Entity\ConfigEntityInterface;
6 use Drupal\Core\Form\FormStateInterface;
7
8 /**
9  * Provides a generic base class for an entity deletion form.
10  *
11  * @ingroup entity_api
12  */
13 class EntityDeleteForm extends EntityConfirmFormBase {
14
15   use EntityDeleteFormTrait;
16
17   /**
18    * {@inheritdoc}
19    */
20   public function buildForm(array $form, FormStateInterface $form_state) {
21     $form = parent::buildForm($form, $form_state);
22     $entity = $this->getEntity();
23     // Only do dependency processing for configuration entities. Whilst it is
24     // possible for a configuration entity to be dependent on a content entity,
25     // these dependencies are soft and content delete permissions are often
26     // given to more users. This method should not make assumptions that $entity
27     // is a configuration entity in case we decide to remove the following
28     // condition.
29     if (!($entity instanceof ConfigEntityInterface)) {
30       return $form;
31     }
32     $this->addDependencyListsToForm($form, $entity->getConfigDependencyKey(), $this->getConfigNamesToDelete($entity), $this->getConfigManager(), $this->entityManager);
33
34     return $form;
35   }
36
37   /**
38    * Gets the configuration manager.
39    *
40    * @return \Drupal\Core\Config\ConfigManager
41    *   The configuration manager.
42    */
43   protected function getConfigManager() {
44     return \Drupal::service('config.manager');
45   }
46
47   /**
48    * Returns config names to delete for the deletion confirmation form.
49    *
50    * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
51    *   The entity being deleted.
52    *
53    * @return string[]
54    *   A list of configuration names that will be deleted by this form.
55    */
56   protected function getConfigNamesToDelete(ConfigEntityInterface $entity) {
57     return [$entity->getConfigDependencyName()];
58   }
59
60 }