protected function RightToAccessEntityTraversal::getFieldValue in General Data Protection Regulation 3.0.x
Same name and namespace in other branches
- 8.2 modules/gdpr_tasks/src/Traversal/RightToAccessEntityTraversal.php \Drupal\gdpr_tasks\Traversal\RightToAccessEntityTraversal::getFieldValue()
- 8 modules/gdpr_tasks/src/Traversal/RightToAccessEntityTraversal.php \Drupal\gdpr_tasks\Traversal\RightToAccessEntityTraversal::getFieldValue()
Gets the field value, taking into account file references.
Parameters
\Drupal\Core\Entity\FieldableEntityInterface $entity: The current entity being processed.
\Drupal\Core\Field\FieldDefinitionInterface $field: Field definition.
string $fieldId: Field ID.
Return value
string Field value
1 call to RightToAccessEntityTraversal::getFieldValue()
- RightToAccessEntityTraversal::processEntity in modules/
gdpr_tasks/ src/ Traversal/ RightToAccessEntityTraversal.php - Handles the entity.
File
- modules/
gdpr_tasks/ src/ Traversal/ RightToAccessEntityTraversal.php, line 85
Class
- RightToAccessEntityTraversal
- Entity traversal for performing Right to Access requests.
Namespace
Drupal\gdpr_tasks\TraversalCode
protected function getFieldValue(FieldableEntityInterface $entity, FieldDefinitionInterface $field, $fieldId) {
// Special handling for file references.
// For files, we want to add to the assets collection.
$labels = [];
if ($entity->{$fieldId} instanceof EntityReferenceFieldItemList) {
if ($field
->getSetting('target_type') === 'file') {
/** @var \Drupal\file\Entity\File $file */
foreach ($entity->{$fieldId}
->referencedEntities() as $file) {
$this->assets[] = [
'target_id' => $file
->id(),
'display' => 1,
];
$labels[] = "assets/{$file->id()}." . pathinfo($file
->getFileUri(), PATHINFO_EXTENSION);
}
}
else {
/** @var \Drupal\Core\Entity\EntityInterface $referenced_entity */
foreach ($entity->{$fieldId}
->referencedEntities() as $referenced_entity) {
if ($referenced_entity
->label()) {
$labels[] = "{$referenced_entity->label()} [{$referenced_entity->id()}]";
}
else {
$labels[] = $referenced_entity
->id();
}
}
}
}
else {
$labels[] = $entity
->get($fieldId)
->getString();
}
return implode(', ', $labels);
}