diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php index 571d616..648a171 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php @@ -30,6 +30,13 @@ class TimestampAgoFormatter extends FormatterBase implements ContainerFactoryPluginInterface { /** + * The date formatter service. + * + * @var \Drupal\Core\Datetime\DateFormatter + */ + protected $dateFormatter; + + /** * Constructs a TimestampAgoFormatter object. * * @param string $plugin_id @@ -47,7 +54,7 @@ class TimestampAgoFormatter extends FormatterBase implements ContainerFactoryPlu * @param array $third_party_settings * Any third party settings settings. * @param \Drupal\Core\Datetime\DateFormatter $date_formatter - * The date formatter service. + * The date formatter service. */ public function __construct($plugin_id, $plugin_definition, FieldDefinitionInterface $field_definition, array $settings, $label, $view_mode, array $third_party_settings, DateFormatter $date_formatter) { parent::__construct($plugin_id, $plugin_definition, $field_definition, $settings, $label, $view_mode, $third_party_settings); @@ -83,7 +90,7 @@ public function viewElements(FieldItemListInterface $items) { $updated = $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $item->value))); } else { - $updated = t('never'); + $updated = $this->t('never'); } $elements[$delta] = array('#markup' => $updated); diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php index df12a53..8209e1e 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php @@ -2,7 +2,7 @@ /** * @file - * Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\UriFormatter. + * Contains \Drupal\Core\Field\Plugin\Field\FieldFormatter\UriLinkFormatter. */ namespace Drupal\Core\Field\Plugin\Field\FieldFormatter; diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 7cf2e73..053dcd3 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -105,6 +105,7 @@ function aggregator_entity_extra_field_info() { 'description' => t('Items associated with this feed'), 'weight' => 0, ), + // @todo Move to a formatter at https://www.drupal.org/node/2339917. 'image' => array( 'label' => t('Image'), 'description' => t('The feed image'), @@ -116,16 +117,21 @@ function aggregator_entity_extra_field_info() { 'description' => t('The description of this feed'), 'weight' => 3, ), + 'more_link' => array( + 'label' => t('More link'), + 'description' => t('A more link to the feed detail page'), + 'weight' => 5, + ), + 'feed_icon' => array( + 'label' => t('Feed icon'), + 'description' => t('An icon that links to the feed url'), + 'weight' => 6, + ), ), ); $extra['aggregator_item']['aggregator_item'] = array( 'display' => array( - 'feed' => array( - 'label' => t('Source feed'), - 'description' => t('The aggregator feed entity associated with this item'), - 'weight' => 0, - ), // @todo Move to a formatter at https://drupal.org/node/2149845. 'description' => array( 'label' => t('Description'), diff --git a/core/modules/aggregator/aggregator.theme.inc b/core/modules/aggregator/aggregator.theme.inc index f20dbf5..e90a798 100644 --- a/core/modules/aggregator/aggregator.theme.inc +++ b/core/modules/aggregator/aggregator.theme.inc @@ -78,29 +78,6 @@ function template_preprocess_aggregator_feed(&$variables) { } $variables['full'] = $variables['elements']['#view_mode'] == 'full'; $variables['title'] = String::checkPlain($feed->label()); - if ($variables['full']) { - $variables['link'] = array( - '#theme' => 'feed_icon', - '#url' => $feed->getUrl(), - '#title' => t('!title feed', array('!title' => $feed->label())), - ); - } - else { - $title_stripped = strip_tags($feed->label()); - $variables['link'] = array( - '#type' => 'link', - '#title' => t('More posts about @title', array( - '@title' => $title_stripped, - )), - '#href' => 'aggregator/sources/' . $feed->id(), - '#options' => array( - 'html' => TRUE, - 'attributes' => array( - 'title' => $title_stripped, - ), - ), - ); - } } /** diff --git a/core/modules/aggregator/config/install/core.entity_view_display.aggregator_feed.aggregator_feed.default.yml b/core/modules/aggregator/config/install/core.entity_view_display.aggregator_feed.aggregator_feed.default.yml new file mode 100644 index 0000000..9474720 --- /dev/null +++ b/core/modules/aggregator/config/install/core.entity_view_display.aggregator_feed.aggregator_feed.default.yml @@ -0,0 +1,34 @@ +id: aggregator_feed.aggregator_feed.default +label: null +targetEntityType: aggregator_feed +bundle: aggregator_feed +mode: default +langcode: en +status: true +content: + items: + weight: 0 + checked: + type: timestamp_ago + weight: 1 + settings: { } + third_party_settings: { } + label: inline + image: + weight: 2 + description: + weight: 3 + link: + type: uri_link + weight: 4 + settings: { } + third_party_settings: { } + label: inline + feed_icon: + weight: 5 +hidden: + more_link: true +third_party_settings: { } +dependencies: + module: + - aggregator diff --git a/core/modules/aggregator/config/install/core.entity_view_display.aggregator_feed.aggregator_feed.summary.yml b/core/modules/aggregator/config/install/core.entity_view_display.aggregator_feed.aggregator_feed.summary.yml index f9f14b8..5278f31 100644 --- a/core/modules/aggregator/config/install/core.entity_view_display.aggregator_feed.aggregator_feed.summary.yml +++ b/core/modules/aggregator/config/install/core.entity_view_display.aggregator_feed.aggregator_feed.summary.yml @@ -5,11 +5,14 @@ mode: summary content: items: weight: 0 + more_link: + weight: 1 hidden: link: true checked: true description: true image: true + feed_icon: true status: true dependencies: entity: diff --git a/core/modules/aggregator/config/install/core.entity_view_display.aggregator_item.aggregator_item.summary.yml b/core/modules/aggregator/config/install/core.entity_view_display.aggregator_item.aggregator_item.summary.yml index c29ffeb..bffdb9c 100644 --- a/core/modules/aggregator/config/install/core.entity_view_display.aggregator_item.aggregator_item.summary.yml +++ b/core/modules/aggregator/config/install/core.entity_view_display.aggregator_item.aggregator_item.summary.yml @@ -16,3 +16,4 @@ dependencies: - core.entity_view_mode.aggregator_item.summary module: - aggregator + - entity_reference diff --git a/core/modules/aggregator/src/Entity/Item.php b/core/modules/aggregator/src/Entity/Item.php index 1d7fc5c..5df7013 100644 --- a/core/modules/aggregator/src/Entity/Item.php +++ b/core/modules/aggregator/src/Entity/Item.php @@ -58,9 +58,15 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setSetting('unsigned', TRUE); $fields['fid'] = BaseFieldDefinition::create('entity_reference') - ->setLabel(t('Aggregator feed ID')) - ->setDescription(t('The ID of the aggregator feed.')) - ->setSetting('target_type', 'aggregator_feed'); + ->setLabel(t('Source feed')) + ->setDescription(t('The aggregator feed entity associated with this item.')) + ->setSetting('target_type', 'aggregator_feed') + ->setDisplayOptions('view', array( + 'label' => 'hidden', + 'type' => 'entity_reference_label', + 'weight' => 0, + )) + ->setDisplayConfigurable('form', TRUE); $fields['title'] = BaseFieldDefinition::create('string') ->setLabel(t('Title')) diff --git a/core/modules/aggregator/src/FeedViewBuilder.php b/core/modules/aggregator/src/FeedViewBuilder.php index 84fa2ad..d42641a 100644 --- a/core/modules/aggregator/src/FeedViewBuilder.php +++ b/core/modules/aggregator/src/FeedViewBuilder.php @@ -30,7 +30,7 @@ class FeedViewBuilder extends EntityViewBuilder { * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. * @param \Drupal\Core\Config\Config $config - * The 'aggregator.settings' config. + * The 'aggregator.settings' config. */ public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, Config $config) { parent::__construct($entity_type, $entity_manager, $language_manager); @@ -60,7 +60,7 @@ public function buildComponents(array &$build, array $entities, array $displays, $display = $displays[$bundle]; if ($display->getComponent('items')) { - // When in summary view mode respect the list_max setting. + // 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 @@ -109,6 +109,33 @@ public function buildComponents(array &$build, array $entities, array $displays, } $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 posts about @title', array( + '@title' => $title_stripped, + )), + '#route_name' => 'entity.aggregator_feed.canonical', + '#route_parameters' => array('aggregator_feed' => $entity->id()), + '#options' => array( + 'html' => TRUE, + 'attributes' => array( + 'title' => $title_stripped, + ), + ), + ); + } + } } diff --git a/core/modules/aggregator/src/ItemViewBuilder.php b/core/modules/aggregator/src/ItemViewBuilder.php index 0a0b5ce..a6488bb 100644 --- a/core/modules/aggregator/src/ItemViewBuilder.php +++ b/core/modules/aggregator/src/ItemViewBuilder.php @@ -25,25 +25,6 @@ public function buildComponents(array &$build, array $entities, array $displays, $bundle = $entity->bundle(); $display = $displays[$bundle]; - if ($display->getComponent('feed')) { - // Retrieve the feed. - $feed = $this->entityManager - ->getStorage('aggregator_feed') - ->load($entity->getFeedId()); - - // Render the feed title as well a link to it. - $build[$id]['feed'] = array( - '#type' => 'link', - '#title' => $feed->label(), - '#href' => 'aggregator/sources/' . $feed->id(), - '#options' => array( - 'attributes' => array('class' => array('feed-item-source')), - ), - '#prefix' => '
', - '#suffix' => '
', - ); - } - if ($display->getComponent('description')) { $build[$id]['description'] = array( '#markup' => aggregator_filter_xss($entity->getDescription()), diff --git a/core/modules/aggregator/templates/aggregator-feed.html.twig b/core/modules/aggregator/templates/aggregator-feed.html.twig index 8cd7c11..1876c45 100644 --- a/core/modules/aggregator/templates/aggregator-feed.html.twig +++ b/core/modules/aggregator/templates/aggregator-feed.html.twig @@ -8,7 +8,6 @@ * * Available variables: * - title: Title of the feed item. - * - link: A "Read more" link on summary view mode, a feed icon on full mode. * - content: All field items. Use {{ content }} to print them all, * or print a subset such as {{ content.field_example }}. Use * {{ content|without('field_example') }} to temporarily suppress the printing @@ -29,6 +28,4 @@ {{ content }} - {{ link }} -