You are here

private function RightToBeForgottenEntityTraversal::anonymize in General Data Protection Regulation 8

Same name and namespace in other branches
  1. 8.2 modules/gdpr_tasks/src/Traversal/RightToBeForgottenEntityTraversal.php \Drupal\gdpr_tasks\Traversal\RightToBeForgottenEntityTraversal::anonymize()
  2. 3.0.x modules/gdpr_tasks/src/Traversal/RightToBeForgottenEntityTraversal.php \Drupal\gdpr_tasks\Traversal\RightToBeForgottenEntityTraversal::anonymize()

Runs anonymize functionality against a field.

Parameters

\Drupal\Core\Field\FieldItemListInterface $field: The field to anonymize.

\Drupal\Core\Field\FieldDefinitionInterface $field_definition: The field definition.

\Drupal\gdpr_fields\Entity\GdprField $field_config: GDPR field configuration.

Return value

array First element is success boolean, second element is the error message.

1 call to RightToBeForgottenEntityTraversal::anonymize()
RightToBeForgottenEntityTraversal::processEntity in modules/gdpr_tasks/src/Traversal/RightToBeForgottenEntityTraversal.php

File

modules/gdpr_tasks/src/Traversal/RightToBeForgottenEntityTraversal.php, line 210

Class

RightToBeForgottenEntityTraversal
Entity traversal used for Right to be Forgotten requests.

Namespace

Drupal\gdpr_tasks\Traversal

Code

private function anonymize(FieldItemListInterface $field, FieldDefinitionInterface $field_definition, GdprField $field_config) {
  $anonymizer_id = $this
    ->getAnonymizerId($field_definition, $field_config);
  if (!$anonymizer_id) {
    return [
      FALSE,
      "Could not anonymize field {$field->getName()}. Please consider changing this field from 'anonymize' to 'remove', or register a custom anonymizer.",
      NULL,
    ];
  }
  try {
    $anonymizer = $this->anonymizerFactory
      ->get($anonymizer_id);
    $field
      ->setValue($anonymizer
      ->anonymize($field->value, $field));
    return [
      TRUE,
      NULL,
      $anonymizer_id,
    ];
  } catch (\Exception $e) {
    return [
      FALSE,
      $e
        ->getMessage(),
      NULL,
    ];
  }
}