SiteSettingEntityTypeDeleteForm.php in Site Settings and Labels 8
File
src/Form/SiteSettingEntityTypeDeleteForm.php
View source
<?php
namespace Drupal\site_settings\Form;
use Drupal\Core\Entity\EntityConfirmFormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Url;
use Drupal\site_settings\SiteSettingsLoader;
use Symfony\Component\DependencyInjection\ContainerInterface;
class SiteSettingEntityTypeDeleteForm extends EntityConfirmFormBase {
protected $siteSettingsLoader;
public function __construct(SiteSettingsLoader $site_settings_loader) {
$this->siteSettingsLoader = $site_settings_loader;
}
public static function create(ContainerInterface $container) {
return new static($container
->get('site_settings.loader'));
}
public function getQuestion() {
return $this
->t('Are you sure you want to delete %name?', [
'%name' => $this->entity
->label(),
]);
}
public function getCancelUrl() {
return new Url('entity.site_setting_entity_type.collection');
}
public function getConfirmText() {
return $this
->t('Delete');
}
public function submitForm(array &$form, FormStateInterface $form_state) {
$entities = $this->entityTypeManager
->getStorage('site_setting_entity')
->loadByProperties([
'type' => $this->entity
->id(),
]);
if (!empty($entities)) {
$controller = $this->entityTypeManager
->getStorage('site_setting_entity');
$controller
->delete($entities);
}
$this->entity
->delete();
$this
->messenger()
->addMessage($this
->t('Successfully deleted the "@label" site setting.', [
'@label' => $this->entity
->label(),
]));
$this->siteSettingsLoader
->clearCache();
$form_state
->setRedirectUrl($this
->getCancelUrl());
}
}