You are here

public function EntityReferenceTaxonomyTermRssFormatter::viewElements in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/taxonomy/src/Plugin/Field/FieldFormatter/EntityReferenceTaxonomyTermRssFormatter.php \Drupal\taxonomy\Plugin\Field\FieldFormatter\EntityReferenceTaxonomyTermRssFormatter::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

core/modules/taxonomy/src/Plugin/Field/FieldFormatter/EntityReferenceTaxonomyTermRssFormatter.php, line 31
Contains \Drupal\taxonomy\Plugin\Field\FieldFormatter\EntityReferenceTaxonomyTermRssFormatter.

Class

EntityReferenceTaxonomyTermRssFormatter
Plugin implementation of the 'entity reference taxonomy term RSS' formatter.

Namespace

Drupal\taxonomy\Plugin\Field\FieldFormatter

Code

public function viewElements(FieldItemListInterface $items, $langcode) {
  $parent_entity = $items
    ->getEntity();
  $elements = array();
  foreach ($this
    ->getEntitiesToView($items, $langcode) as $delta => $entity) {
    $parent_entity->rss_elements[] = array(
      'key' => 'category',
      'value' => $entity
        ->label(),
      'attributes' => array(
        'domain' => $entity
          ->id() ? \Drupal::url('entity.taxonomy_term.canonical', [
          'taxonomy_term' => $entity
            ->id(),
        ], array(
          'absolute' => TRUE,
        )) : '',
      ),
    );
  }
  return $elements;
}