FeedViewBuilder::buildComponents

public FeedViewBuilder::buildComponents(array &$build, array $entities, array $displays, $view_mode)

Builds the component fields and properties of a set of entities.

Parameters

&$build: The renderable array representing the entity content.

\Drupal\Core\Entity\EntityInterface[] $entities: The entities whose content is being built.

\Drupal\Core\Entity\Display\EntityViewDisplayInterface[] $displays: The array of entity view displays holding the display options configured for the entity components, keyed by bundle name.

string $view_mode: The view mode in which the entity is being viewed.

Overrides EntityViewBuilder::buildComponents

File

core/modules/aggregator/src/FeedViewBuilder.php, line 50

Class

FeedViewBuilder
View builder handler for aggregator feeds.

Namespace

Drupal\aggregator

Code

public function buildComponents(array &$build, array $entities, array $displays, $view_mode) {
  parent::buildComponents($build, $entities, $displays, $view_mode);

  foreach ($entities as $id => $entity) {
    $bundle = $entity->bundle();
    $display = $displays[$bundle];

    if ($display->getComponent('items')) {
      // When in summary view mode, respect the list_max setting.
      $limit = $view_mode == 'summary' ? $this->config->get('source.list_max') : 20;
      // Retrieve the items attached to this feed.
      $items = $this->entityManager
        ->getStorage('aggregator_item')
        ->loadByFeed($entity->id(), $limit);

      $build[$id]['items'] = $this->entityManager
        ->getViewBuilder('aggregator_item')
        ->viewMultiple($items, $view_mode, $entity->language()->getId());

      if ($view_mode == 'full') {
        // Also add the pager.
        $build[$id]['pager'] = array('#type' => 'pager');
      }
    }

    if ($display->getComponent('description')) {
      $build[$id]['description'] = array(
        '#markup' => $entity->getDescription(),
        '#allowed_tags' => _aggregator_allowed_tags(),
        '#prefix' => '<div class="feed-description">',
        '#suffix' => '</div>',
      );
    }

    if ($display->getComponent('image')) {
      $image_link = array();
      // Render the image as link if it is available.
      $image = $entity->getImage();
      $label = $entity->label();
      $link_href = $entity->getWebsiteUrl();
      if ($image && $label && $link_href) {
        $link_title = array(
          '#theme' => 'image',
          '#uri' => $image,
          '#alt' => $label,
        );
        $image_link = array(
          '#type' => 'link',
          '#title' => $link_title,
          '#url' => Url::fromUri($link_href),
          '#options' => array(
            'attributes' => array('class' => array('feed-image')),
          ),
        );
      }
      $build[$id]['image'] = $image_link;
    }

    if ($display->getComponent('feed_icon')) {
      $build[$id]['feed_icon'] = array(
        '#theme' => 'feed_icon',
        '#url' => $entity->getUrl(),
        '#title' => t('@title feed', array('@title' => $entity->label())),
      );
    }

    if ($display->getComponent('more_link')) {
      $title_stripped = strip_tags($entity->label());
      $build[$id]['more_link'] = array(
        '#type' => 'link',
        '#title' => t('More<span class="visually-hidden"> posts about @title</span>', array(
          '@title' => $title_stripped,
        )),
        '#url' => Url::fromRoute('entity.aggregator_feed.canonical', ['aggregator_feed' => $entity->id()]),
        '#options' => array(
          'attributes' => array(
            'title' => $title_stripped,
          ),
        ),
      );
    }

  }
}
doc_Drupal
2016-10-29 09:10:23
Comments
Leave a Comment

Please login to continue.