You are here

protected function RightToBeForgottenDisplayTraversal::processEntity in General Data Protection Regulation 8

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

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

\Drupal\Core\Entity\EntityMalformedException

Overrides EntityTraversal::processEntity

File

modules/gdpr_tasks/src/Traversal/RightToBeForgottenDisplayTraversal.php, line 23

Class

RightToBeForgottenDisplayTraversal
Entity traversal for the right to be forgotten preview display.

Namespace

Drupal\gdpr_tasks\Traversal

Code

protected function processEntity(FieldableEntityInterface $entity, GdprFieldConfigEntity $config, $row_id, GdprField $parent_config = NULL) {
  $entity_type = $entity
    ->getEntityTypeId();
  $entity_definition = $entity
    ->getEntityType();
  $fields = $this->entityFieldManager
    ->getFieldDefinitions($entity_type, $entity
    ->bundle());
  $field_configs = $config
    ->getFieldsForBundle($entity
    ->bundle());
  foreach ($fields as $field_id => $field) {
    $field_config = isset($field_configs[$field_id]) ? $field_configs[$field_id] : NULL;

    // If the field is not configured, not enabled,
    // or not enabled for RTF, then skip it.
    if ($field_config === NULL || !$field_config->enabled || !in_array($field_config->rtf, [
      'anonymize',
      'remove',
      'maybe',
    ])) {
      continue;
    }
    $key = "{$entity_type}.{$entity->id()}.{$field_id}";
    $this->results[$key] = [
      'title' => $field
        ->getLabel(),
      'value' => $entity
        ->get($field_id)
        ->getString(),
      'entity' => $entity_definition
        ->getLabel(),
      'bundle' => $this
        ->getBundleLabel($entity),
      'notes' => $field_config->notes,
      'gdpr_rtf' => $field_config->rtf,
      'link' => $field_config->rtf == 'maybe' ? $entity
        ->toLink('Edit', 'edit-form') : '',
    ];
  }
}