Part of meta-issue #2016679: Expand Entity Type interfaces to provide methods, protect the properties.

See the detailed explanations there and look at the issues that already have patches or were commited.

Add get*, set* and additional methods as it makes sense to replace the public properties (e.g. isSomething() and something())

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

marvin_B8’s picture

Assigned: Unassigned » marvin_B8
marvin_B8’s picture

Status: Active » Needs review
FileSize
14.92 KB

i add the get and set methods to the feedinteface.

Status: Needs review » Needs work

The last submitted patch, Expand-FeedInterface-with-methods-2028037-3.patch, failed testing.

marvin_B8’s picture

Status: Needs work » Needs review
FileSize
32.48 KB

second try

Status: Needs review » Needs work

The last submitted patch, 2-Expand-FeedInterface-with-methods-2028037-3.patch, failed testing.

ParisLiakos’s picture

Hi, thanks for working on this

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -15,6 +15,278 @@
+  public function setId($id);

i dont think it makes sense to have this method. ID's are usually readonly:)

Berdir’s picture

marvin_B8’s picture

marvin_B8’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 3-Expand-FeedInterface-with-methods-2028037-3.patch, failed testing.

Berdir’s picture

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   * @return \Drupal\comment\CommentInterface|null
+   *   The class instance that this method is called on.
+   */
+  public function setTitle($title);
...
+   * @return \Drupal\aggregator\Plugin\Core\Entity\FeedInterface|null
+   *   The class instance that this method is called on.
+   */
+  public function setLangcode($langcode);

