Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

News feeds as page controller #4682

Merged
merged 35 commits into from
Aug 10, 2022
Merged

Conversation

bezin
Copy link
Contributor

@bezin bezin commented May 17, 2022

This implements news feeds as page controller and superseds #4459 eventually. Also I decided to split these into a news-bundle PR and an Event-bundle PR, because I find it easier to handle.

Still a couple things to do:

  • Add feeds to layout (DCA is updated, but the correct routes need to be added to the page. Requires ResponseContext)
  • Check and improve extensibility (e.g. provide better ways to extend RSS feeds core-bundle#1243, overwrite image size of every image element)
  • Get rid of some legacy code. if possible
  • Update permisssion handling (see below)
  • Page Icon: fix offset in page tree and add required variants (not visible, not editable, ...)
  • Update News Feed Insert tag
  • Remove obsolete code
  • Write migration (migrate feeds to pages; update permissions, if necessary)
  • Add tests

There are also some permissions for news feeds, i.e. which news feed a editor has access to and if he/she is allowed to create or delete them). Since this feed is now a page controller, access in general is handled by the page type limitation. The question is, if we want to keep this distinction? I for myself are fine with the general limitation (can access news feed page types yes/no).

New Features

  • JSON Feeds
  • Only list featured/unfeatured news articles in the feed (equivalent to the newslist module)

@bezin bezin marked this pull request as draft May 17, 2022 07:58
@bezin bezin force-pushed the news-feed-as-controller branch from 667c058 to 183a266 Compare May 17, 2022 08:13
Copy link
Member

@aschempp aschempp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks very promising! Added feedback and minor nitpicks, but overall its 🔥

news-bundle/src/ContaoManager/Plugin.php Outdated Show resolved Hide resolved
news-bundle/src/Controller/NewsFeedController.php Outdated Show resolved Hide resolved
news-bundle/src/Controller/NewsFeedController.php Outdated Show resolved Hide resolved
news-bundle/src/Controller/NewsFeedController.php Outdated Show resolved Hide resolved
news-bundle/src/Controller/NewsFeedController.php Outdated Show resolved Hide resolved
news-bundle/src/Resources/contao/dca/tl_layout.php Outdated Show resolved Hide resolved
news-bundle/src/Controller/NewsFeedController.php Outdated Show resolved Hide resolved
news-bundle/src/Resources/contao/languages/en/tl_page.xlf Outdated Show resolved Hide resolved
news-bundle/src/Resources/contao/dca/tl_news_feed.php Outdated Show resolved Hide resolved
@bezin bezin force-pushed the news-feed-as-controller branch from df1ab5e to 09fc96e Compare May 18, 2022 10:05
@bezin bezin force-pushed the news-feed-as-controller branch from ba94d69 to 9339deb Compare May 18, 2022 10:43
@aschempp
Copy link
Member

I also noticed FeedIO currently requires Guzzle (see alexdebril/feed-io#398) 🙈

@leofeyer leofeyer added this to the 5.0 milestone May 20, 2022
@bezin bezin force-pushed the news-feed-as-controller branch from fa24ecb to cbafd91 Compare May 23, 2022 12:19
@bezin bezin force-pushed the news-feed-as-controller branch 2 times, most recently from b799aa6 to f2a2357 Compare May 31, 2022 07:20
@bezin
Copy link
Contributor Author

bezin commented May 31, 2022

There are also some permissions for news feeds, i.e. which news feed a editor has access to and if he/she is allowed to create or delete them). Since this feed is now a page controller, access in general is handled by the page type limitation. The question is, if we want to keep this distinction?

What is your take on this? IMO we should drop these granular permissions and handle feeds like every other page, too.

@bezin bezin force-pushed the news-feed-as-controller branch from 5377d6e to f0e189f Compare May 31, 2022 11:49
@aschempp
Copy link
Member

There are also some permissions for news feeds, i.e. which news feed a editor has access to and if he/she is allowed to create or delete them). Since this feed is now a page controller, access in general is handled by the page type limitation. The question is, if we want to keep this distinction?

What is your take on this? IMO we should drop these granular permissions and handle feeds like every other page, too.

I think so too. Did we consider how this can be migrated on an update? Because I guess we cannot migrate the permissions?

@bezin bezin force-pushed the news-feed-as-controller branch from 1c1c18e to 2b1258d Compare May 31, 2022 12:54
@bezin
Copy link
Contributor Author

bezin commented May 31, 2022

I think so too. Did we consider how this can be migrated on an update? Because I guess we cannot migrate the permissions?

As there is no direct equivalent to each option after this gets merged I think we cannot migrate these. The baseline would be, that if an editor has the permission to at least one news feed, we should allow access to the new News Feed page type in general. However, this would mean the editor may now have permission to more feeds than previously.

@bezin
Copy link
Contributor Author

bezin commented May 31, 2022

As you see I have added a TransformFeedItem to make the transformation from a news model to feed item exensible. However, I am not exactly sure about this and have some more cases, where I fail to see how to implement this the right way:

  • I use feeds (custom implementation) with CleverReach to import Contao News into their editor. They do not wait long enough when requesting images for it work with our deferred image resizing. Hence I need a way to tell Contao to resize images right away in this case.

  • For the same use case, I want to be able to overwrite image sizes in Image content elements to resize them to a size that is suitable for mailings.

