public function AmpImageFormatter::viewElements in Accelerated Mobile Pages (AMP) 8
Same name and namespace in other branches
- 8.3 src/Plugin/Field/FieldFormatter/AmpImageFormatter.php \Drupal\amp\Plugin\Field\FieldFormatter\AmpImageFormatter::viewElements()
- 8.2 src/Plugin/Field/FieldFormatter/AmpImageFormatter.php \Drupal\amp\Plugin\Field\FieldFormatter\AmpImageFormatter::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 ImageFormatter::viewElements
File
- src/
Plugin/ Field/ FieldFormatter/ AmpImageFormatter.php, line 110 - Contains \Drupal\amp\Plugin\Field\FieldFormatter\AmpImageFormatter.
Class
- AmpImageFormatter
- Plugin implementation of the 'amp_image' formatter.
Namespace
Drupal\amp\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode) {
$elements = parent::viewElements($items, $langcode);
foreach ($elements as $delta => $element) {
$elements[$delta]['#item_attributes']['layout'] = $this
->getSetting('amp_layout');
if ($this
->getSetting('amp_layout') == 'fixed-height') {
$elements[$delta]['#item_attributes']['height'] = $this
->getSetting('amp_fixed_height');
$elements[$delta]['#item_attributes']['width'] = 'auto';
}
}
return $elements;
}