public function ConsentFormatter::viewElements in General Data Protection Regulation 8
Same name and namespace in other branches
- 8.2 modules/gdpr_consent/src/Plugin/Field/FieldFormatter/ConsentFormatter.php \Drupal\gdpr_consent\Plugin\Field\FieldFormatter\ConsentFormatter::viewElements()
- 3.0.x modules/gdpr_consent/src/Plugin/Field/FieldFormatter/ConsentFormatter.php \Drupal\gdpr_consent\Plugin\Field\FieldFormatter\ConsentFormatter::viewElements()
Builds a renderable array for a field value.
Parameters
\Drupal\Core\Field\FieldItemListInterface $items: The field values to be rendered.
string $langcode: The language that should be used to render the field.
Return value
array A renderable array for $items, as an array of child elements keyed by consecutive numeric indexes starting from 0.
Overrides FormatterInterface::viewElements
File
- modules/
gdpr_consent/ src/ Plugin/ Field/ FieldFormatter/ ConsentFormatter.php, line 76
Class
- ConsentFormatter
- Plugin implementation of the gdpr_consent_formatter formatter.
Namespace
Drupal\gdpr_consent\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$output = [];
$storage = $this->entityTypeManager
->getStorage('gdpr_consent_agreement');
foreach ($items as $delta => $item) {
$agreement = $storage
->loadRevision($item->target_revision_id);
$link = $this
->t('Removed');
if ($agreement) {
$link = $agreement
->toLink($agreement->title->value, 'revision')
->toString();
}
$output[$delta] = [
'name' => [
'#markup' => $this
->t('@title on @date', [
'@title' => $link,
'@date' => $item->date,
]),
],
];
}
return $output;
}