diff --git a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php new file mode 100644 index 0000000..571d616 --- /dev/null +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/TimestampAgoFormatter.php @@ -0,0 +1,95 @@ +dateFormatter = $date_formatter; + } + + /** + * {@inheritdoc} + */ + public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) { + // @see \Drupal\Core\Field\FormatterPluginManager::createInstance(). + return new static( + $plugin_id, + $plugin_definition, + $configuration['field_definition'], + $configuration['settings'], + $configuration['label'], + $configuration['view_mode'], + $configuration['third_party_settings'], + $container->get('date.formatter') + ); + } + + /** + * {@inheritdoc} + */ + public function viewElements(FieldItemListInterface $items) { + $elements = array(); + + foreach ($items as $delta => $item) { + if ($item->value) { + $updated = $this->t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $item->value))); + } + else { + $updated = t('never'); + } + + $elements[$delta] = array('#markup' => $updated); + } + + return $elements; + } + +} 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 a6522e9..df12a53 100644 --- a/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php +++ b/core/lib/Drupal/Core/Field/Plugin/Field/FieldFormatter/UriLinkFormatter.php @@ -35,8 +35,6 @@ public function viewElements(FieldItemListInterface $items) { '#type' => 'link', '#href' => $item->value, '#title' => $item->value, - // @todo Make this configurable? - '#options' => array('absolute' => TRUE), ); } diff --git a/core/modules/aggregator/aggregator.module b/core/modules/aggregator/aggregator.module index 024a36b..7cf2e73 100644 --- a/core/modules/aggregator/aggregator.module +++ b/core/modules/aggregator/aggregator.module @@ -105,13 +105,6 @@ function aggregator_entity_extra_field_info() { 'description' => t('Items associated with this feed'), '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' => 1, - ), 'image' => array( 'label' => t('Image'), 'description' => t('The feed image'), @@ -133,13 +126,6 @@ function aggregator_entity_extra_field_info() { 'description' => t('The aggregator feed entity associated with this 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'), diff --git a/core/modules/aggregator/aggregator.theme.inc b/core/modules/aggregator/aggregator.theme.inc index 53ab9fd..f20dbf5 100644 --- a/core/modules/aggregator/aggregator.theme.inc +++ b/core/modules/aggregator/aggregator.theme.inc @@ -27,7 +27,6 @@ function template_preprocess_aggregator_item(&$variables) { $variables['url'] = check_url($item->getLink()); $variables['title'] = String::checkPlain($item->label()); - $variables['attributes']['class'][] = 'feed-item'; } /** @@ -102,8 +101,6 @@ function template_preprocess_aggregator_feed(&$variables) { ), ); } - - $variables['attributes']['class'][] = 'feed-source'; } /** diff --git a/core/modules/aggregator/config/install/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 similarity index 84% rename from core/modules/aggregator/config/install/entity.view_display.aggregator_feed.aggregator_feed.summary.yml rename to core/modules/aggregator/config/install/core.entity_view_display..aggregator_feed.aggregator_feed.summary.yml index 3097653..f9f14b8 100644 --- a/core/modules/aggregator/config/install/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 @@ -13,6 +13,6 @@ hidden: status: true dependencies: entity: - - entity.view_mode.aggregator_feed.summary + - core.entity_view_mode.aggregator_feed.summary module: - aggregator diff --git a/core/modules/aggregator/config/install/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 similarity index 84% rename from core/modules/aggregator/config/install/entity.view_display.aggregator_item.aggregator_item.summary.yml rename to core/modules/aggregator/config/install/core.entity_view_display..aggregator_item.aggregator_item.summary.yml index dcbd77c..c29ffeb 100644 --- a/core/modules/aggregator/config/install/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 @@ -13,6 +13,6 @@ hidden: status: true dependencies: entity: - - entity.view_mode.aggregator_item.summary + - core.entity_view_mode.aggregator_item.summary module: - aggregator diff --git a/core/modules/aggregator/config/install/entity.view_mode.aggregator_feed.summary.yml b/core/modules/aggregator/config/install/core.entity_view_mode.aggregator_feed.summary.yml similarity index 100% rename from core/modules/aggregator/config/install/entity.view_mode.aggregator_feed.summary.yml rename to core/modules/aggregator/config/install/core.entity_view_mode.aggregator_feed.summary.yml diff --git a/core/modules/aggregator/src/Entity/Feed.php b/core/modules/aggregator/src/Entity/Feed.php index 6fe48e3..5a33b71 100644 --- a/core/modules/aggregator/src/Entity/Feed.php +++ b/core/modules/aggregator/src/Entity/Feed.php @@ -36,8 +36,8 @@ * "canonical" = "entity.aggregator_feed.canonical", * "edit-form" = "entity.aggregator_feed.edit_form", * "delete-form" = "entity.aggregator_feed.delete_form", - * "admin-form" = "aggregator.admin_overview", * }, + * field_ui_base_route = "aggregator.admin_overview", * base_table = "aggregator_feed", * fieldable = TRUE, * render_cache = FALSE, @@ -185,7 +185,13 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['checked'] = BaseFieldDefinition::create('timestamp') ->setLabel(t('Checked')) ->setDescription(t('Last time feed was checked for new items, as Unix timestamp.')) - ->setDefaultValue(0); + ->setDefaultValue(0) + ->setDisplayOptions('view', array( + 'label' => 'inline', + 'type' => 'timestamp_ago', + 'weight' => 1, + )) + ->setDisplayConfigurable('view', TRUE); $fields['queued'] = BaseFieldDefinition::create('timestamp') ->setLabel(t('Queued')) diff --git a/core/modules/aggregator/src/Entity/Item.php b/core/modules/aggregator/src/Entity/Item.php index 43f6de4..1d7fc5c 100644 --- a/core/modules/aggregator/src/Entity/Item.php +++ b/core/modules/aggregator/src/Entity/Item.php @@ -92,8 +92,14 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { ->setDescription(t('The body of the feed item.')); $fields['timestamp'] = BaseFieldDefinition::create('created') - ->setLabel(t('Posted timestamp')) - ->setDescription(t('Posted date of the feed item, as a Unix timestamp.')); + ->setLabel(t('Posted on')) + ->setDescription(t('Posted date of the feed item, as a Unix timestamp.')) + ->setDisplayOptions('view', array( + 'label' => 'hidden', + 'type' => 'timestamp_ago', + 'weight' => 1, + )) + ->setDisplayConfigurable('view', TRUE); // @todo Convert to a real UUID field in https://drupal.org/node/2149851. $fields['guid'] = BaseFieldDefinition::create('string_long') diff --git a/core/modules/aggregator/src/FeedViewBuilder.php b/core/modules/aggregator/src/FeedViewBuilder.php index 73e6a96..84fa2ad 100644 --- a/core/modules/aggregator/src/FeedViewBuilder.php +++ b/core/modules/aggregator/src/FeedViewBuilder.php @@ -7,7 +7,6 @@ namespace Drupal\aggregator; -use Drupal\Core\Datetime\DateFormatter; use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\EntityTypeInterface; @@ -30,13 +29,12 @@ class FeedViewBuilder extends EntityViewBuilder { * The entity manager service. * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager * The language manager. - * @param \Drupal\Core\Datetime\Date $date_formatter - * The date formatter service. + * @param \Drupal\Core\Config\Config $config + * The 'aggregator.settings' config. */ - public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, Config $config, DateFormatter $date_formatter) { + public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, Config $config) { parent::__construct($entity_type, $entity_manager, $language_manager); $this->config = $config; - $this->dateFormatter = $date_formatter; } /** @@ -47,8 +45,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI $entity_type, $container->get('entity.manager'), $container->get('language_manager'), - $container->get('config.factory')->get('aggregator.settings'), - $container->get('date.formatter') + $container->get('config.factory')->get('aggregator.settings') ); } @@ -80,22 +77,6 @@ public function buildComponents(array &$build, array $entities, array $displays, } } - if ($display->getComponent('checked')) { - // Render the checked timestamp as time ago. - $last_checked = $entity->getLastCheckedTime(); - if ($last_checked) { - $updated = t('@time ago', array('@time' => $this->dateFormatter->formatInterval(REQUEST_TIME - $last_checked))); - } - else { - $updated = t('never'); - } - $build[$id]['checked'] = array( - '#markup' => t('Updated: @updated', array('@updated' => $updated)), - '#prefix' => '
', - '#suffix' => '
', - ); - } - if ($display->getComponent('description')) { $build[$id]['description'] = array( '#markup' => aggregator_filter_xss($entity->getDescription()), diff --git a/core/modules/aggregator/src/ItemViewBuilder.php b/core/modules/aggregator/src/ItemViewBuilder.php index 565e52d..0a0b5ce 100644 --- a/core/modules/aggregator/src/ItemViewBuilder.php +++ b/core/modules/aggregator/src/ItemViewBuilder.php @@ -8,13 +8,7 @@ namespace Drupal\aggregator; use Drupal\Component\Utility\String; -use Drupal\Core\Datetime\DateFormatter; -use Drupal\Core\Entity\EntityInterface; -use Drupal\Core\Entity\EntityManagerInterface; -use Drupal\Core\Entity\EntityTypeInterface; use Drupal\Core\Entity\EntityViewBuilder; -use Drupal\Core\Language\LanguageManagerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Render controller for aggregator feed items. @@ -22,35 +16,6 @@ class ItemViewBuilder extends EntityViewBuilder { /** - * Constructs a new ItemViewBuilder. - * - * @param \Drupal\Core\Entity\EntityTypeInterface $entity_type - * The entity type definition. - * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager - * The entity manager service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - * @param \Drupal\Core\Datetime\Date $date_formatter - * The date formatter service. - */ - public function __construct(EntityTypeInterface $entity_type, EntityManagerInterface $entity_manager, LanguageManagerInterface $language_manager, DateFormatter $date_formatter) { - parent::__construct($entity_type, $entity_manager, $language_manager); - $this->dateFormatter = $date_formatter; - } - - /** - * {@inheritdoc} - */ - public static function createInstance(ContainerInterface $container, EntityTypeInterface $entity_type) { - return new static( - $entity_type, - $container->get('entity.manager'), - $container->get('language_manager'), - $container->get('date.formatter') - ); - } - - /** * {@inheritdoc} */ public function buildComponents(array &$build, array $entities, array $displays, $view_mode, $langcode = NULL) { @@ -79,37 +44,6 @@ public function buildComponents(array &$build, array $entities, array $displays, ); } - if ($display->getComponent('timestamp')) { - if ($view_mode == 'summary') { - // Always render the timestamp as time ago on summary. - $build[$id]['timestamp'] = array( - '#theme' => 'time', - '#attributes' => array( - 'datetime' => $this->dateFormatter->format($entity->getPostedTime(), 'html_datetime', '', 'UTC'), - 'class' => array('feed-item-age'), - ), - '#text' => t('%age old', array('%age' => $this->dateFormatter->formatInterval(REQUEST_TIME - $entity->getPostedTime()))), - '#html' => TRUE, - ); - } - else { - // On full mode only display as time ago only if the post is in the - // same month. - $posted_time = $entity->getPostedTime(); - if (date('Ymd', $posted_time) == date('Ymd')) { - $date = t('%ago ago', array('%ago' => $this->dateFormatter->formatInterval(REQUEST_TIME - $posted_time))); - } - else { - $date = $this->dateFormatter->format($posted_time, 'medium'); - } - $build[$id]['timestamp'] = array( - '#markup' => $date, - '#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 4f8d400..8cd7c11 100644 --- a/core/modules/aggregator/templates/aggregator-feed.html.twig +++ b/core/modules/aggregator/templates/aggregator-feed.html.twig @@ -19,7 +19,7 @@ * @ingroup themeable */ #} - + {{ title_prefix }} {% if not full %} diff --git a/core/modules/aggregator/templates/aggregator-item.html.twig b/core/modules/aggregator/templates/aggregator-item.html.twig index 5ad6b4d..8f31937 100644 --- a/core/modules/aggregator/templates/aggregator-item.html.twig +++ b/core/modules/aggregator/templates/aggregator-item.html.twig @@ -16,7 +16,7 @@ * @ingroup themeable */ #} - + {{ title_prefix }}

{{ title }}