You are here

protected function EntityTypeForm::getBaseFields in Field Encryption 3.0.x

Gets a list of base fields that can be encrypted for an entity type.

Parameters

string $entity_type_id: The entity type ID.

Return value

string[]|\Drupal\Core\StringTranslation\TranslatableMarkup[] A array of base fields labels that can be encrypted. Keyed by base field name.

1 call to EntityTypeForm::getBaseFields()
EntityTypeForm::buildForm in src/Form/EntityTypeForm.php
Form constructor.

File

src/Form/EntityTypeForm.php, line 275

Class

EntityTypeForm
Configures field encryption on the entity type level.

Namespace

Drupal\field_encrypt\Form

Code

protected function getBaseFields($entity_type_id) {
  $possible_fields = [];
  $entity_type = $this->entityTypeManager
    ->getDefinition($entity_type_id);
  $excluded_fields = [
    'id',
    'revision',
    'bundle',
    'langcode',
    'uuid',
  ];
  $excluded_fields = array_filter(array_map(function ($key) use ($entity_type) {
    return $entity_type
      ->getKey($key);
  }, $excluded_fields));

  // Can't encrypt the encrypted field.
  $excluded_fields[] = ProcessEntities::ENCRYPTED_FIELD_STORAGE_NAME;
  foreach ($this->entityFieldManager
    ->getBaseFieldDefinitions($entity_type_id) as $base_field) {
    if (!in_array($base_field
      ->getName(), $excluded_fields, TRUE)) {
      $possible_fields[$base_field
        ->getName()] = $base_field
        ->getLabel();
    }
  }
  return $possible_fields;
}