3 namespace Drupal\Core\Entity;
5 use Drupal\Core\Config\Entity\ConfigEntityInterface;
6 use Drupal\Core\Form\FormStateInterface;
9 * Provides a generic base class for an entity deletion form.
13 class EntityDeleteForm extends EntityConfirmFormBase {
15 use EntityDeleteFormTrait;
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
29 if (!($entity instanceof ConfigEntityInterface)) {
32 $this->addDependencyListsToForm($form, $entity->getConfigDependencyKey(), $this->getConfigNamesToDelete($entity), $this->getConfigManager(), $this->entityManager);
38 * Gets the configuration manager.
40 * @return \Drupal\Core\Config\ConfigManager
41 * The configuration manager.
43 protected function getConfigManager() {
44 return \Drupal::service('config.manager');
48 * Returns config names to delete for the deletion confirmation form.
50 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
51 * The entity being deleted.
54 * A list of configuration names that will be deleted by this form.
56 protected function getConfigNamesToDelete(ConfigEntityInterface $entity) {
57 return [$entity->getConfigDependencyName()];