You are here

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

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

Handles the entity.

By default this just returns the entity instance, but derived classes should override this method if they need to collect additional data on the instance.

Parameters

\Drupal\Core\Entity\FieldableEntityInterface $entity: The entity to handle.

\Drupal\gdpr_fields\Entity\GdprFieldConfigEntity $config: GDPR config for this entity.

string $row_id: Row identifier used in SARs.

\Drupal\gdpr_fields\Entity\GdprField|null $parent_config: Parent's config.

Overrides EntityTraversal::processEntity

File

modules/gdpr_tasks/src/Traversal/RightToAccessEntityTraversal.php, line 24

Class

RightToAccessEntityTraversal
Entity traversal for performing Right to Access requests.

Namespace

Drupal\gdpr_tasks\Traversal

Code

protected function processEntity(FieldableEntityInterface $entity, GdprFieldConfigEntity $config, $row_id, GdprField $parent_config = NULL) {
  $entity_type = $entity
    ->getEntityTypeId();
  $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;
    }
    $plugin_name = "{$entity_type}|{$entity->bundle()}|{$field_id}";
    $filename = 'main';
    if ($parent_config) {
      $filename = !empty($parent_config->sarsFilename) ? $parent_config->sarsFilename : $filename;
    }
    $field_value = $this
      ->getFieldValue($entity, $field, $field_id);
    $data = [
      'plugin_name' => $plugin_name,
      'entity_type' => $entity_type,
      'entity_id' => $entity
        ->id(),
      'file' => $filename,
      'row_id' => $row_id,
      'label' => $field
        ->getLabel(),
      'value' => $field_value,
      'notes' => $field_config->notes,
      'rta' => $field_config->rta,
    ];
    $this->results["{$plugin_name}|{$entity->id()}"] = $data;
  }
}