Unverified Commit f82dea9e authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3518662 by catch, berdir: Use a lazy builder/placeholder for the top bar

parent 1e930a4d
Loading
Loading
Loading
Loading
Loading
+19 −6
Original line number Diff line number Diff line
@@ -204,13 +204,26 @@ protected function getContentTop(): array {
   * @see hook_page_top()
   */
  public function buildTopBar(array &$page_top): void {
    $page_top['top_bar']['#cache']['contexts'][] = 'user.permissions';
    if ($this->currentUser->hasPermission('access navigation')) {
      $page_top['top_bar'] = [
      '#type' => 'top_bar',
      '#access' => $this->currentUser->hasPermission('access navigation'),
        '#cache' => [
        'keys' => ['top_bar'],
        'contexts' => ['user.permissions'],
          'keys' => ['navigation', 'top_bar'],
          'max-age' => CacheBackendInterface::CACHE_PERMANENT,
        ],
        '#lazy_builder' => ['navigation.renderer:doBuildTopBar', []],
        '#create_placeholder' => TRUE,
      ];
    }
  }

  /**
   * Lazy builder to generate the top bar render array.
   */
  #[TrustedCallback]
  public function doBuildTopBar(): array {
    return [
      '#type' => 'top_bar',
    ];
  }

+2 −2
Original line number Diff line number Diff line
@@ -76,14 +76,14 @@ public function testLogin(): void {

    $expected = [
      'QueryCount' => 4,
      'CacheGetCount' => 47,
      'CacheGetCount' => 45,
      'CacheGetCountByBin' => [
        'config' => 10,
        'data' => 4,
        'discovery' => 9,
        'bootstrap' => 8,
        'dynamic_page_cache' => 1,
        'render' => 14,
        'render' => 12,
        'menu' => 1,
      ],
      'CacheSetCount' => 2,