Problem/Motivation

The \Drupal\Core\Menu\ContextualLinkManager::getContextualLinksArrayByGroup() calls the ContextualLinkInterface::getTitle() implementations with an argument (which is a request object) but the interface definition does not suggests that an argument will be passed always.

Instead the manager is supposed to use the controller resolver as the \Drupal\Core\Menu\LocalActionManager does.

The docs for \Drupal\Core\Menu\LocalActionInterface::getTitle and \Drupal\Core\Menu\ContextualLinkInterface::getTitle are nearly identical and indicate the controller resolver will be used.

Proposed resolution

Call ContextualLinkInterface::getTitle via the controller resolver (if possible) or fix the docs to indicate the request object is the only possible parameter.

Allowed?

https://www.drupal.org/core/d8-allowed-changes
Might be allowed in 8.2.x
https://www.drupal.org/core/d8-allowed-changes#beta
as a non-disruptive bug fix

https://www.drupal.org/core/release-cycle-overview#dates
8.2.x is in beta until the Sept 7 rc1

Remaining tasks

User interface changes

No

API changes

Probably none - adding better docs and test coverage

Data model changes

No

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Sweetchuck created an issue. See original summary.

Sweetchuck’s picture

Issue tags: +Drupalaton
YesCT’s picture

So, one thing we can do is look for usages of getTitle() and if any that pass an arg, all of those do not *use* the arg, then we could take the arg out and leave the interface as it is. So I guess we are searching for some usage where the arg *is* used.

Wim Leers’s picture

Priority: Normal » Minor
Status: Active » Needs review
FileSize
732 bytes

Nice catch!

AFAICT that's just a c/p remnant. Nothing relies on it. Let's just remove it.

YesCT’s picture

Status: Needs review » Needs work

I think we need to change some more things (where it was called with a request). I'm working on a new patch.

YesCT’s picture

Priority: Minor » Normal
Issue summary: View changes
Status: Needs work » Needs review
Issue tags: +DX (Developer Experience)
FileSize
1.84 KB
2.19 KB

I went through
ag "\->getTitle.*request" core
And looked for any that were using $request that should not.

Lots were from TitleResolverInterface getTitle() and seemed fine.

I did *not* figure out core/modules/system/tests/modules/batch_test/batch_test.module call to getTitle()

And

LocalActionDefaultTest::testGetTitleWithTitleArguments() looks related but different because it is
LocalActionDefault which has a getTitle() with a request arg, but it does not use the arg, and it is an
LocalActionInterface which has no arguments to getTitle()

#2795235: Inaccurate getTitle() signature in LocalActionDefault for that.

---
these changes are

1. to remove the use that is not needed when the request arg is taken out,

2. to take out the request (which was not used) from the methods that were adding it as an arg

---
lets see if this causes any tests to fail.

---

not minor according to https://www.drupal.org/core/issue-priority#minor

Status: Needs review » Needs work

The last submitted patch, 6: 2783375-6.patch, failed testing.

YesCT’s picture

I'm looking into the fails. Test results point to UserTokenReplaceTest

running locally with
php core/scripts/run-tests.sh --sqlite /tmp/drupal/test.sqlite --dburl mysql://root:root@localhost/drupal2 --url http://localhost:8888/drupal2 --class "Drupal\user\Tests\UserTokenReplaceTest"

Drupal\user\Tests\UserTokenReplaceTest 60 passes

hm. gonna retest.

YesCT’s picture

Title: Inaccurate getTitle() signature in ContextualLinkInterface » Multiple getTitle() implementations violate their Menu subsystem interfaces
Status: Needs work » Needs review
FileSize
3.48 KB

combining with #2795235: Inaccurate getTitle() signature in LocalActionDefault per #11 there.

bit worrying that that also had some fails
https://www.drupal.org/pift-ci-job/449085

pwolanin’s picture

I'm pretty sure the Request object should be passed there based on the code in places like the ContextualLinkManager

        'title' => $plugin->getTitle($request),

You need the request or something to e.g. resolve the current user.

pwolanin’s picture

The LocalTaskManager does:

  public function getTitle(LocalTaskInterface $local_task) {
    $controller = array($local_task, 'getTitle');
    $request = $this->requestStack->getCurrentRequest();
    $arguments = $this->controllerResolver->getArguments($request, $controller);
    return call_user_func_array($controller, $arguments);
  }

So... this is like the way Symfony allows you to add the request as an argument to any route controller. Maybe it's just a documentation gap?

pwolanin’s picture

Status: Needs review » Needs work

This is one of those screwy things I recall discussing with maybe dawehner or tim.plunkett

When you are using the controller resolver, the interface has no args, but any implementation can ask for args with a default of NULL.

So, I'm not sure this issue is going in the right direction.

The discrepancy between contextual link and the others seems like the problem in addition to weak docs.

LocalActionManager also uses the controller resolver

  public function getTitle(LocalActionInterface $local_action) {
    $controller = array($local_action, 'getTitle');
    $arguments = $this->controllerResolver->getArguments($this->requestStack->getCurrentRequest(), $controller);
    return call_user_func_array($controller, $arguments);
  }

MenuLink is expected to be much more flexible behind the plugin facade, so it's not using the same approach at all

pwolanin’s picture

Title: Multiple getTitle() implementations violate their Menu subsystem interfaces » ContextualLinkManager calls getTitle() on ContextualLinkInterface plugins without using the controller resolver
Issue summary: View changes

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev
larowlan’s picture

Issue tags: +Bug Smash Initiative

Agree with #13

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 9.5.x-dev

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

Version: 9.5.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. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.