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.
15 class EntityDeleteForm extends EntityConfirmFormBase {
17 use EntityDeleteFormTrait;
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
31 if (!($entity instanceof ConfigEntityInterface)) {
34 $this->addDependencyListsToForm($form, $entity->getConfigDependencyKey(), $this->getConfigNamesToDelete($entity), $this->getConfigManager(), $this->entityManager);
40 * Gets the configuration manager.
42 * @return \Drupal\Core\Config\ConfigManager
43 * The configuration manager.
45 protected function getConfigManager() {
46 return \Drupal::service('config.manager');
50 * Returns config names to delete for the deletion confirmation form.
52 * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
53 * The entity being deleted.
56 * A list of configuration names that will be deleted by this form.
58 protected function getConfigNamesToDelete(ConfigEntityInterface $entity) {
59 return [$entity->getConfigDependencyName()];