Commit 1bcf50ad authored by Tim Diels's avatar Tim Diels
Browse files

Issue #3325514 by tim-diels: Recent items shown even when there are no recent items

parent 687096f8
Loading
Loading
Loading
Loading
+53 −49
Original line number Diff line number Diff line
@@ -175,6 +175,14 @@ class ContentMenuLinkDerivative extends DeriverBase implements ContainerDeriverI

    if (!empty($count)) {

      $entity_storage = \Drupal::service('entity_type.manager')->getStorage('node');
      $ids = $entity_storage->getQuery()
        ->condition('type', $content_type->id())
        ->pager($count + 1)
        ->sort('changed', 'DESC')
        ->execute();

      if (count($ids)) {
        $links[$link_name . '.recent'] = [
          'title' => $this->t('Recent items'),
          'route_name' => 'system.admin_content',
@@ -188,19 +196,12 @@ class ContentMenuLinkDerivative extends DeriverBase implements ContainerDeriverI
          'options' => [
            'attributes' => [
              'class' => [
              'admin-toolbar-content-recent-items'
            ]
          ]
        ]
                'admin-toolbar-content-recent-items',
              ],
            ],
          ],
        ] + $base_plugin_definition;

      $entity_storage = \Drupal::service('entity_type.manager')->getStorage('node');
      $ids = $entity_storage->getQuery()
        ->condition('type', $content_type->id())
        ->pager($count + 1)
        ->sort('changed', 'DESC')
        ->execute();

        $c = 0;
        foreach ($ids as $id) {
          // Skip the last one.
@@ -210,16 +211,18 @@ class ContentMenuLinkDerivative extends DeriverBase implements ContainerDeriverI

          /** @var \Drupal\node\NodeInterface $entity */
          $entity = $entity_storage->load($id);
        if ($entity === null) continue; // HACK fix, getQuery can return results which load can't load???
          if ($entity === NULL) {
            continue;
          } // HACK fix, getQuery can return results which load can't load???
          $links[$link_name . '.entity.' . $entity->id()] = [
            'title' => $entity->label(),
            'route_name' => "entity.node.edit_form",
            'route_parameters' => [
            'node' => $entity->id()
              'node' => $entity->id(),
            ],
            'menu_name' => 'admin',
            'weight' => $c + 1,
          'parent' => $base_plugin_definition['id'] . ':' . $link_name
            'parent' => $base_plugin_definition['id'] . ':' . $link_name,
          ] + $base_plugin_definition;
        }

@@ -237,12 +240,13 @@ class ContentMenuLinkDerivative extends DeriverBase implements ContainerDeriverI
            'options' => [
              'attributes' => [
                'class' => [
                'admin-toolbar-content-more-item'
              ]
            ]
          ]
                  'admin-toolbar-content-more-item',
                ],
              ],
            ],
          ] + $base_plugin_definition;
        }
      }

    }