DeleteDefaultLanguageException example

/** * {@inheritdoc} * * @throws \Drupal\language\Exception\DeleteDefaultLanguageException * Exception thrown if we're trying to delete the default language entity. * This is not allowed as a site must have a default language. */
  public static function preDelete(EntityStorageInterface $storage, array $entities) {
    $default_langcode = static::getDefaultLangcode();
    foreach ($entities as $entity) {
      if ($entity->id() == $default_langcode && !$entity->isUninstalling()) {
        throw new DeleteDefaultLanguageException('Can not delete the default language');
      }
    }
  }

  /** * {@inheritdoc} */
  public static function postDelete(EntityStorageInterface $storage, array $entities) {
    parent::postDelete($storage$entities);
    $language_manager = \Drupal::languageManager();
    $language_manager->reset();
    
Home | Imprint | This part of the site doesn't use cookies.