Chris@0: config = $config; Chris@18: $this->entityTypeManager = $entity_type_manager; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { Chris@0: return new static( Chris@0: $entity_type, Chris@18: $container->get('entity.repository'), Chris@0: $container->get('language_manager'), Chris@18: $container->get('config.factory')->get('aggregator.settings'), Chris@18: $container->get('theme.registry'), Chris@18: $container->get('entity_display.repository'), Chris@18: $container->get('entity_type.manager') Chris@0: ); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function buildComponents(array &$build, array $entities, array $displays, $view_mode) { Chris@0: parent::buildComponents($build, $entities, $displays, $view_mode); Chris@0: Chris@0: foreach ($entities as $id => $entity) { Chris@0: $bundle = $entity->bundle(); Chris@0: $display = $displays[$bundle]; Chris@0: Chris@0: if ($display->getComponent('items')) { Chris@0: // When in summary view mode, respect the list_max setting. Chris@0: $limit = $view_mode == 'summary' ? $this->config->get('source.list_max') : 20; Chris@0: // Retrieve the items attached to this feed. Chris@18: $items = $this->entityTypeManager Chris@0: ->getStorage('aggregator_item') Chris@0: ->loadByFeed($entity->id(), $limit); Chris@0: Chris@18: $build[$id]['items'] = $this->entityTypeManager Chris@0: ->getViewBuilder('aggregator_item') Chris@0: ->viewMultiple($items, $view_mode, $entity->language()->getId()); Chris@0: Chris@0: if ($view_mode == 'full') { Chris@0: // Also add the pager. Chris@0: $build[$id]['pager'] = ['#type' => 'pager']; Chris@0: } Chris@0: } Chris@0: Chris@0: if ($display->getComponent('description')) { Chris@0: $build[$id]['description'] = [ Chris@0: '#markup' => $entity->getDescription(), Chris@0: '#allowed_tags' => _aggregator_allowed_tags(), Chris@0: '#prefix' => '
', Chris@0: '#suffix' => '
', Chris@0: ]; Chris@0: } Chris@0: Chris@0: if ($display->getComponent('image')) { Chris@0: $image_link = []; Chris@0: // Render the image as link if it is available. Chris@0: $image = $entity->getImage(); Chris@0: $label = $entity->label(); Chris@0: $link_href = $entity->getWebsiteUrl(); Chris@0: if ($image && $label && $link_href) { Chris@0: $link_title = [ Chris@0: '#theme' => 'image', Chris@0: '#uri' => $image, Chris@0: '#alt' => $label, Chris@0: ]; Chris@0: $image_link = [ Chris@0: '#type' => 'link', Chris@0: '#title' => $link_title, Chris@0: '#url' => Url::fromUri($link_href), Chris@0: '#options' => [ Chris@0: 'attributes' => ['class' => ['feed-image']], Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: $build[$id]['image'] = $image_link; Chris@0: } Chris@0: Chris@0: if ($display->getComponent('feed_icon')) { Chris@0: $build[$id]['feed_icon'] = [ Chris@0: '#theme' => 'feed_icon', Chris@0: '#url' => $entity->getUrl(), Chris@0: '#title' => t('@title feed', ['@title' => $entity->label()]), Chris@0: ]; Chris@0: } Chris@0: Chris@0: if ($display->getComponent('more_link')) { Chris@0: $title_stripped = strip_tags($entity->label()); Chris@0: $build[$id]['more_link'] = [ Chris@0: '#type' => 'link', Chris@0: '#title' => t('More posts about @title', [ Chris@0: '@title' => $title_stripped, Chris@0: ]), Chris@0: '#url' => Url::fromRoute('entity.aggregator_feed.canonical', ['aggregator_feed' => $entity->id()]), Chris@0: '#options' => [ Chris@0: 'attributes' => [ Chris@0: 'title' => $title_stripped, Chris@0: ], Chris@0: ], Chris@0: ]; Chris@0: } Chris@0: Chris@0: } Chris@0: } Chris@0: Chris@0: }