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.
- field_encrypt_entity_storage_load() needs to be the first implementation of hook_entity_storage_load() so other implementations can use decrypted data.
- field_encrypt_entity_presave() needs to be the last implementation of hook_entity_presave() so other implementations can use decrypted data.
- field_encrypt_entity_insert() and field_encrypt_entity_update() can not be triggered in the correct location as hook_ENTITY_TYPE_insert() and hook_ENTITY_TYPE_update() are triggered first. Field encrypt tries to get around this by dynamically declaring hook_ENTITY_TYPE_insert() and hook_ENTITY_TYPE_update() implementations.
See also
field_encrypt_entity_storage_load()
field_encrypt_entity_presave()
_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;
}
}
}
}