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
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | 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 , ), ), ); } } } |
Please login to continue.