You are here

protected function FieldEncryptProcessEntities::getUnencryptedPlaceholderValue in Field Encryption 8.2

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.

2 calls to FieldEncryptProcessEntities::getUnencryptedPlaceholderValue()
FieldEncryptProcessEntities::allowEncryption in src/FieldEncryptProcessEntities.php
Defines if a given field + property on an entity should be encrypted.
FieldEncryptProcessEntities::processValue in src/FieldEncryptProcessEntities.php
Encrypt or decrypt a value.

File

src/FieldEncryptProcessEntities.php, line 333

Class

FieldEncryptProcessEntities
Service class to process entities and fields for encryption.

Namespace

Drupal\field_encrypt

Code

protected function getUnencryptedPlaceholderValue(ContentEntityInterface $entity, FieldItemListInterface $field, $property_name) {
  $unencrypted_storage_value = NULL;
  $property_definitions = $field
    ->getFieldDefinition()
    ->get('fieldStorage')
    ->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 = '[ENCRYPTED]';
      }
      break;
    case "integer":
    case "boolean":
    case "float":
      $unencrypted_storage_value = 0;
      break;
  }
  $context = [
    "entity" => $entity,
    "field" => $field,
    "property" => $property_name,
  ];
  \Drupal::modulehandler()
    ->alter('field_encrypt_unencrypted_storage_value', $unencrypted_storage_value, $context);
  return $unencrypted_storage_value;
}