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