You are here

private function Anonymizer::remove in General Data Protection Regulation 7

Removes the field value.

Parameters

array $field_info: The current field to process.

object|EntityInterface $entity: The current field to process.

Return value

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

1 call to Anonymizer::remove()
Anonymizer::run in modules/gdpr_tasks/src/Anonymizer.php
Runs anonymization routines against a user.

File

modules/gdpr_tasks/src/Anonymizer.php, line 154

Class

Anonymizer
Anonymizes or removes field values for GDPR.

Code

private function remove(array $field_info, $entity) {
  try {
    $entity_type = $field_info['entity_type'];
    $field = $field_info['plugin']->property_name;

    // If this is the entity's ID, treat the removal as remove the entire
    // entity.
    if (self::propertyIsEntityId($entity_type, $field)) {
      if (entity_delete($entity_type, $entity->{$field}) === FALSE) {
        return array(
          FALSE,
          "Unable to delete entity type.",
        );
      }
      return array(
        TRUE,
        NULL,
      );
    }

    // Check if the property can be removed.
    $wrapper = entity_metadata_wrapper($entity_type, $entity);
    if (!self::propertyCanBeRemoved($entity_type, $field, $wrapper->{$field}
      ->info(), $error_message)) {
      return array(
        FALSE,
        $error_message,
      );
    }

    // Otherwise assume we can simply clear the field.
    $entity->{$field} = NULL;
    return array(
      TRUE,
      NULL,
    );
  } catch (Exception $e) {
    return array(
      FALSE,
      $e
        ->getMessage(),
    );
  }
}