You are here

class FieldModuleUninstallValidator in Zircon Profile 8

Same name in this branch
  1. 8 core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php \Drupal\Core\Field\FieldModuleUninstallValidator
  2. 8 core/lib/Drupal/Core/ProxyClass/Field/FieldModuleUninstallValidator.php \Drupal\Core\ProxyClass\Field\FieldModuleUninstallValidator
Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php \Drupal\Core\Field\FieldModuleUninstallValidator

Validates module uninstall readiness based on defined storage definitions.

@todo Remove this once we support field purging for base fields. See https://www.drupal.org/node/2282119.

Hierarchy

Expanded class hierarchy of FieldModuleUninstallValidator

1 string reference to 'FieldModuleUninstallValidator'
core.services.yml in core/core.services.yml
core/core.services.yml
1 service uses FieldModuleUninstallValidator
field_uninstall_validator in core/core.services.yml
Drupal\Core\Field\FieldModuleUninstallValidator

File

core/lib/Drupal/Core/Field/FieldModuleUninstallValidator.php, line 22
Contains \Drupal\Core\Field\FieldModuleUninstallValidator.

Namespace

Drupal\Core\Field
View source
class FieldModuleUninstallValidator implements ModuleUninstallValidatorInterface {
  use StringTranslationTrait;

  /**
   * Constructs the object.
   *
   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
   *   The entity manager.
   * @param \Drupal\Core\StringTranslation\TranslationInterface $string_translation
   *   The string translation service.
   */
  public function __construct(EntityManagerInterface $entity_manager, TranslationInterface $string_translation) {
    $this->entityManager = $entity_manager;
    $this->stringTranslation = $string_translation;
  }

  /**
   * {@inheritdoc}
   */
  public function validate($module_name) {
    $reasons = array();

    // We skip fields provided by the Field module as it implements field
    // purging.
    if ($module_name != 'field') {
      foreach ($this->entityManager
        ->getDefinitions() as $entity_type_id => $entity_type) {

        // We skip entity types defined by the module as there must be no
        // content to be able to uninstall them anyway.
        // See \Drupal\Core\Entity\ContentUninstallValidator.
        if ($entity_type
          ->getProvider() != $module_name && $entity_type
          ->isSubclassOf('\\Drupal\\Core\\Entity\\FieldableEntityInterface')) {
          foreach ($this->entityManager
            ->getFieldStorageDefinitions($entity_type_id) as $storage_definition) {
            if ($storage_definition
              ->getProvider() == $module_name) {
              $storage = $this->entityManager
                ->getStorage($entity_type_id);
              if ($storage instanceof FieldableEntityStorageInterface && $storage
                ->countFieldData($storage_definition, TRUE)) {
                $reasons[] = $this
                  ->t('There is data for the field @field-name on entity type @entity_type', array(
                  '@field-name' => $storage_definition
                    ->getName(),
                  '@entity_type' => $entity_type
                    ->getLabel(),
                ));
              }
            }
          }
        }
      }
    }
    return $reasons;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
FieldModuleUninstallValidator::validate public function Determines the reasons a module can not be uninstalled. Overrides ModuleUninstallValidatorInterface::validate
FieldModuleUninstallValidator::__construct public function Constructs the object.
StringTranslationTrait::$stringTranslation protected property The string translation service.
StringTranslationTrait::formatPlural protected function Formats a string containing a count of items.
StringTranslationTrait::getNumberOfPlurals protected function Returns the number of plurals supported by a given language.
StringTranslationTrait::getStringTranslation protected function Gets the string translation service.
StringTranslationTrait::setStringTranslation public function Sets the string translation service to use. 2
StringTranslationTrait::t protected function Translates a string to the current language or to a given language.