protected function ProcessEntities::getUnencryptedPlaceholderValue in Field Encryption 3.0.x
Render a placeholder value to be stored in the unencrypted field storage.
Parameters
\Drupal\Core\Entity\ContentEntityInterface $entity: The entity to encrypt fields on.
\Drupal\Core\Field\FieldItemListInterface $field: The field to encrypt.
string $property_name: The property to encrypt.
Return value
mixed The unencrypted placeholder value.
1 call to ProcessEntities::getUnencryptedPlaceholderValue()
- ProcessEntities::encryptFieldValue in src/
ProcessEntities.php - Moves the unencrypted value to the encrypted field storage.
File
- src/
ProcessEntities.php, line 281
Class
- ProcessEntities
- Service class to process entities and fields for encryption.
Namespace
Drupal\field_encryptCode
protected function getUnencryptedPlaceholderValue(ContentEntityInterface $entity, FieldItemListInterface $field, string $property_name) {
$unencrypted_storage_value = NULL;
$property_definitions = $field
->getFieldDefinition()
->getFieldStorageDefinition()
->getPropertyDefinitions();
$data_type = $property_definitions[$property_name]
->getDataType();
switch ($data_type) {
case "string":
case "email":
case "datetime_iso8601":
case "duration_iso8601":
case "uri":
case "filter_format":
// Decimal fields are string data type, but get stored as number.
if ($field
->getFieldDefinition()
->getType() == "decimal") {
$unencrypted_storage_value = 0;
}
else {
$unencrypted_storage_value = static::ENCRYPTED_VALUE;
}
break;
case "integer":
case "boolean":
case "float":
$unencrypted_storage_value = 0;
break;
}
// Allow field storages to override the placeholders.
$field_storage = $field
->getFieldDefinition()
->getFieldStorageDefinition();
if ($field_storage
->isBaseField()) {
$placeholder_overrides = $field_storage
->getSetting('field_encrypt.placeholders') ?? [];
}
else {
$placeholder_overrides = $field_storage
->getThirdPartySetting('field_encrypt', 'placeholders') ?? [];
}
return $placeholder_overrides[$property_name] ?? $unencrypted_storage_value;
}