You are here

protected function RightToAccessDisplayTraversal::processEntity in General Data Protection Regulation 3.0.x

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

Throws

\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException

Overrides EntityTraversal::processEntity

File

modules/gdpr_tasks/src/Traversal/RightToAccessDisplayTraversal.php, line 22

Class

RightToAccessDisplayTraversal
Entity traversal for the Right to Access 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 RTA, then skip it.
    if ($field_config === NULL || !$field_config->enabled || !in_array($field_config->rta, [
      'inc',
      'maybe',
    ])) {
      continue;
    }
    $key = "{$entity_type}.{$entity->id()}.{$field_id}";
    $field_value = $entity
      ->get($field_id)
      ->getString();
    $this->results[$key] = [
      'title' => $field
        ->getLabel(),
      'value' => $field_value,
      'entity' => $entity_definition
        ->getLabel(),
      'bundle' => $this
        ->getBundleLabel($entity),
      'notes' => $field_config->notes,
      'gdpr_rta' => $field_config->rta,
    ];
  }
}