Problem/Motivation

Except for aggregator_feed, node and user, all content entity types are still declaring their routes manually instead of utilizing the default route provider we have in core now.

Proposed resolution

Use a route provider for all core content entity types, specifically:

Remaining tasks

User interface changes

None.

API changes

None.

Data model changes

None.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

tstoeckler created an issue. See original summary.

tstoeckler’s picture

Issue summary: View changes
tstoeckler’s picture

Assigned: Unassigned » tstoeckler
Issue summary: View changes
Status: Active » Needs review
FileSize
19.55 KB

Here we go.

Leaving menu links out for now, because they do something interesting with bundles. Will open a separate issue for that.

Status: Needs review » Needs work

The last submitted patch, 3: 2723615-3-route-provider-content.patch, failed testing.

tstoeckler’s picture

Status: Needs work » Needs review
FileSize
19.54 KB

Rebased local branch with 8.2.x

Status: Needs review » Needs work

The last submitted patch, 5: 2723615-5-route-provider-content.patch, failed testing.

tstoeckler’s picture

Opened #2760653: Use an entity route provider for taxonomy terms for the menu links, see the IS there for why.

tstoeckler’s picture

tstoeckler’s picture

So this is also postponed on #2751835: Entity::urlRouteParameters() is broken for add-page and add-form link templates because taxonomy terms also have the same weird code that nodes have that prints out all entity links in the head.

Let's see if a combined patch is green.

tstoeckler’s picture

Title: Use entity route providers for all content entity types » [PP-1] Use entity route providers for all content entity types
tstoeckler’s picture

Title: [PP-1] Use entity route providers for all content entity types » [PP-1] Use entity route providers for all content entity types except menu_link_content
dawehner’s picture

Really great work!

+++ b/core/modules/shortcut/src/Entity/ShortcutHtmlRouteProvider.php
@@ -0,0 +1,62 @@
+        ->setDefault('_title_callback', FALSE)
...
+        ->setDefault('_title_callback', FALSE)

Is there any way to properly unset a value?

tstoeckler’s picture

There's no dedicated method. What we could do is:

$defaults = $route->getDefaults();
unset($defaults['_title_callback']);
$defaults['_title'] = ...;
$route->setDefaults($defaults);

That was a bit too verbose for my taste, so I went with the slightly less correct but more readable version. I don't feel strongly, though. If you think the above would be better, I can do that.

tstoeckler’s picture

Title: [PP-1] Use entity route providers for all content entity types except menu_link_content » Use entity route providers for all content entity types except menu_link_content
FileSize
1.36 KB
21.87 KB

Implemented #13.

I am also splitting out the taxonomy changes out of this issue. That way this no longer needs to be postponed. I am moving those over to #2760653: Use an entity route provider for taxonomy terms which was originally about menu link, but I am merging menu links back in here. So the attached patch is the one in #5 plus the one in #5 over there (plus the attached interdiff per #13).

tstoeckler’s picture

Title: Use entity route providers for all content entity types except menu_link_content » Use entity route providers for all content entity types
Issue summary: View changes
FileSize
26.42 KB

Merging #2760653: Use an entity route provider for taxonomy terms back in here, not that that's no longer postponed.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dawehner’s picture

That is certainly super nice work!

  1. +++ b/core/modules/block_content/block_content.routing.yml
    @@ -6,26 +6,6 @@ entity.block_content_type.collection:
    -    _title_callback: 'Drupal\block_content\Controller\BlockContentController::getAddFormTitle'
    
    +++ b/core/modules/comment/comment.routing.yml
    @@ -36,24 +27,6 @@ comment.approve:
    -    _title_callback: '\Drupal\comment\Controller\CommentController::commentPermalinkTitle'
    

    Should we mark this method as deprecated as well?

  2. +++ b/core/modules/block_content/src/Entity/BlockContentHtmlRouteProvider.php
    @@ -0,0 +1,70 @@
    +    if ($add_page_route = $collection->get("entity.{$entity_type_id}.add_page")) {
    +      $collection->add('block_content.add_page', $add_page_route);
    +      $collection->remove("entity.{$entity_type_id}.add_page");
    +    }
    +    if ($add_form_route = $collection->get("entity.{$entity_type_id}.add_form")) {
    +      $collection->add('block_content.add_form', $add_form_route);
    +      $collection->remove("entity.{$entity_type_id}.add_form");
    +    }
    

    I'm wondering whether we should maybe copy the route definition or so?

