Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
\Drupal\Core\Menu\ContextualLinkInterface
has a comment that says:
18 * Subclasses may add optional arguments like NodeInterface $node = NULL that
19 * will be supplied by the ControllerResolver.
This is potentially problematic, as you cannot use the instance of this method without using the controller resolver/knowing the arguments beforehand. This means users of a base class cannot use the derived classes automatically. This principle is called Liskov substitution principle.
More interfaces with the same problem:
\Drupal\Core\Form\FormInterface::buildForm
\Drupal\Core\Menu\ContextualLinkInterface
\Drupal\Core\Menu\LocalActionInterface
\Drupal\Core\Menu\LocalTaskInterface
This was added in commit 0d263c64 to address issue #2084463.
Proposed resolution
1. Remove this comment.
2. Identify if a need does exist to add parameters to getTitle. If so, implement an appropriate design pattern.
Remaining tasks
User interface changes
none
Comments
Comment #1
josephdpurcell CreditAttribution: josephdpurcell commentedComment #2
josephdpurcell CreditAttribution: josephdpurcell commentedComment #3
dawehner@josephdpurcell
Well things aren't as easy as you think. You can read a lot of the discussion about that.
It basically comes down to:
Its just that there is no optimal solution IMHO and well for now it would be a API change.
Comment #6
josephdpurcell CreditAttribution: josephdpurcell commentedI just took a look at the latest 8.2.x branch and this issue remains relevant.
Comment #7
dawehnerYeah sadly noone ever come up with a solution for #3
Also updated the issue summary to be approachable.