You are here

private function RightToBeForgottenEntityTraversal::remove in General Data Protection Regulation 3.0.x

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

Removes the field value.

Parameters

\Drupal\Core\Field\FieldItemListInterface $field: The current field to process.

\Drupal\gdpr_fields\Entity\GdprField $field_config: The current field config.

\Drupal\Core\Entity\EntityInterface $entity: The entity to remove.

Return value

array First element is success boolean, second element is the error message, third element is boolean indicating whether the whole entity should be deleted.

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

File

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

Class

RightToBeForgottenEntityTraversal
Entity traversal used for Right to be Forgotten requests.

Namespace

Drupal\gdpr_tasks\Traversal

Code

private function remove(FieldItemListInterface $field, GdprField $field_config, EntityInterface $entity) {
  try {
    $should_delete = FALSE;

    // If this is the entity's ID, treat the removal as remove the entire
    // entity.
    $entity_type = $entity
      ->getEntityType();
    $error_message = NULL;
    if ($entity_type
      ->getKey('id') == $field
      ->getName()) {
      $should_delete = TRUE;
      return [
        TRUE,
        NULL,
        $should_delete,
      ];
    }

    // Check if the property can be removed.
    if (!$field_config
      ->propertyCanBeRemoved($field
      ->getFieldDefinition(), $error_message)) {
      return [
        FALSE,
        $error_message,
        $should_delete,
      ];
    }

    // Otherwise assume we can simply clear the field.
    $field
      ->setValue(NULL);
    return [
      TRUE,
      NULL,
      $should_delete,
    ];
  } catch (ReadOnlyException $e) {
    return [
      FALSE,
      $e
        ->getMessage(),
      $should_delete,
    ];
  }
}