EntityDeleteForm.php 1.8 KB
Newer Older
1 2 3 4
<?php

namespace Drupal\Core\Entity;

5 6 7
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\Form\FormStateInterface;

8 9 10 11 12 13 14 15 16
/**
 * Provides a generic base class for an entity deletion form.
 *
 * @ingroup entity_api
 */
class EntityDeleteForm extends EntityConfirmFormBase {

  use EntityDeleteFormTrait;

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
  /**
   * {@inheritdoc}
   */
  public function buildForm(array $form, FormStateInterface $form_state) {
    $form = parent::buildForm($form, $form_state);
    $entity = $this->getEntity();
    // Only do dependency processing for configuration entities. Whilst it is
    // possible for a configuration entity to be dependent on a content entity,
    // these dependencies are soft and content delete permissions are often
    // given to more users. This method should not make assumptions that $entity
    // is a configuration entity in case we decide to remove the following
    // condition.
    if (!($entity instanceof ConfigEntityInterface)) {
      return $form;
    }
32
    $this->addDependencyListsToForm($form, $entity->getConfigDependencyKey(), $this->getConfigNamesToDelete($entity), $this->getConfigManager(), $this->entityManager);
33 34 35 36 37 38 39 40 41 42 43 44 45 46

    return $form;
  }

  /**
   * Gets the configuration manager.
   *
   * @return \Drupal\Core\Config\ConfigManager
   *   The configuration manager.
   */
  protected function getConfigManager() {
    return \Drupal::service('config.manager');
  }

47 48 49 50 51 52 53 54 55 56 57 58 59
  /**
   * Returns config names to delete for the deletion confirmation form.
   *
   * @param \Drupal\Core\Config\Entity\ConfigEntityInterface $entity
   *   The entity being deleted.
   *
   * @return string[]
   *   A list of configuration names that will be deleted by this form.
   */
  protected function getConfigNamesToDelete(ConfigEntityInterface $entity) {
    return [$entity->getConfigDependencyName()];
  }

60
}