core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php | 6 +++++- core/lib/Drupal/Core/Menu/MenuLinkTree.php | 2 +- core/modules/system/tests/src/Unit/Menu/MenuLinkTreeTest.php | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php b/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php index e3c1643..a26f6b0 100644 --- a/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php +++ b/core/lib/Drupal/Core/Menu/DefaultMenuLinkTreeManipulators.php @@ -75,7 +75,11 @@ public function __construct(AccessManagerInterface $access_manager, AccountInter * * This is compatible with render caching, because of cache context bubbling: * conditionally defined cache contexts (i.e. subtrees that are only - * accessible to some users) will bubble just + * accessible to some users) will bubble just like they do for render arrays. + * This is why inaccessible subtrees are deleted, except at the root level: if + * we didn't keep those at the root level, we wouldn't be able to know which + * cache contexts would cause those subtrees to become accessible again, thus + * forcing us to conclude that that subtree is unconditionally inaccessible. * * @param \Drupal\Core\Menu\MenuLinkTreeElement[] $tree * The menu link tree to manipulate. diff --git a/core/lib/Drupal/Core/Menu/MenuLinkTree.php b/core/lib/Drupal/Core/Menu/MenuLinkTree.php index a7d5f7e..4b6502f 100644 --- a/core/lib/Drupal/Core/Menu/MenuLinkTree.php +++ b/core/lib/Drupal/Core/Menu/MenuLinkTree.php @@ -171,7 +171,7 @@ public function build(array $tree, $level = 0, CacheableMetadata &$tree_access_c // Gather the access cacheability of every item in the menu link tree, // including inaccessible items. This allows us to render cache the menu - // tree, yet still automatically the rendered menu by the same cache + // tree, yet still automatically vary the rendered menu by the same cache // contexts that the access results vary by. // However, if $data->access is not an AccessResultInterface object, this // still will render the menu link, because this method does not want to diff --git a/core/modules/system/tests/src/Unit/Menu/MenuLinkTreeTest.php b/core/modules/system/tests/src/Unit/Menu/MenuLinkTreeTest.php index 0cd0c1d..d699a8e 100644 --- a/core/modules/system/tests/src/Unit/Menu/MenuLinkTreeTest.php +++ b/core/modules/system/tests/src/Unit/Menu/MenuLinkTreeTest.php @@ -71,7 +71,7 @@ protected function setUp() { * itself, because it may be dynamic. For this reason, MenuLinkInterface * extends CacheableDependencyInterface. It allows any menu link plugin to * mark itself as uncacheable (max-age=0) or dynamic (by specifying cache - * tags and/or contexts), to indicate the extent of dynamicness. + * tags and/or contexts), to indicate the extent of dynamism. * This means there are two cases: * a. permanently cacheable, no cache tags, no cache contexts * b. anything else: non-permanently cacheable, and/or cache tags, and/or