diff --git a/core/modules/aggregator/aggregator.pages.inc b/core/modules/aggregator/aggregator.pages.inc index a711c18ae12ccfb22ab356b676f240c5c2197bac..e364aee0fd2f6b1df680b5f96f2ff9bffecb0737 100644 --- a/core/modules/aggregator/aggregator.pages.inc +++ b/core/modules/aggregator/aggregator.pages.inc @@ -63,21 +63,22 @@ function aggregator_load_feed_items($type, $data = NULL, $limit = 20) { function template_preprocess_aggregator_item(&$variables) { $item = $variables['aggregator_item']; - $variables['feed_url'] = check_url($item->link->value); - $variables['feed_title'] = check_plain($item->title->value); - $variables['content'] = aggregator_filter_xss($item->description->value); + $variables['feed_url'] = check_url($item->getLink()); + $variables['feed_title'] = check_plain($item->getTitle()); + $variables['content'] = aggregator_filter_xss($item->getDescription()); $variables['source_url'] = ''; $variables['source_title'] = ''; - if (isset($item->ftitle) && isset($item->fid->value)) { - $variables['source_url'] = url("aggregator/sources/$item->fid->value"); + $fid = $item->getFeedId(); + if (isset($item->ftitle) && $fid !== NULL) { + $variables['source_url'] = url('aggregator/sources/' . $fid); $variables['source_title'] = check_plain($item->ftitle); } - if (date('Ymd', $item->timestamp->value) == date('Ymd')) { - $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->timestamp->value))); + if (date('Ymd', $item->getPostedTime()) == date('Ymd')) { + $variables['source_date'] = t('%ago ago', array('%ago' => format_interval(REQUEST_TIME - $item->getPostedTime()))); } else { - $variables['source_date'] = format_date($item->timestamp->value, 'medium'); + $variables['source_date'] = format_date($item->getPostedTime(), 'medium'); } $variables['categories'] = array(); @@ -185,18 +186,18 @@ function template_preprocess_aggregator_summary_items(&$variables) { function template_preprocess_aggregator_summary_item(&$variables) { $item = $variables['aggregator_item']; - $variables['url'] = l(check_plain($item->label()), check_url(url($item->link->value, array('absolute' => TRUE))), array( + $variables['url'] = l(check_plain($item->label()), check_url(url($item->getLink(), array('absolute' => TRUE))), array( 'attributes' => array( - 'class' => array('feed-item-url',), + 'class' => array('feed-item-url'), ), )); $variables['age'] = array( '#theme' => 'datetime', '#attributes' => array( - 'datetime' => format_date($item->timestamp->value, 'html_datetime', '', 'UTC'), - 'class' => array('feed-item-age'), + 'datetime' => format_date($item->getPostedTime(), 'html_datetime', '', 'UTC'), + 'class' => array('feed-item-age',), ), - '#text' => t('%age old', array('%age' => format_interval(REQUEST_TIME - $item->timestamp->value))), + '#text' => t('%age old', array('%age' => format_interval(REQUEST_TIME - $item->getPostedTime()))), '#html' => TRUE, ); } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php index cb96e27d1c732f78722ff652abbbf624a1475ef3..961ed7f9ec316b36dfd3a6059fa8305309a4c72b 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Item.php @@ -34,90 +34,6 @@ */ class Item extends ContentEntityBase implements ItemInterface { - /** - * The feed item ID. - * - * @todo rename to id. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $iid; - - /** - * The feed ID. - * - * @todo rename to feed_id. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $fid; - - /** - * Title of the feed item. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $title; - - /** - * The feed language code. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $langcode; - - /** - * Link to the feed item. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $link; - - /** - * Author of the feed item. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $author; - - /** - * Body of the feed item. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $description; - - /** - * Posted date of the feed item, as a Unix timestamp. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $timestamp; - - /** - * Unique identifier for the feed item. - * - * @var \Drupal\Core\Field\FieldItemListInterface - */ - public $guid; - - /** - * {@inheritdoc} - */ - public function init() { - parent::init(); - - // We unset all defined properties, so magic getters apply. - unset($this->iid); - unset($this->fid); - unset($this->title); - unset($this->author); - unset($this->description); - unset($this->guid); - unset($this->link); - unset($this->timestamp); - } - /** * Implements Drupal\Core\Entity\EntityInterface::id(). */ @@ -138,8 +54,8 @@ public function label($langcode = NULL) { public function postCreate(EntityStorageControllerInterface $storage_controller) { parent::postCreate($storage_controller); - if (!isset($this->timestamp->value)) { - $this->timestamp->value = REQUEST_TIME; + if ($this->getPostedTime() === NULL) { + $this->setPostedTime(REQUEST_TIME); } } @@ -214,4 +130,101 @@ public static function baseFieldDefinitions($entity_type) { return $fields; } + /** + * @inheritdoc + */ + public function getFeedId() { + return $this->get('fid')->value; + } + + /** + * @inheritdoc + */ + public function setFeedId($fid) { + return $this->set('fid', $fid); + } + + /** + * @inheritdoc + */ + public function getTitle() { + return $this->get('title')->value; + } + + /** + * @inheritdoc + */ + public function setTitle($title) { + return $this->set('title', $title); + } + + /** + * @inheritdoc + */ + public function getLink() { + return $this->get('link')->value; + } + + /** + * @inheritdoc + */ + public function setLink($link) { + return $this->set('link', $link); + } + + /** + * @inheritdoc + */ + public function getAuthor() { + return $this->get('author')->value; + } + + /** + * @inheritdoc + */ + public function setAuthor($author) { + return $this->set('author', $author); + } + + /** + * @inheritdoc + */ + public function getDescription() { + return $this->get('description')->value; + } + + /** + * @inheritdoc + */ + public function setDescription($description) { + return $this->set('description', $description); + } + + /** + * @inheritdoc + */ + public function getPostedTime() { + return $this->get('timestamp')->value; + } + + /** + * @inheritdoc + */ + public function setPostedTime($timestamp) { + return $this->set('timestamp', $timestamp); + } + + /** + * @inheritdoc + */ + public function getGuid() { + return $this->get('guid')->value; + } + + /** + * @inheritdoc + */ + public function setGuid($guid) { + return $this->set('guid', $guid); + } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/ItemInterface.php b/core/modules/aggregator/lib/Drupal/aggregator/ItemInterface.php index 9ad17a2cdd0d05676adc348386845fc74c3f0842..83e7418fb159ac17a40a556afc7a1ef1c6359318 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/ItemInterface.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/ItemInterface.php @@ -14,4 +14,134 @@ */ interface ItemInterface extends ContentEntityInterface { + /** + * Returns the feed id of aggregator item. + * + * @return int + * The feed id. + */ + public function getFeedId(); + + /** + * Sets the feed id of aggregator item. + * + * @param int $fid + * The feed id + * + * @return \Drupal\aggregator\ItemInterface + * The called feed item entity. + */ + public function setFeedId($fid); + + /** + * Returns the title of the feed item. + * + * @return string + * The title of the feed item. + */ + public function getTitle(); + + /** + * Sets the title of the feed item. + * + * @param string $title + * The title of the feed item. + * + * @return \Drupal\aggregator\ItemInterface + * The called feed item entity. + */ + public function setTitle($title); + + /** + * Returns the link to the feed item. + * + * @return string + * The link to the feed item. + */ + public function getLink(); + + /** + * Sets the link to the feed item. + * + * @param string $link + * The link to the feed item. + * @return \Drupal\aggregator\ItemInterface + * The called feed item entity. + */ + public function setLink($link); + + /** + * Returns the author of the feed item. + * + * @return string + * The author of the feed item. + */ + public function getAuthor(); + + /** + * Sets the author of the feed item. + * + * @param string $author + * The author name of the feed item. + * @return \Drupal\aggregator\ItemInterface + * The called feed item entity. + */ + public function setAuthor($author); + + /** + * Returns the body of the feed item. + * + * @return string + * The body of the feed item. + */ + public function getDescription(); + + /** + * Sets the body of the feed item. + * + * @param string $description + * The body of the feed item. + * + * @return \Drupal\aggregator\ItemInterface + * The called feed item entity. + */ + public function setDescription($description); + + /** + * Returns the posted date of the feed item, as a Unix timestamp. + * + * @return int + * The posted date of the feed item, as a Unix timestamp. + */ + public function getPostedTime(); + + /** + * Sets the posted date of the feed item, as a Unix timestamp. + * + * @param int $timestamp + * The posted date of the feed item, as a Unix timestamp. + * + * @return \Drupal\aggregator\ItemInterface + * The called feed item entity. + */ + public function setPostedTime($timestamp); + + /** + * Returns the unique identifier for the feed item. + * + * @return string + * The unique identifier for the feed item. + */ + public function getGuid(); + + /** + * Sets the unique identifier for the feed item. + * + * @param string $guid + * The unique identifier for the feed item. + * + * @return \Drupal\aggregator\ItemInterface + * The called feed item entity. + */ + public function setGuid($guid); } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php b/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php index 7e05027186b4016f4d9f681fb462277758360c5f..b4aeadd369e5dce2fdbeb66056f4c67578b53bc8 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/ItemStorageController.php @@ -50,7 +50,7 @@ public function deleteCategories(array $entities) { * {@inheritdoc} */ public function saveCategories(Item $item) { - $result = $this->database->query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(':fid' => $item->fid->value)); + $result = $this->database->query('SELECT cid FROM {aggregator_category_feed} WHERE fid = :fid', array(':fid' => $item->getFeedId())); foreach ($result as $category) { $this->database->merge('aggregator_category_item') ->key(array( diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php index ec7d19333ca78613056cc4b5a50d03e19591aed6..f2b1cbcf598aaffa7ecf8f6e33cd7928d698b4f0 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/aggregator/processor/DefaultProcessor.php @@ -171,17 +171,17 @@ public function process(Feed $feed) { $entry = entity_create('aggregator_item', array('langcode' => $feed->language()->id)); } if ($item['timestamp']) { - $entry->timestamp->value = $item['timestamp']; + $entry->setPostedTime($item['timestamp']); } // Make sure the item title and author fit in the 255 varchar column. - $entry->title->value = truncate_utf8($item['title'], 255, TRUE, TRUE); - $entry->author->value = truncate_utf8($item['author'], 255, TRUE, TRUE); + $entry->setTitle(truncate_utf8($item['title'], 255, TRUE, TRUE)); + $entry->setAuthor(truncate_utf8($item['author'], 255, TRUE, TRUE)); - $entry->fid->value = $feed->id(); - $entry->link->value = $item['link']; - $entry->description->value = $item['description']; - $entry->guid->value = $item['guid']; + $entry->setFeedId($feed->id()); + $entry->setLink($item['link']); + $entry->setDescription($item['description']); + $entry->setGuid($item['guid']); $entry->save(); } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedProcessorPluginTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedProcessorPluginTest.php index a577b728887491340fbde18672e9df85cf583170..c880b15376fa1f65e6ede9c8731cc1ad9dd72f5e 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedProcessorPluginTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/FeedProcessorPluginTest.php @@ -41,7 +41,7 @@ public function testProcess() { $this->updateFeedItems($feed); foreach ($feed->items as $iid) { $item = entity_load('aggregator_item', $iid); - $this->assertTrue(strpos($item->title->value, 'testProcessor') === 0); + $this->assertTrue(strpos($item->getTitle(), 'testProcessor') === 0); } } diff --git a/core/modules/aggregator/lib/Drupal/aggregator/Tests/Views/IntegrationTest.php b/core/modules/aggregator/lib/Drupal/aggregator/Tests/Views/IntegrationTest.php index dcb41857ba0f9ce8ab7e52ac72d2f520dd2ee098..ed6c7457595d8055a304c4b3b3439cba29e39323 100644 --- a/core/modules/aggregator/lib/Drupal/aggregator/Tests/Views/IntegrationTest.php +++ b/core/modules/aggregator/lib/Drupal/aggregator/Tests/Views/IntegrationTest.php @@ -101,13 +101,13 @@ public function testAggregatorItemView() { // Ensure that the rendering of the linked title works as expected. foreach ($view->result as $row) { $iid = $view->field['iid']->getValue($row); - $expected_link = l($items[$iid]->title->value, $items[$iid]->link->value, array('absolute' => TRUE)); + $expected_link = l($items[$iid]->getTitle(), $items[$iid]->getLink(), array('absolute' => TRUE)); $this->assertEqual($view->field['title']->advancedRender($row), $expected_link, 'Ensure the right link is generated'); - $expected_author = aggregator_filter_xss($items[$iid]->author->value); + $expected_author = aggregator_filter_xss($items[$iid]->getAuthor()); $this->assertEqual($view->field['author']->advancedRender($row), $expected_author, 'Ensure the author got filtered'); - $expected_description = aggregator_filter_xss($items[$iid]->description->value); + $expected_description = aggregator_filter_xss($items[$iid]->getDescription()); $this->assertEqual($view->field['description']->advancedRender($row), $expected_description, 'Ensure the author got filtered'); } }