You are here

function field_encrypt_test_field_encrypt_allow_encryption in Field Encryption 3.0.x

Implements hook_field_encrypt_allow_encryption().

File

tests/modules/field_encrypt_test/field_encrypt_test.module, line 103
Contains module hooks for field_encrypt_test.

Code

function field_encrypt_test_field_encrypt_allow_encryption(ContentEntityInterface $entity) {
  if (\Drupal::state()
    ->get('field_encrypt_test.hook_field_encrypt_allow_encryption', FALSE)) {
    \Drupal::messenger()
      ->addMessage("Allow encryption hook: Entity title: {$entity->label()}");

    // Only encrypt fields on unpublished nodes.
    if ($entity
      ->getEntityTypeId() === 'node') {
      if ($entity
        ->isPublished()) {
        return FALSE;
      }
    }
  }
}