You are here

public function AmpTextFormatter::viewElements in Accelerated Mobile Pages (AMP) 8.3

Same name and namespace in other branches
  1. 8 src/Plugin/Field/FieldFormatter/AmpTextFormatter.php \Drupal\amp\Plugin\Field\FieldFormatter\AmpTextFormatter::viewElements()
  2. 8.2 src/Plugin/Field/FieldFormatter/AmpTextFormatter.php \Drupal\amp\Plugin\Field\FieldFormatter\AmpTextFormatter::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 TextDefaultFormatter::viewElements

File

src/Plugin/Field/FieldFormatter/AmpTextFormatter.php, line 28

Class

AmpTextFormatter
Plugin implementation of the 'amp_text' formatter.

Namespace

Drupal\amp\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {

  // Swap out 'processed_text' type and replace with 'amp_processed_text'.
  $elements = parent::viewElements($items, $langcode);
  foreach ($elements as $delta => $element) {
    if ($element['#type'] == 'processed_text') {
      $elements[$delta]['#type'] = 'amp_processed_text';
    }
  }
  return $elements;
}