All setters should return \Drupal\aggregator\FeedInterface.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Core/Entity/Feed.phpundefined
@@ -41,133 +41,17 @@
    * Overrides Drupal\Core\Entity\EntityNG::init().
    */
   public function init() {
     parent::init();

You can remove this method completely.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/Plugin/Core/Entity/Feed.phpundefined
@@ -264,4 +148,194 @@ protected function clearBlockCacheDefinitions() {
   }
 
+
+

Too any empty lines here.

marvin_B8’s picture

Status: Needs work » Needs review
FileSize
5.11 KB
31.27 KB

Status: Needs review » Needs work

The last submitted patch, Expand-FeedInterface-with-methods-2028037-12.patch, failed testing.

marvin_B8’s picture

Status: Needs work » Needs review
FileSize
13.37 KB
33.81 KB
YesCT’s picture

was that interdiff backward?
- 'href' => "admin/config/services/aggregator/edit/feed/{$feed->getId()}",
+ 'href' => "admin/config/services/aggregator/edit/feed/{$feed->fid}",
says you are using ->fid now, and not using getId().
is that right?

marvin_B8’s picture

we don't use getId() anymore and yes i use ->fid because it is a return from a database query. i thought every $feed is a object but some of them a db querys and now i need to make some steps back with that patch. was a mistake from me.

tim.plunkett’s picture

+++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.phpundefined
@@ -151,27 +151,27 @@
     foreach ($result as $feed) {

What you should do instead is inject the feed storage controller, and do $feeds = $this->feedStorage->loadMultiple($result);
And then loop over them using the proper methods (id() not getId()).

marvin_B8’s picture

i need some help because i'm not sure how i can change the feed db querys in

-AggregatorFeedBlock.php
-ImportOpmlTest.php
-Aggregator.pages.php

or i don't need it ?

marvin_B8’s picture

doppel post sry

ParisLiakos’s picture

i can take a look sometime this week, but till then you could check the patch in #1957312: Use the entity storage controller in aggregator module it might help

Berdir’s picture

Status: Needs review » Needs work
+++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.phpundefined
@@ -145,33 +145,32 @@ public function feedRefresh(FeedInterface $aggregator_feed, Request $request) {
-    $result = $this->database->query('SELECT f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block, COUNT(i.iid) AS items FROM {aggregator_feed} f LEFT JOIN {aggregator_item} i ON f.fid = i.fid GROUP BY f.fid, f.title, f.url, f.refresh, f.checked, f.link, f.description, f.hash, f.etag, f.modified, f.image, f.block ORDER BY f.title');
-
+    $feeds = $this->entityManager->getStorageController('aggregator_feed')->loadMultiple();

Yes, not sure about changing this, missing some parts like ->items (which is a count()). I'd just leave this for now.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedFormController.phpundefined
@@ -35,27 +35,27 @@ public function form(array $form, array &$form_state) {
-      '#default_value' => $feed->language()->id,
+      '#default_value' => $feed->getLangcode(),

This is not necessary.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+  /**
+   * Returns the language code of the feed..
+   *
+   * @return string
+   *   The languagecode of the feed.
+   */
+  public function getLangcode();

Yeah, we didn't this for other interfaces. language() unfortunately returns the language entity but that's fine.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+  public function setLangcode($langcode);

This one is useful, so keep that.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   * Sets the url to the feed.
+   *
+   *
+   * @param string $url
+   *   A string containing the url of the feed.
...
+   * Sets the refresh rate of the feed.
+   *
+   *
+   * @param int $refresh

Should only have a single empty line above @param.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   * @return int
+   *   The refresh rate of the feed.
...
+   *   The refresh rate of the feed.

Let's document that it's in seconds.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+  public function getRefresh();

getRefreshRate()? Method names should be a good compromise between self-explaining and not too long :)

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   *  Returns the last time where the feed was checked for new items, as Unix timestamp.

Two spaces in front of the text. let's reove the as unix timestamp from here, to keep it under 80 characters. We still have that in the @return.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   */
+  public function getChecked();

Let's name this (get/set)LastCheckedTime(), that's also used as variable for the feed source template.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   * Sets the Time when this feed was queued for refresh, 0 if not queued.
+   *
+   *
+   * @param int $checked

Again two empty lines.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   */
+  public function getQueued();

Let's also try to find a better method name for this... getQuuedTime()?

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   * @param int $queued
+   *    A int with the time of the last refresh.

No need to repeat in, just timestamp of the last refresh should be enough.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   * Returns the parent website of the feed.
+   *
+   * @return int
+   *   The node ID of the node where the comment is attached.
+   */
+  public function getLink();

What about getWebsiteLink() then?

the @return is copied from somewhere.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   * Returns the Calculated hash of the feed data, used for validating cache.
+   *
+   * @return string
+   *   The Calculated hash of the feed data.
+   */
+  public function getHash();

Not sure what to name this one.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+   * Return when the feed was last modified, as a Unix timestamp.
+   *
+   * @return int
+   *   The timestamp of the last modified.

This could use a little bit more documentation, the @return also isn't really a sentence.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+  public function getModified();

getLastModified() I'd say.

+++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.phpundefined
@@ -14,6 +14,255 @@
+  /**
+   * Return the Number of items to display in the feed’s block.
+   *
+   * @return int
+   *   The Number of items to display in the feed’s block.
+   */
+  public function getBlock();

Tricky one. getBlockItemCount()? Sad that this is still in here, wanted to move it to instance configuration· Too late now I guess.

jsbalsera’s picture

Assigned: marvin_B8 » jsbalsera
jsbalsera’s picture

Re-rolled and changes made, except changing getLink with getWebsiteLink, because it causes the test to fail, and generating the next Uncaught Exception:

Uncaught PHP Exception Zend\\Feed\\Reader\\Exception\\BadMethodCallException: "Method: getWebsiteLinkdoes not exist and could not be located on a registered Extension" at /home/jsanchez/projects/d8/core/vendor/zendframework/zend-feed/Zend/Feed/Reader/Feed/AbstractFeed.php line 259

jsbalsera’s picture

Assigned: jsbalsera » Unassigned
Status: Needs work » Needs review
Berdir’s picture

Status: Needs review » Needs work

Thanks, I think we're getting close here :)

  1. +++ b/core/modules/aggregator/aggregator.module
    @@ -358,21 +358,21 @@ function aggregator_refresh(Feed $feed) {
    -        if (empty($feed->link->value)) {
    -          $feed->link->value = $feed->url->value;
    +        if (is_null($feed->getLink())) {
    +          $feed->setLink($feed->getUrl());
             }
    

    I don't think there is a need for an explicit is_null() check, just if (!$feed->getLink()) should be fine. The empty was when those objects weren't typed and might or might not have those properties.

  2. +++ b/core/modules/aggregator/aggregator.pages.inc
    @@ -232,27 +232,27 @@ function template_preprocess_aggregator_feed_source(&$variables) {
    -  if (!empty($feed->image->value) && $feed->label() && !empty($feed->link->value)) {
    +  if (!is_null($feed->getImage()) && $feed->label() && !is_null($feed->getLink())) {
    

    Same here.

  3. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Controller/AggregatorController.php
    @@ -185,19 +186,19 @@ public function adminOverview() {
    -        'title' => $this->t('Edit'),
    +        'title' => t('Edit'),
             'href' => "admin/config/services/aggregator/edit/feed/$feed->fid",
           );
           $links['delete'] = array(
    -        'title' => $this->t('Delete'),
    +        'title' => t('Delete'),
             'href' => "admin/config/services/aggregator/delete/feed/$feed->fid",
           );
           $links['remove'] = array(
    -        'title' => $this->t('Remove items'),
    +        'title' => t('Remove items'),
             'href' => "admin/config/services/aggregator/remove/$feed->fid",
           );
           $links['update'] = array(
    -        'title' => $this->t('Update items'),
    +        'title' => t('Update items'),
    

    This seems like an accidental revert, those changes should be removed from the patch.

  4. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php
    @@ -41,121 +41,6 @@
    -   * @var \Drupal\Core\Entity\Field\FieldInterface
    

    The class has been renamed, so this will conflict here, just re-remove it.

  5. +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php
    @@ -14,6 +14,239 @@
    +   * Sets the Langcode of the feed.
    

    lowercase, also not sure if we should use "language code".

  6. +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php
    @@ -14,6 +14,239 @@
    +   * Returns the url to the feed.
    

    Should be URL I think (only in the docblock, the method name has to be camel case.

  7. +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php
    @@ -14,6 +14,239 @@
    +   * Returns the last time where the feed was checked for new items, as Unix timestamp.
    

    Over 80 characters. Maybe remove the as unix timestamp part, as we have that in the @return anyway.

  8. +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php
    @@ -14,6 +14,239 @@
    +   * Sets the Time when this feed was queued for refresh, 0 if not queued.
    

    Time here and in the other docbocks below should be lowercase.

johnennew’s picture

Assigned: Unassigned » johnennew
Status: Needs work » Active

Going to pick this one up now.

johnennew’s picture

Status: Active » Needs review
FileSize
30.87 KB

I took getLangcode() and setLangcode() out of the FeedInterface as they don't appear to be used anywhere. Can put these back if they are needed.

Added corrections from #25 above.

Renamed *etLink() to *etWebsiteLink() as suggested - not sure what the error in #23 is, I didn't get it.

Couldn't make an interdiff

johnennew’s picture

Some whitespace in the last patch has been removed.

Berdir’s picture

Status: Needs review » Needs work
Issue tags: +Novice, +Entity Field API

The last submitted patch, drupal8.aggregator-module.2028037-28.patch, failed testing.

jsbalsera’s picture

Status: Needs work » Needs review
FileSize
7.18 KB
30.75 KB

Rerolled patch

ParisLiakos’s picture

  1. +++ b/core/modules/aggregator/lib/Drupal/aggregator/Entity/Feed.php
    @@ -320,4 +207,177 @@ public static function baseFieldDefinitions($entity_type) {
    +  public function getBlockItemCount() {
    +    return $this->get('block')->value;
    +  }
    ...
    +  public function setBlockItemCount($block) {
    +    $this->set('block', $block);
    +    return $this;
    
    +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php
    @@ -15,7 +15,230 @@
    +   */
    +  public function getBlockItemCount();
    ...
    +   */
    +  public function setBlockItemCount($block);
    

    we should remove those. feeds no longer have a block property

  2. +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php
    @@ -15,7 +15,230 @@
    +   * Returns the parent website of the feed.
    ...
    +  public function getWebsiteLink();
    ...
    +   * Sets the parent website of the feed.
    ...
    +  public function setWebsiteLink($link);
    

    I would say name this (get|set)WebsiteUrl().
    "link" makes me think o <a> tags, while this here, will only give you the href ;)

  3. +++ b/core/modules/aggregator/lib/Drupal/aggregator/FeedInterface.php
    @@ -15,7 +15,230 @@
    +  public function getLastModified();
    ...
    +  public function setModified($modified);
    

    we should either prefix both with Last or none;)

ParisLiakos’s picture

Issue summary: View changes
Status: Needs review » Needs work
jsbalsera’s picture

Assigned: johnennew » Unassigned
Status: Needs work » Needs review
FileSize
29.05 KB
6.96 KB
Berdir’s picture

Status: Needs review » Reviewed & tested by the community

I think this is good to go.

Xano’s picture

Xano’s picture

LinL’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
29.08 KB

Rerolled, patch no longer applied.

ParisLiakos’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
LinL’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
28.22 KB

Rerolled without core/modules/aggregator/lib/Drupal/aggregator/Tests/CategorizeFeedTest.php deleted in #2127725: Remove category handling from aggregator

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

thank you!

LinL’s picture

And another reroll.

LinL’s picture

Status: Reviewed & tested by the community » Needs review
ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community
xjm’s picture

Berdir’s picture

xjm’s picture

Issue tags: +RTBC 4+ weeks
webchick’s picture

Status: Reviewed & tested by the community » Needs work

I just committed #2149841: The 'aggregator_feed' entity type doesn't have a UUID field which probably means this one needs a re-roll.

This initiative was totally off my radar and I do not understand why we are doing this (the linked issue summary just says "->getSomething() would be nicer" which strikes me as a spurious reason to spear-head such a massive API change as this post-API freeze), but I guess Alex Pott has been committing these for the most part, so I'll probably leave it to him.

YesCT’s picture

The patch still applies.

I'll send it for a retest.

I took a look at #2149841: The 'aggregator_feed' entity type doesn't have a UUID field
and given that @Berdir says in #2016679-12: Expand Entity Type interfaces to provide methods, protect the properties not to add uuid() or setUuid()

Do not add getter methods for things that already exist on EntityInterface, do not duplicate:
** id() for the primary id of the entity (no getId())
...
** uuid()
...
Another example: setUUID(), this is set automatically initially and must not be changed afterwards.

I'm not sure what needs work here.

These might be of interest:
ag "function uuid\\(" core
ag "function getUuid\\(" core

YesCT’s picture

Status: Needs work » Needs review
Berdir’s picture

Agreed that there is probably no overlap, there is already a uuid() method provided by Entityinterface.

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

back to rtbc then

webchick’s picture

Title: Expand FeedInterface with methods » Change notice: Expand FeedInterface with methods
Priority: Normal » Major
Status: Reviewed & tested by the community » Active
Issue tags: +Needs change record

Ok, since we made the decision in the other issue to do this method-ification to all the things, let's do this.

Committed and pushed to 8.x.

We'll need to scour existing change notices to make sure they reflect the methods introduced here.

xjm’s picture

Title: Change notice: Expand FeedInterface with methods » Expand FeedInterface with methods
Priority: Major » Normal
Status: Active » Fixed
Issue tags: -RTBC over 4 weeks

I believe this is covered by https://drupal.org/node/1806650, so added that to this issue. I only found one other reference to FeedInterface in the change records and it was fine.

xjm’s picture

Issue tags: -Novice, -Needs change record

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.