From contao/core-bundle#1243:

  • Add a namespace to the Feed object, e.g. for Facebook Instant Articles. The library we use supports this, but it must be extensible by a third party.

Any comment much appreciated. Maybe the image resizing must be solved completely different anyways.

@bezin
Copy link
Contributor Author

bezin commented Jun 1, 2022

I experimented with a provider service rather than an event (see bezin@19aad3b)

I implemented a FeedProvider that a) creates the feed instance, b) fetches the news articles depending on page settings and c) transforms articles to items. This way, you may decorate the provider and alter the feed instance and/or every item.

Add additional namespaces to the feed instance:

// src/App/NewsFeedProvider

class NewsFeedProvider implements FeedProviderInterface
{
  // ...
  public function getFeed(): FeedInterface
  {
    $feed = $this->inner->getFeed();
    $feed->addNS('content', 'http://purl.org/rss/1.0/modules/content/');
    return $feed;
  }
  // ...
}

Add a custom format options to tl_page.feedSource and alter item transformation all together in your decorator:

// src/App/NewsFeedProvider

class NewsFeedProvider implements FeedProviderInterface
{
  // ...
  public function getItemFromModel(NewsModel $model): ItemInterface
  {
    if ('my_custom_source_option' !== $this->pageModel->feedSource) {
      return $this->inner->getItemFromModel($model);
    }
    
    // Handle item creation in your own way
  }
  // ...
}

What are your thoughts on this?

@fritzmg
Copy link
Contributor

fritzmg commented Jun 1, 2022

Apparently you are not supposed to extend from the original service when decorating 😬 🤷

I'd prefer an event still I think, since that is what we use for /sitemap.xml and /robots.txt as well.

@m-vo
Copy link
Member

m-vo commented Jun 1, 2022

Apparently you are not supposed to extend from the original service when decorating

Yes, that's a bad idea in general, because you cannot guarantee that the original class will be in the correct state if you only pass on some calls. Implementing the interface, injecting the original service and using its public API is usually safer to do. 🙂

But tbh this is also true for every extended base class - so it primarily depends on if a class is designed for this use case or not (for non abstract classes: mostly not).

@bezin
Copy link
Contributor Author

bezin commented Jun 1, 2022

Apparently you are not supposed to extend from the original service when decorating 😬 🤷

Yes, you are right. This is actually wrong in the example – it is not required.

@bezin bezin force-pushed the news-feed-as-controller branch 2 times, most recently from fed0994 to 3b870ed Compare June 3, 2022 10:43
@leofeyer leofeyer force-pushed the news-feed-as-controller branch from 1c6b3c2 to 0a59409 Compare August 10, 2022 08:26
@bezin
Copy link
Contributor Author

bezin commented Aug 10, 2022

Couldn’t you create those images on the fly when running the tests? like we do here:

Did so in 931f26b Thanks for the hint!

@leofeyer leofeyer changed the title News feed as page controller News feeds as page controller Aug 10, 2022
@leofeyer leofeyer merged commit 739b8a9 into contao:5.0 Aug 10, 2022
@leofeyer
Copy link
Member

Thank you @bezin.

@bezin bezin deleted the news-feed-as-controller branch August 11, 2022 10:30
leofeyer added a commit that referenced this pull request Apr 14, 2023
Description
-----------

Fixes #5948

The callback was accidentally removed in #4682.

Commits
-------

d25d03c Add the "adjustDca" load callback to tl_news_archive again
leofeyer pushed a commit that referenced this pull request Mar 8, 2024
Description
-----------

This fixes several problems (also see commits) in #4682

1. The feed selection in page layouts was not migrated to the new pages
2. the new feed pages were not published, making the feeds unavailable after the update
3. if no root page was found, the existing data was silently dropped (when dropping tables) instead of failing the migration
4. DBAL `fetchOne` would return `false` if no root page was found, but the method signature expected a `null` value
5. Sorts the new feed pages at the bottom of the root pages (probably related to #6715)
6. correctly handles the base feed URL if it e.g. contains a trailing slash

/cc @bezin

Commits
-------

e77aa64 Also migrate the layout configuration for news feeds
543a354 Publishe the newly created feed pages
631239b Fail the migration if no root page is found
12ff483 Fixed return argument when finding root page
be39358 Fixed parsing feed base URL with trailing slash
5d2bd02 Sort the new feed pages at the bottom of the root page
acf6e9f Fixed tests
leofeyer pushed a commit to contao/news-bundle that referenced this pull request Mar 8, 2024
Description
-----------

This fixes several problems (also see commits) in contao/contao#4682

1. The feed selection in page layouts was not migrated to the new pages
2. the new feed pages were not published, making the feeds unavailable after the update
3. if no root page was found, the existing data was silently dropped (when dropping tables) instead of failing the migration
4. DBAL `fetchOne` would return `false` if no root page was found, but the method signature expected a `null` value
5. Sorts the new feed pages at the bottom of the root pages (probably related to contao/contao#6715)
6. correctly handles the base feed URL if it e.g. contains a trailing slash

/cc @bezin

Commits
-------

e77aa64d Also migrate the layout configuration for news feeds
543a354c Publishe the newly created feed pages
631239b5 Fail the migration if no root page is found
12ff4830 Fixed return argument when finding root page
be393581 Fixed parsing feed base URL with trailing slash
5d2bd02b Sort the new feed pages at the bottom of the root page
acf6e9f1 Fixed tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants