diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php new file mode 100644 index 0000000..a6522e9 --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php @@ -0,0 +1,46 @@ + $item) { + $elements[$delta] = array( + '#type' => 'link', + '#href' => $item->value, + '#title' => $item->value, + // @todo Make this configurable? + '#options' => array('absolute' => TRUE), + ); + } + + return $elements; + } + +} diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php index 693e4ce..6db2b9c 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldType/UriItem.php @@ -21,7 +21,8 @@ * id = "uri", * label = @Translation("URI"), * description = @Translation("An entity field containing a URI."), - * no_ui = TRUE + * no_ui = TRUE, + * default_formatter = "uri_link", * ) */ class UriItem extends StringItem { diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index c0ff91e..d6f4690 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -92,15 +92,6 @@ function aggregator_permission() { } /** - * Implements hook_entity_bundle_info(). - */ -function aggregator_entity_bundle_info() { - $bundles['aggregator_feed']['aggregator_feed']['label'] = t('Aggregator feed'); - $bundles['aggregator_item']['aggregator_item']['label'] = t('Aggregator item'); - return $bundles; -} - -/** * Implements hook_entity_extra_field_info(). */ function aggregator_entity_extra_field_info() { @@ -113,25 +104,23 @@ function aggregator_entity_extra_field_info() { 'description' => t('Items associated with this feed'), 'weight' => 0, ), - 'link' => array( - 'label' => t('Link'), - 'description' => t("The link to this feed's website"), - 'weight' => 0, - ), + // @todo Move to a formatter after https://drupal.org/node/2226493 which + // provides the TimestampFormatter is in. 'checked' => array( 'label' => t('Last checked'), 'description' => t('When this feed was last checked'), - 'weight' => 0, - ), - 'description' => array( - 'label' => t('Description'), - 'description' => t('The description of this feed'), - 'weight' => 0, + 'weight' => 1, ), 'image' => array( 'label' => t('Image'), 'description' => t('The feed image'), - 'weight' => 0, + 'weight' => 2, + ), + // @todo Move to a formatter at https://drupal.org/node/2149845. + 'description' => array( + 'label' => t('Description'), + 'description' => t('The description of this feed'), + 'weight' => 3, ), ), ); @@ -143,25 +132,18 @@ function aggregator_entity_extra_field_info() { 'description' => t('The aggregator feed entity associated with this item'), 'weight' => 0, ), - 'link' => array( - 'label' => t('Link'), - 'description' => t("The link to this feed item"), - 'weight' => 0, - ), - 'author' => array( - 'label' => t('Author'), - 'description' => t('Author of this feed item'), - 'weight' => 0, + // @todo Move to a formatter after https://drupal.org/node/2226493 which + // provides the TimestampFormatter is in. + 'timestamp' => array( + 'label' => t('Date'), + 'description' => t('Posted date of the feed as time ago'), + 'weight' => 1, ), + // @todo Move to a formatter at https://drupal.org/node/2149845. 'description' => array( 'label' => t('Description'), 'description' => t('The description of this feed item'), - 'weight' => 0, - ), - 'timestamp' => array( - 'label' => t('Date'), - 'description' => t('Posted date of the feed as time ago'), - 'weight' => 0, + 'weight' => 2, ), ), ); diff --git a/core/modules/aggregator/aggregator.routing.yml b/core/modules/aggregator/aggregator.routing.yml index 4cdd2fe..206bfd7 100644 --- a/core/modules/aggregator/aggregator.routing.yml +++ b/core/modules/aggregator/aggregator.routing.yml @@ -52,7 +52,7 @@ aggregator.feed_add: aggregator.feed_view: path: '/aggregator/sources/{aggregator_feed}' defaults: - _content: '\Drupal\aggregator\Controller\AggregatorController::viewFeed' + _entity_view: 'aggregator_feed' _title_callback: '\Drupal\aggregator\Controller\AggregatorController::feedTitle' requirements: _permission: 'access news feeds' diff --git a/core/modules/aggregator/aggregator.theme.inc b/core/modules/aggregator/aggregator.theme.inc index c356593..ae78297 100644 --- a/core/modules/aggregator/aggregator.theme.inc +++ b/core/modules/aggregator/aggregator.theme.inc @@ -78,7 +78,7 @@ function template_preprocess_aggregator_feed(&$variables) { $variables['content'][$key] = $variables['elements'][$key]; } - $variables['full'] = $variables['elements']['#view_mode'] == 'default'; + $variables['full'] = $variables['elements']['#view_mode'] == 'full'; $variables['title'] = String::checkPlain($feed->label()); if ($variables['full']) { $variables['link'] = array( diff --git a/core/modules/aggregator/config/install/entity.view_display.aggregator_feed.aggregator_feed.default.yml b/core/modules/aggregator/config/install/entity.view_display.aggregator_feed.aggregator_feed.default.yml deleted file mode 100644 index 872e486..0000000 --- a/core/modules/aggregator/config/install/entity.view_display.aggregator_feed.aggregator_feed.default.yml +++ /dev/null @@ -1,18 +0,0 @@ -id: aggregator_feed.aggregator_feed.default -targetEntityType: aggregator_feed -bundle: aggregator_feed -mode: default -content: - items: - weight: 0 - checked: - weight: 1 - image: - weight: 2 - description: - weight: 3 - link: - weight: 4 -hidden: { } -status: true -dependencies: { } diff --git a/core/modules/aggregator/config/install/entity.view_display.aggregator_item.aggregator_item.default.yml b/core/modules/aggregator/config/install/entity.view_display.aggregator_item.aggregator_item.default.yml deleted file mode 100644 index d859836..0000000 --- a/core/modules/aggregator/config/install/entity.view_display.aggregator_item.aggregator_item.default.yml +++ /dev/null @@ -1,16 +0,0 @@ -id: aggregator_item.aggregator_item.default -targetEntityType: aggregator_item -bundle: aggregator_item -mode: default -content: - feed: - weight: 0 - timestamp: - weight: 1 - description: - weight: 2 -hidden: - link: true - author: true -status: true -dependencies: { } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php index 616e1a6..3f26cf8 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php @@ -33,21 +33,6 @@ public function feedAdd() { } /** - * Displays all the items captured from the particular feed. - * - * @param \Drupal\aggregator\FeedInterface $aggregator_feed - * The feed for which to display all items. - * - * @return array - * The rendered list of items for the feed. - */ - public function viewFeed(FeedInterface $aggregator_feed) { - return $this->entityManager() - ->getViewBuilder('aggregator_feed') - ->view($aggregator_feed, 'default'); - } - - /** * Builds a listing of aggregator feed items. * * @param \Drupal\aggregator\ItemInterface[] $items diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php index d40ec0a..d7fdec10 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php @@ -187,8 +187,13 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('Time when this feed was queued for refresh, 0 if not queued.')); $fields['link'] = FieldDefinition::create('uri') - ->setLabel(t('Link')) - ->setDescription(t('The link of the feed.')); + ->setLabel(t('URL')) + ->setDescription(t('The link of the feed.')) + ->setDisplayOptions('view', array( + 'label' => 'inline', + 'weight' => 4, + )) + ->setDisplayConfigurable('view', TRUE); $fields['description'] = FieldDefinition::create('string_long') ->setLabel(t('Description')) diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php index bb9e0aa..b2a587f 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php @@ -65,11 +65,20 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['link'] = FieldDefinition::create('uri') ->setLabel(t('Link')) - ->setDescription(t('The link of the feed item.')); + ->setDescription(t('The link of the feed item.')) + ->setDisplayOptions('view', array( + 'type' => 'hidden', + )) + ->setDisplayConfigurable('view', TRUE); $fields['author'] = FieldDefinition::create('string') ->setLabel(t('Author')) - ->setDescription(t('The author of the feed item.')); + ->setDescription(t('The author of the feed item.')) + ->setDisplayOptions('view', array( + 'label' => 'hidden', + 'weight' => 3, + )) + ->setDisplayConfigurable('view', TRUE); // @todo Convert to a text field in https://drupal.org/node/2149845. $fields['description'] = FieldDefinition::create('string') diff --git a/core/modules/aggregator/lib/Drupal/aggregator/FeedViewBuilder.php b/core/modules/aggregator/lib/Drupal/aggregator/FeedViewBuilder.php index bc0d82b..a6caad3 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/FeedViewBuilder.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedViewBuilder.php @@ -69,26 +69,12 @@ public function buildComponents(array &$build, array $entities, array $displays, ->getViewBuilder('aggregator_item') ->viewMultiple($items, $view_mode, $langcode); - if ($view_mode != 'summary') { + if ($view_mode == 'full') { // Also add the pager. $build[$id]['pager'] = array('#theme' => 'pager'); } } - if ($display->getComponent('link')) { - $link = $entity->getWebsiteUrl(); - if ($link) { - $build[$id]['link'] = array( - '#type' => 'link', - '#href' => $link, - '#title' => $link, - '#options' => array('absolute' => TRUE), - '#prefix' => '
' . t('URL:') . ' ', - '#suffix' => '
', - ); - } - } - if ($display->getComponent('checked')) { // Render the checked timestamp as time ago. $last_checked = $entity->getLastCheckedTime(); diff --git a/core/modules/aggregator/lib/Drupal/aggregator/ItemViewBuilder.php b/core/modules/aggregator/lib/Drupal/aggregator/ItemViewBuilder.php index c3754a8..428ee7b 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/ItemViewBuilder.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/ItemViewBuilder.php @@ -45,15 +45,6 @@ public function buildComponents(array &$build, array $entities, array $displays, ); } - if ($display->getComponent('link')) { - $build[$id]['link'] = array( - '#type' => 'link', - '#href' => $entity->getLink(), - '#title' => $entity->label(), - '#options' => array('absolute' => TRUE), - ); - } - if ($display->getComponent('timestamp')) { if ($view_mode == 'summary') { // Always render the timestamp as time ago on summary. @@ -92,14 +83,6 @@ public function buildComponents(array &$build, array $entities, array $displays, '#suffix' => '', ); } - - if ($display->getComponent('author')) { - $build[$id]['author'] = array( - '#markup' => String::checkPlain($entity->getAuthor()), - '#prefix' => '', - '#suffix' => '', - ); - } } }