1

I'm trying to add a Moderation Dashboard tab to the user page like the Moderation Dashboard module, but I can't use Panels. Is it possible to create a layout on a route using layout builder?

I've created the route in msk_module/my_module.routing.yml with

my_module.moderation_dashboard:
  path: '/user/{user}/dashboard'
  defaults:
    _title: 'Moderation Dashboard'
    _controller: '\Drupal\my_module\Controller\MyModuleDashboardController::index'
  requirements:
    _user_is_logged_in: 'TRUE'

And the links task in msk_module/my_module.links.task.yml with

my_module.moderation_dashboard:
  route_name: my_module.moderation_dashboard
  base_route: entity.user.canonical
  title: 'Moderation Dashboard'
  weight: 30

And started the controller in msk_module/src/Controller/MyModuleDashboardController.php with

<?php

namespace Drupal\my_module\Controller;

use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

/**
 * Controller for moderation dashboard.
 */
class MyModuleDashboardController extends ControllerBase {

  /**
   * Display the markup.
   *
   * @return array
   *   Return markup array.
   */
  public function index() {
    return [
      '#type' => 'markup',
      '#markup' => $this->t('Hello, World!'),
    ];
  }

}

So the tab is where I want it. The contents for the tab are the block views displays from the views from Moderation Dashboard. I suppose I can use hook_theme() and a template and some small amount of CSS. Just wondering if layout builder can do the same thing as the panel in page manager can do?

2
  • The Layout Builder module works with content entities, which include the User entity, not generic routes.
    – avpaderno
    Commented Jun 11, 2020 at 20:24
  • 1
    To clarify @apaderno's point, the implementations of the LB API in core are focused on fieldable entities, but that doesn't mean you couldn't achieve this using the API yourself. Docs are lacking though. There are tests that prove it should work, search core for "test_simple_config" Commented Dec 16, 2022 at 19:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.