tstoeckler’s picture

Thanks for the review, much appreciated!

Re #17:

    1. See
      +        ->setDefault('_title_callback', BlockContentController::class . '::getAddFormTitle');
      

      in \Drupal\block_content\Entity\BlockContentHtmlRouteProvider::getAddFormRoute().

    2. Good catch! Fixed.
  1. Do you mean leaving in the old route definition or do you mean cloning the actual route object? I'm not sure I understand.
tstoeckler’s picture

Assigned: tstoeckler » Unassigned

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

tstoeckler’s picture

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

phenaproxima’s picture

Status: Needs review » Needs work
Issue tags: +SprintWeekend2018, +Needs reroll

This definitely needs a re-roll.

robpowell’s picture

Status: Needs work » Active
Issue tags: +SprintWeekendBOS

I am rerolling for SprintWeekend2018

robpowell’s picture

Status: Active » Needs review
robpowell’s picture

phenaproxima’s picture

Status: Needs review » Needs work
Issue tags: -Needs reroll

Thanks, @robpowell and @tstoeckler! This is a pretty straightforward patch, and a very nice improvement to the entity system.

  1. +++ b/core/modules/block_content/src/Entity/BlockContentHtmlRouteProvider.php
    @@ -0,0 +1,70 @@
    +    // Rename the add page and add form routes for backwards compatibility.
    +    $entity_type_id = $entity_type->id();
    +    if ($add_page_route = $collection->get("entity.{$entity_type_id}.add_page")) {
    +      $collection->add('block_content.add_page', $add_page_route);
    +      $collection->remove("entity.{$entity_type_id}.add_page");
    +    }
    +    if ($add_form_route = $collection->get("entity.{$entity_type_id}.add_form")) {
    +      $collection->add('block_content.add_form', $add_form_route);
    +      $collection->remove("entity.{$entity_type_id}.add_form");
    +    }
    

    Is there a way to mark these routes as deprecated?

  2. +++ b/core/modules/comment/src/Controller/CommentController.php
    @@ -153,6 +153,9 @@ public function commentPermalink(Request $request, CommentInterface $comment) {
    +   *
    +   * @deprecated in 8.2.x, will be removed in Drupal 9. Use
    +   *   \Drupal\Core\Entity\Controller\EntityController::title() instead.
        */
       public function commentPermalinkTitle(CommentInterface $comment) {
    

    Should be trigger a deprecation notice in the method itself?

  3. +++ b/core/modules/menu_link_content/src/Controller/MenuController.php
    @@ -18,6 +18,10 @@ class MenuController extends ControllerBase {
    +   * @deprecated in 8.2.x, will be removed in Drupal 9. Use
    +   *   '_entity_form: menu_link_content.add' as a route default instead and
    +   *   specify the bundle as a route default additionally.
        */
       public function addLink(MenuInterface $menu) {
    

    Ditto here.

  4. +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContent.php
    @@ -379,4 +386,17 @@ public function setRequiresRediscovery($rediscovery) {
    +    // Account for legacy route names.
    +    /** @var \Drupal\Core\Url $url */
    +    $url = parent::toUrl($rel, $options);
    +    if ($rel === 'add-form') {
    +      $url = Url::fromRoute('entity.menu.add_link_form', $url->getRouteParameters(), $url->getOptions());
    +    }
    +    return $url;
    

    We should probably trigger a deprecation notice here.

  5. +++ b/core/modules/menu_link_content/src/Entity/MenuLinkContentHtmlRouteProvider.php
    @@ -0,0 +1,66 @@
    +    if ($add_form_route = $collection->get("entity.{$entity_type_id}.add_form")) {
    +      $collection->add('entity.menu.add_link_form', $add_form_route);
    +      $collection->remove("entity.{$entity_type_id}.add_form");
    

    Why is this deviating from the generic entity.FOOBAR.add_form pattern?

  6. +++ b/core/modules/shortcut/src/Controller/ShortcutController.php
    @@ -19,6 +19,9 @@ class ShortcutController extends ControllerBase {
    +   *
    +   * @deprecated in 8.2.x, will be removed in 9.x. Use
    +   *   '_entity_form: shortcut.add' in route declarations instead.
        */
       public function addForm(ShortcutSetInterface $shortcut_set) {
    

    We should fire a deprecation notice here.

  7. +++ b/core/modules/shortcut/src/Entity/ShortcutHtmlRouteProvider.php
    @@ -0,0 +1,62 @@
    +/**
    + * Provides HTML routes for block contents.
    + */
    +class ShortcutHtmlRouteProvider extends DefaultHtmlRouteProvider {
    

    Inaccurate doc comment.

  8. +++ b/core/modules/shortcut/src/Entity/ShortcutHtmlRouteProvider.php
    @@ -0,0 +1,62 @@
    +    if ($add_form_route = $collection->get("entity.{$entity_type_id}.add_form")) {
    +      $collection->add('shortcut.link_add', $add_form_route);
    +      $collection->remove("entity.{$entity_type_id}.add_form");
    +    }
    

    Again, why is this deviating from the entity.TYPE.add_form pattern?

  9. +++ b/core/modules/taxonomy/src/Controller/TaxonomyController.php
    @@ -20,6 +20,9 @@ class TaxonomyController extends ControllerBase {
    +   *
    +   * @deprecated in 8.2.x, will be removed in 9.x. Use
    +   *   '_entity_form: taxonomy_term.add' in route declarations instead.
        */
       public function addForm(VocabularyInterface $taxonomy_vocabulary) {
    

    Should fire a deprecation notice here.

  10. +++ b/core/modules/taxonomy/src/Entity/TermHtmlRouteProvider.php
    @@ -0,0 +1,37 @@
    +/**
    + * Provides HTML routes for block contents.
    + */
    +class TermHtmlRouteProvider extends AdminHtmlRouteProvider {
    

    Needs a doc comment update.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

andypost’s picture

andypost’s picture

Issue tags: +@deprecated

Is there policy about deprecation of route names?

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

AaronMcHale’s picture

According to the issue summary:

Except for aggregator_feed, node and user

node and user could benefit from using or extending the DefaultHtmlRouteProvider class, as currently they do provide their own Route Provider classes but those classes don't extend DefaultHtmlRouteProvider resulting in unnecessary code and YAML entries, this issue seems like a good place to also resolve that.

For clarity aggregator_feed does provide a Route Provider class, but it does extend DefaultHtmlRouteProvider so nothing needs done there.

AaronMcHale’s picture

Found #2723579: [PP-1] NodeRouteProvider should extend DefaultHtmlRouteProvider, last activity over there seems older than on this issue though, we can either leave that one open and fix over there, or close that one and fix over here, any preferences?

tstoeckler’s picture

Re #34: These sets of issues have been very contentious in the past because they sometimes involve minor behavior changes and/or arguable API changes, so I would prefer to scope them as small as possible. So let's leave that issue open just for nodes.

AaronMcHale’s picture

@tstoeckler yeah fair enough, it'll also mean this issue will likely land in Core quicker if the scope remains as it is.

andypost’s picture

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

longwave’s picture

Status: Needs work » Needs review
FileSize
25.91 KB

Rerolled for 9.3.x, #28 not addressed yet.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/comment/src/Controller/CommentController.php
    @@ -171,6 +171,9 @@ public function commentPermalink(Request $request, CommentInterface $comment) {
    +   * @deprecated in 8.2.x, will be removed in Drupal 9. Use
    +   *   \Drupal\Core\Entity\Controller\EntityController::title() instead.
    

    needs separate issue

  2. +++ b/core/modules/shortcut/src/Controller/ShortcutController.php
    @@ -19,6 +19,9 @@ class ShortcutController extends ControllerBase {
    +   * @deprecated in 8.2.x, will be removed in 9.x. Use
    +   *   '_entity_form: shortcut.add' in route declarations instead.
    

    needs own issue

  3. +++ b/core/modules/taxonomy/src/Controller/TaxonomyController.php
    @@ -20,6 +20,9 @@ class TaxonomyController extends ControllerBase {
    +   * @deprecated in 8.2.x, will be removed in 9.x. Use
    +   *   '_entity_form: taxonomy_term.add' in route declarations instead.
    

    the same

andypost’s picture

longwave’s picture

Title: Use entity route providers for all content entity types » [PP-1] Use entity route providers for all content entity types
Status: Needs work » Postponed

Agree with #47, let's postpone until we can provide BC.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

larowlan’s picture

Status: Postponed » Active

Block content module has support for deprecating routes, see \Drupal\block_content\Controller\BlockContentController::blockContentTypeRedirect

this can be active again I think