Problem/Motivation

We want a quick access to edit the current layout if the user has access to that.
Provide local task for editing current dashboard layout.

Proposed resolution

As local task won't have the context for building the layout builder route, we need an intermediate redirect where we can check the referer. This is not clean, and there are no references in core to using a similar pattern aside of logging (dblog, syslog)

Remaining tasks

Patch with tests.

User interface changes

Added an "edit layout" tab to the dashboard.

API changes

None.

Data model changes

None.

Comments

penyaskito created an issue. See original summary.

penyaskito’s picture

Status: Active » Postponed
StatusFileSize
new2.96 KB

This patch applies on top of #3348617: Show dashboards as local tasks, so postponing on that one.

penyaskito’s picture

StatusFileSize
new420 bytes
new2.98 KB

Oops I renamed the route last minute, changing local tasks too.

penyaskito’s picture

I think visually it's less weird with a local action instead of local tasks, which produces all kind of weird behaviors as we are using as a local task a route that has already its own local tasks, so we see duplicated tabs etc (even when trying a secondary level). Ideally we would revisit this when/if https://www.drupal.org/project/ideas/issues/3325034 materializes.

penyaskito’s picture

I let both implementations for comparison at the tugboats at:

local task: https://github.com/penyaskito/dashboard-initiative/pull/10
local action: https://github.com/penyaskito/dashboard-initiative/pull/17

plopesc’s picture

Hi,

Thank you for your great work here. Tested both Tugboat environments, and I would go for the Local Action based approach.

It looks cleaner to me. The "Edit Layout" local task at the same level can be confusing and it requires the extra redirect you mentioned.

In case we want to follow the local tasks path, we might try to add the parent_id property to show it in a second level, like in /admin/structure/block.

penyaskito’s picture

Both options would require an intermediate redirect for the "default" dashboard. And you can't specify a parent_id (or a base route) with arguments, or I didn't found a way, so the local tasks ended up being a mess (even more with a second level).

Maybe you want to give it a try?

plopesc’s picture

StatusFileSize
new8.88 KB

Agree that nested local tasks can be problematic, so let's put them apart for now.

Attaching patch following a custom local task class approach instead of the intermediate controller. This approach could be useful as well if we need to move to local tasks in the future.

andypost’s picture

  1. +++ b/src/DashboardManager.php
    @@ -0,0 +1,66 @@
    +  /**
    +   * The current user account.
    +   *
    +   * @var \Drupal\Core\Session\AccountInterface
    +   */
    +  protected $currentUser;
    +
    +  /**
    +   * The entity type manager.
    +   *
    +   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
    +   */
    +  protected $entityTypeManager;
    ...
    +  public function __construct(AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager) {
    
    - public function __construct(AccountInterface $current_user, EntityTypeManagerInterface $entity_type_manager) {
    +public function __construct(protected AccountInterface $current_user, protected EntityTypeManagerInterface $entity_type_manager) {
    
  2. +++ b/src/DashboardManager.php
    @@ -0,0 +1,66 @@
    +   * @return \Drupal\dashboard\DashboardInterface|null
    +   *   The dashboard to be used if available, NULL otherwise.
    ...
    +  public function getDefaultDashboard(AccountInterface $account = NULL) {
    

    could return type ?DashboardInterface

  3. +++ b/src/Plugin/Menu/LocalAction/DashboardLocalAction.php
    @@ -0,0 +1,73 @@
    +   * The dashboard manager.
    +   *
    +   * @var \Drupal\dashboard\DashboardManager
    +   */
    +  protected $dashboardManager;
    ...
    +    DashboardManager $dashboard_manager
    

    could be moved to protected DashboardManager $dashboard_manager in constructor

plopesc’s picture

Back to Needs Review once #3348617 is already merged.

Thank you for your review @andypost. I'm fine these PHP 8.1 style code changes, but I don't know what's the policy about it in Drupal core right now. Reviewed some modules and apparently they're not not following it yet. In any case I would do it at once for the whole module at some point instead of following it in specific places and other don't.

andypost’s picture

Core started to adopt constructor promotions already, it helps to minimize boilerplate for properties.

penyaskito’s picture

I agree with @andypost here. Better start doing it already than accumulating more tech debt.
I've tested this and it looks great. @plopesc Happy to merge this as is, and we do a quick round of constructor promotions in a follow-up?

plopesc’s picture

Sounds like a plan!

Thank you for checking it.

penyaskito’s picture

Title: [PP-1] Provide local task for editing current dashboard layout » Provide local task for editing current dashboard layout
Status: Postponed » Reviewed & tested by the community
penyaskito’s picture

Created https://www.drupal.org/project/3327580/issues/3367934

Committing this now after checking in https://github.com/penyaskito/dashboard-initiative/pull/19 that works as expected and tests pass.

penyaskito’s picture

Status: Reviewed & tested by the community » Fixed

Thanks!

Status: Fixed » Closed (fixed)

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

plopesc’s picture

Project: Dashboard-sandbox » Dashboard
Version: » 2.x-dev