public function EncryptedFieldValueManager::saveEncryptedFieldValues in Field Encryption 8.2
Save encrypted field values and link them to their parent entity.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to save EncryptedFieldValue entities for.
Overrides EncryptedFieldValueManagerInterface::saveEncryptedFieldValues
File
- src/
EncryptedFieldValueManager.php, line 63
Class
- EncryptedFieldValueManager
- Manager containing common functions to manage EncryptedFieldValue entities.
Namespace
Drupal\field_encryptCode
public function saveEncryptedFieldValues(ContentEntityInterface $entity) {
if (!empty($entity->encrypted_field_values)) {
foreach ($entity->encrypted_field_values as $encrypted_field_value) {
if ($encrypted_field_value instanceof EncryptedFieldValueInterface) {
// Update the parent entity (revision) id, now that it's known.
$encrypted_field_value
->set('entity_id', $entity
->id());
$encrypted_field_value
->set('entity_revision_id', $this
->getEntityRevisionId($entity));
// Actually save the EncryptedFieldValue entity.
$encrypted_field_value
->save();
}
}
unset($entity->encrypted_field_values);
}
}