Problem/Motivation

The proper way to retrieve an upcasted route parameter is via the RouteMatch. BookNavigationBlock and BookNavigationCacheContext attempt to achieve that by accessing the request attribute directly.

Proposed resolution

Use the proper method to access upcasted route parameter, i.e. the same code as BookBreadcrumbBuilder.

Remaining tasks

User interface changes

API changes

Data model changes

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Bug
Issue priority Not critical
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

znerol created an issue. See original summary.

znerol’s picture

Status: Active » Needs review
FileSize
6.53 KB

Status: Needs review » Needs work

The last submitted patch, 2: use_routematch_instead-2575827-2.patch, failed testing.

znerol’s picture

Status: Needs work » Needs review

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

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

Version: 8.1.x-dev » 8.3.x-dev
Status: Needs review » Reviewed & tested by the community

Let's keep this a 8.3.x only fix, so we don't have to deal with 100% strict BC policies.

+++ b/core/modules/book/src/Cache/BookNavigationCacheContext.php
diff --git a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php
index 1a68622..d2c43cd 100644

index 1a68622..d2c43cd 100644
--- a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php

--- a/core/modules/book/src/Plugin/Block/BookNavigationBlock.php
+++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php

+++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php
+++ b/core/modules/book/src/Plugin/Block/BookNavigationBlock.php
@@ -8,12 +8,13 @@

@@ -8,12 +8,13 @@
 namespace Drupal\book\Plugin\Block;
 

Could we not rewrite this block to use context as in block context? Then this block could be also used for usecases where the node is provided by something else in page_manager/panels. I guess this could be totally be done in a follow up.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

I don't think #7 is really a followup - if we're changing how the block gets its book node let's get it right first time.

dawehner’s picture

I don't think #7 is really a followup - if we're changing how the block gets its book node let's get it right first time.

Well, the problem with #7 is that it requires a big update path, and it will break instances of the block in page_manager we cannot update.

alexpott’s picture

Status: Needs work » Reviewed & tested by the community

@dawehner ah ok - then a followup it is.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

Still, the patch needs re-rolling.

dawehner’s picture

hitesh-jain’s picture

Assigned: Unassigned » hitesh-jain
hitesh-jain’s picture

Status: Needs work » Needs review
FileSize
6.64 KB
hitesh-jain’s picture

hitesh-jain’s picture

Assigned: hitesh-jain » Unassigned
hitesh-jain’s picture

Issue tags: -Needs reroll

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.

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.

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.

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.

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.

mindbet’s picture

Patch updated to 9.1-dev

paulocs’s picture

Do we need test coverage for it?

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.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

BookTest already has coverage for the block, as this is a refactor/bug fix I don't think we need additional coverage.

Tentatively marking RTBC. Unsure if we have to do the deprecation dance in the constructors here or not. I could only find one case in contrib and it looks like the module is using the service incorrectly anyway, as it just duplicates the existing core service twice:

https://git.drupalcode.org/project/book_blocks/-/blob/8.x.-1.x/book_bloc...

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: 2575827-25.patch, failed testing. View results

alexpott’s picture

@longwave given thats a stable module I think we should either fix it first or account for BC here by removing the typehint and doing a deprecation dance.

Something like:

  /**
   * Constructs a new BookNavigationCacheContext service.
   *
   * @param \Drupal\Core\Routing\RouteMatchInterface $route_match
   *   The current route match.
   */
  public function __construct($route_match) {
    if (!$route_match instanceof RouteMatchInterface) {
      @trigger_error("@todo", E_USER_DEPRECATED);
      $route_match = \Drupal::routeMatch();
    }
    $this->routeMatch = $route_match;
  }
ayushmishra206’s picture

Status: Needs work » Needs review
FileSize
826 bytes
6.49 KB

Made the changes suggested in #30. Please review.

alexpott’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/book/src/Cache/BookNavigationCacheContext.php
    @@ -25,20 +26,24 @@ class BookNavigationCacheContext implements CacheContextInterface, ContainerAwar
    -    $this->requestStack = $request_stack;
    

    Oh we also should use the \Drupal\Core\DependencyInjection\DeprecatedServicePropertyTrait in order to provide BC for this. See \Drupal\Core\Installer\Form\SiteConfigureForm::$deprecatedProperties for an example of how that works.

  2. +++ b/core/modules/book/src/Cache/BookNavigationCacheContext.php
    @@ -25,20 +26,24 @@ class BookNavigationCacheContext implements CacheContextInterface, ContainerAwar
    +      @trigger_error("@todo", E_USER_DEPRECATED);
    

    @todo was a placeholder :) - see other @trigger_error's in constructors for an example of what to do. I don't think this requires a CR because the @trigger_error message will describe exactly what to do.

msuthars’s picture

Updated the patch as changes mentioned in #32. Please review.

msuthars’s picture

Status: Needs work » Needs review
longwave’s picture

Status: Needs review » Needs work
+++ b/core/modules/book/src/Cache/BookNavigationCacheContext.php
@@ -23,22 +25,32 @@
+      @trigger_error("Passing the request_stack service to ' . __METHOD__ . '() is deprecated in drupal:9.2.0 and will be removed before drupal:10.0.0. The parameter should be instance of \Drupal\Core\Routing\RouteMatchInterface instead", E_USER_DEPRECATED);

A word is missing here - this should read "The parameter should be an instance of..." or could just be "Pass an instance of...". The sentence should also end in a full stop.

Also, we should add a deprecation test for this.

msuthars’s picture

Assigned: Unassigned » msuthars
msuthars’s picture

Assigned: msuthars » Unassigned
Status: Needs work » Needs review
FileSize
8.18 KB
2.07 KB

Updated the patch as changes suggested by @longwave in #35.

msuthars’s picture

FileSize
8.18 KB
2.08 KB

Missed the full stop in patch #37. Updated the patch as changes suggested by @longwave in #35.

longwave’s picture

Thanks, the message looks good now.

+++ b/core/modules/book/tests/src/Functional/BookTest.php
@@ -97,6 +98,17 @@ protected function setUp(): void {
+    $bookNavigationCacheContext = new BookNavigationCacheContext($requestStack);

We will get the unused variable police on this line sooner or later, we should assert something simple about the result I think. Also the variable names should be snake_case not camelCase.

paulocs’s picture

Assigned: Unassigned » paulocs

I'll do the fix

paulocs’s picture

Assigned: paulocs » Unassigned
FileSize
918 bytes
8.24 KB

Added changes pointed on comment #39.

longwave’s picture

Status: Needs review » Needs work

$requestStack doesn't follow our variable naming either, sorry!

msuthars’s picture

Status: Needs work » Needs review
FileSize
8.24 KB
984 bytes

Updated the patch as suggested in #42.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

This all looks good now.

  • catch committed a8ef436 on 9.2.x
    Issue #2575827 by msuthars, paulocs, ayushmishra206, hitesh-jain, znerol...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed/pushed to 9.2.x, thanks!

Status: Fixed » Closed (fixed)

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