Problem/Motivation

Part of a decryption/encryption strategy is that the database never store the decrypted values.
The code in \Drupal\Core\Entity\Sql\SqlContentEntityStorage::doLoadMultiple thought basically disagrees with that:

    if ($entities_from_storage = $this->getFromStorage($ids)) {
      $this->invokeStorageLoadHook($entities_from_storage);
      $this->setPersistentCache($entities_from_storage);
    }

Proposed resolution

Maybe switch to hook_entity_load() instead?

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
#3 2743073-2.patch695 bytesdawehner
#2 2743073-2.patch695 bytesdawehner

Comments

dawehner created an issue. See original summary.

dawehner’s picture

Status: Active » Needs review
StatusFileSize
new695 bytes

Let's see whether this causes any failure for itself

dawehner’s picture

StatusFileSize
new695 bytes

Let's reupload for automated testing

nerdstein’s picture

dawehner, I am cool with the patch, but the tests are failing. Can we connect on this to see why?

talhaparacha’s picture

Status: Needs review » Closed (works as designed)

I don't think there is any need for switching from hook_entity_storage_load() to hook_entity_load().

The latest 8.x-2.x-dev provides the feature of setting an entity type as "uncacheable" as can be seen in the field_encrypt_entity_type_alter() hook:

$entity_types[$uncacheable_type]->set('static_cache', FALSE);
$entity_types[$uncacheable_type]->set('render_cache', FALSE);
$entity_types[$uncacheable_type]->set('persistent_cache', FALSE);

And ContentEntityStorageBase::setPersistentCache() method does effectively nothing on any entity type which has its persistent_cache set to FALSE as can be seen in it's source code:

if (!$this->entityType->isPersistentlyCacheable()) {
    return;
}

This ensures that whenever a field to be encrypted is marked as "uncacheable" in the Field Encrypt settings, then the corresponding entity will never get cached not even after hook_entity_storage_load() invocations. Hence closing this issue for now.