You are here

protected function StateManager::getEntityTypes in Field Encryption 3.0.x

Lists entity types which have encrypted fields.

Return value

string[] The list of entity types with encrypted fields. Keyed by entity type ID.

2 calls to StateManager::getEntityTypes()
StateManager::removeStorageFields in src/StateManager.php
Removes storage base fields if possible.
StateManager::update in src/StateManager.php
Figure out which entity types are encrypted.

File

src/StateManager.php, line 204

Class

StateManager
Manages state for the module.

Namespace

Drupal\field_encrypt

Code

protected function getEntityTypes() {
  $entity_types = [];
  foreach ($this->entityTypeManager
    ->getDefinitions() as $entity_type) {
    if ($entity_type instanceof ContentEntityTypeInterface) {
      $storage_class = $this->entityTypeManager
        ->createHandlerInstance($entity_type
        ->getStorageClass(), $entity_type);
      if ($storage_class instanceof DynamicallyFieldableEntityStorageInterface) {
        $entity_type_id = $entity_type
          ->id();

        // Check base fields.
        if ($this->entityTypeManager
          ->getStorage('field_encrypt_entity_type')
          ->load($entity_type_id)) {
          $entity_types[$entity_type_id] = $entity_type_id;
          continue;
        }

        // Query by filtering on the ID as this is more efficient than
        // filtering on the entity_type property directly.
        $ids = $this->entityTypeManager
          ->getStorage('field_storage_config')
          ->getQuery()
          ->condition('id', $entity_type_id . '.', 'STARTS_WITH')
          ->execute();

        // Fetch all fields on entity type.

        /** @var \Drupal\field\FieldStorageConfigInterface[] $field_storages */
        $field_storages = $this->entityTypeManager
          ->getStorage('field_storage_config')
          ->loadMultiple($ids);
        foreach ($field_storages as $storage) {

          // Check if field is encrypted.
          if ($storage
            ->getThirdPartySetting('field_encrypt', 'encrypt', FALSE) == TRUE) {
            $entity_types[$entity_type_id] = $entity_type_id;
            continue 2;
          }
        }
      }
    }
  }
  return $entity_types;
}