You are here

public function FieldEncryptProcessEntities::entityHasEncryptedFields in Field Encryption 8.2

Check if entity has encrypted fields.

Parameters

\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to check.

Return value

bool TRUE if entity has encrypted fields, FALSE if not.

Overrides FieldEncryptProcessEntitiesInterface::entityHasEncryptedFields

File

src/FieldEncryptProcessEntities.php, line 74

Class

FieldEncryptProcessEntities
Service class to process entities and fields for encryption.

Namespace

Drupal\field_encrypt

Code

public function entityHasEncryptedFields(ContentEntityInterface $entity) {

  // Make sure we can get fields.
  if (!is_callable([
    $entity,
    'getFields',
  ])) {
    return FALSE;
  }
  $encryption_enabled = FALSE;
  foreach ($entity
    ->getFields() as $field) {
    if ($this
      ->checkField($field)) {
      $encryption_enabled = TRUE;
    }
  }
  return $encryption_enabled;
}