public function AmpImageCarousel::viewElements in Accelerated Mobile Pages (AMP) 8.3
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/ AmpImageCarousel.php, line 109
Class
- AmpImageCarousel
- Plugin implementation of the 'amp_image_carousel' formatter.
Namespace
Drupal\amp\Plugin\Field\FieldFormatterCode
public function viewElements(FieldItemListInterface $items, $langcode = NULL) {
$elements = [];
$elements['#items'] = parent::viewElements($items, $langcode);
$layout = $this
->getSetting('layout');
$width = $this
->validWidth($this
->getSetting('width'), $this
->getSetting('layout'));
$height = $this
->validHeight($this
->getSetting('height'), $this
->getSetting('layout'));
foreach ($elements['#items'] as $delta => $item) {
$elements['#items'][$delta]['#item_attributes']['layout'] = $layout;
$elements['#items'][$delta]['#item_attributes']['width'] = $width;
$elements['#items'][$delta]['#item_attributes']['height'] = $height;
$elements['#items'][$delta]['#item_attributes'] = array_filter($elements['#items'][$delta]['#item_attributes']);
$elements['#items'][$delta]['#item_attributes']['loading'] = FALSE;
}
$elements['#attributes']['type'] = $this
->getSetting('type');
$elements['#attributes']['layout'] = $layout;
$elements['#attributes']['width'] = $width;
$elements['#attributes']['height'] = $height;
$elements['#attributes']['controls'] = $this
->getSetting('controls');
$elements['#attributes']['loop'] = $this
->getSetting('loop');
$elements['#attributes'] = array_filter($elements['#attributes']);
$elements['#theme'] = 'amp_image_carousel';
$elements['#attached']['library'] = $this
->getLibraries();
return $elements;
}