You are here

public function SiteSettingEntityTypeDeleteForm::submitForm in Site Settings and Labels 8

Throws

\Drupal\Component\Plugin\Exception\PluginNotFoundException Thrown if the entity type doesn't exist.

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException Thrown if the storage handler couldn't be loaded.

\Drupal\Core\Entity\EntityStorageException

Overrides EntityForm::submitForm

File

src/Form/SiteSettingEntityTypeDeleteForm.php, line 70

Class

SiteSettingEntityTypeDeleteForm
Builds the form to delete Site Setting type entities.

Namespace

Drupal\site_settings\Form

Code

public function submitForm(array &$form, FormStateInterface $form_state) {

  // Get site settings of this type.
  $entities = $this->entityTypeManager
    ->getStorage('site_setting_entity')
    ->loadByProperties([
    'type' => $this->entity
      ->id(),
  ]);
  if (!empty($entities)) {

    // Delete site settings of this type.
    $controller = $this->entityTypeManager
      ->getStorage('site_setting_entity');
    $controller
      ->delete($entities);
  }

  // Delete the site setting entity type.
  $this->entity
    ->delete();
  $this
    ->messenger()
    ->addMessage($this
    ->t('Successfully deleted the "@label" site setting.', [
    '@label' => $this->entity
      ->label(),
  ]));

  // Rebuild the site settings cache.
  $this->siteSettingsLoader
    ->clearCache();
  $form_state
    ->setRedirectUrl($this
    ->getCancelUrl());
}