diff --git a/core/modules/aggregator/src/AggregatorFeedViewsData.php b/core/modules/aggregator/src/AggregatorFeedViewsData.php index 22ce4c2..5406f3f 100644 --- a/core/modules/aggregator/src/AggregatorFeedViewsData.php +++ b/core/modules/aggregator/src/AggregatorFeedViewsData.php @@ -35,7 +35,6 @@ public function getViewsData() { $data['aggregator_feed']['fid']['filter']['id'] = 'numeric'; $data['aggregator_feed']['title']['help'] = $this->t('The title of the aggregator feed.'); - $data['aggregator_feed']['title']['field']['id'] = 'field'; $data['aggregator_feed']['argument']['id'] = 'string'; $data['aggregator_feed']['url']['help'] = $this->t('The fully-qualified URL of the feed.'); diff --git a/core/modules/aggregator/src/AggregatorItemViewsData.php b/core/modules/aggregator/src/AggregatorItemViewsData.php index 0f1a940..5793f07 100644 --- a/core/modules/aggregator/src/AggregatorItemViewsData.php +++ b/core/modules/aggregator/src/AggregatorItemViewsData.php @@ -28,7 +28,6 @@ public function getViewsData() { $data['aggregator_item']['iid']['argument']['numeric'] = TRUE; $data['aggregator_item']['title']['help'] = $this->t('The title of the aggregator item.'); - $data['aggregator_item']['title']['field']['id'] = 'field'; $data['aggregator_item']['title']['field']['extra'] = 'link'; $data['aggregator_item']['link']['help'] = $this->t('The link to the original source URL of the item.'); diff --git a/core/modules/aggregator/src/Plugin/Field/FieldFormatter/AggregatorTitleFormatter.php b/core/modules/aggregator/src/Plugin/Field/FieldFormatter/AggregatorTitleFormatter.php index b6ed568..bc03b87 100644 --- a/core/modules/aggregator/src/Plugin/Field/FieldFormatter/AggregatorTitleFormatter.php +++ b/core/modules/aggregator/src/Plugin/Field/FieldFormatter/AggregatorTitleFormatter.php @@ -57,7 +57,12 @@ public function settingsForm(array $form, FormStateInterface $form_state) { public function viewElements(FieldItemListInterface $items) { $elements = []; - $url = Url::fromUri($items->getEntity()->getLink()); + if ($items->getEntity()->getEntityTypeId() == 'aggregator_feed') { + $url = Url::fromUri($items->getEntity()->getUrl()); + } + else { + $url = Url::fromUri($items->getEntity()->getLink()); + } foreach ($items as $delta => $item) { if ($this->getSetting('display_as_link')) { @@ -79,7 +84,7 @@ public function viewElements(FieldItemListInterface $items) { * {@inheritdoc} */ public static function isApplicable(FieldDefinitionInterface $field_definition) { - return $field_definition->getTargetEntityTypeId() === 'aggregator_item' && $field_definition->getName() === 'title'; + return ($field_definition->getTargetEntityTypeId() === 'aggregator_item' || $field_definition->getTargetEntityTypeId() === 'aggregator_feed' && $field_definition->getName() === 'title'); } } diff --git a/core/modules/aggregator/src/Tests/AggregatorTitleTest.php b/core/modules/aggregator/src/Tests/AggregatorTitleTest.php new file mode 100644 index 0000000..e38ca1d --- /dev/null +++ b/core/modules/aggregator/src/Tests/AggregatorTitleTest.php @@ -0,0 +1,89 @@ +installConfig(['field']); + $this->installEntitySchema('aggregator_feed'); + $this->installEntitySchema('aggregator_item'); + + $this->fieldName = 'title'; + } + + /* + * Tests the formatter output. + */ + public function testStringFormatter() { + $aggregator_feed = Feed::create([ + 'title' => 'testing title', + 'url' => 'http://www.example.com', + ]); + $aggregator_feed->save(); + + $aggregator_item = Item::create([ + 'title' => 'test title', + 'fid' => $aggregator_feed->id(), + 'link' => 'http://www.example.com', + ]); + $aggregator_item->save(); + + $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => TRUE]]); + $result = $this->render($build); + + $this->assertTrue(strpos($result, 'testing title')); + $this->assertTrue(strpos($result, 'href="' . $aggregator_feed->getUrl()) . '"'); + + $build = $aggregator_feed->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]); + $result = $this->render($build); + $this->assertTrue(strpos($result, 'testing title') === 0); + $this->assertTrue(strpos($result, $aggregator_feed->getUrl()) === FALSE); + + $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' =>TRUE]]); + $result = $this->render($build); + + $this->assertTrue(strpos($result, 'test title')); + $this->assertTrue(strpos($result, 'href="' . $aggregator_item->getLink()) . '"'); + + $build = $aggregator_item->{$this->fieldName}->view(['type' => 'aggregator_title', 'settings' => ['display_as_link' => FALSE]]); + $result = $this->render($build); + $this->assertTrue(strpos($result, 'test title') === 0); + $this->assertTrue(strpos($result, $aggregator_item->getLink()) === FALSE); + } + +}