You are here

function field_encrypt_module_implements_alter in Field Encryption 3.0.x

Implements hook_module_implements_alter().

The Field Encrypt module decrypts and encrypts entity data by implementing regular entity hooks. The order in which the hooks are fired determines whether the entity data is encrypted or decrypted. It is important for that for other implementations of these hooks that data is encrypted and decrypted at the right time.

See also

field_encrypt_entity_storage_load()

field_encrypt_entity_presave()

field_encrypt_entity_insert()

field_encrypt_entity_update()

_field_encrypt_define_entity_hooks()

\Drupal\Core\Entity\EntityStorageBase::invokeHook()

File

./field_encrypt.module, line 301
Contains module hooks for field_encrypt.

Code

function field_encrypt_module_implements_alter(&$implementations, $hook) {
  if ($hook == 'entity_presave') {

    // Move our implementation as late as possible so other implementations work
    // with decrypted data.
    $group = $implementations['field_encrypt'];
    unset($implementations['field_encrypt']);
    $implementations['field_encrypt'] = $group;
  }
  elseif ($hook == 'entity_storage_load' || $hook == 'entity_insert' || $hook == 'entity_update') {

    // Move our implementations as early as possible so other implementations
    // work with decrypted data.
    $group = $implementations['field_encrypt'];
    $implementations = [
      'field_encrypt' => $group,
    ] + $implementations;
  }
  elseif (preg_match('/_(insert|update)$/', $hook)) {
    foreach (\Drupal::state()
      ->get('field_encrypt.entity_types', []) as $entity_type_id) {
      if ($hook == $entity_type_id . '_insert' || $hook == $entity_type_id . '_update') {

        // Move our implementations as early as possible so other
        // implementations work with decrypted data.
        if (!isset($implementations['field_encrypt'])) {
          _field_encrypt_define_entity_hooks($entity_type_id);
        }
        $group = $implementations['field_encrypt'] ?? FALSE;
        $implementations = [
          'field_encrypt' => $group,
        ] + $implementations;
      }
    }
  }
}