Link to each dashboard's canonical URL somewhere

Created on 10 April 2025, 10 days ago

Problem/Motivation

User stories...

As a site builder who has just created a dashboard for a colleague, I want to find a canonical link to the dashboard that I just created, so that I can send my colleague a link to it.

As a content editor accustomed to the "View"/"Edit"/"Edit layout" tabs on nodes, I want to find a way to "View" the dashboard that I just created, so that I don't have to come up with a new mental model (i.e.: that dashboards work differently than nodes).

I was evaluating the Dashboard module to see if it would be useful for my client's existing Drupal website. I installed the module, found the dashboard configuration page at /admin/structure/dashboard, created a dashboard, added a bunch of blocks to it that I was happy with, and saved my changes. But I couldn't figure out how to "View" my dashboard from the UI: I could only figure out how to "Preview" it. Going back to the dashboard configuration page at /admin/structure/dashboard, I couldn't find a link to "View" to the dashboard from there either. Looking through the Toolbar (installed by default with the Standard profile), there weren't any links to the /admin/dashboard, nor a way to "View" my new dashboard.

Curious if I was missing something, I looked at dashboard.routing.yml, and to my surprise, found out that there is an entity.dashboard.canonical route, i.e.: /admin/dashboard/{dashboard}. It seemed strange to me that I would have to understand the routing system code to figure out how to link to a dashboard, i.e.: if I was creating a dashboard for a less-technical client or colleague.

Steps to reproduce

  1. Download drupal-11.1.6 and dashboard-2.0.0
  2. Install Drupal using the Standard install profile. Install dashboard from the Extend page at /admin/modules
  3. Go to admin/structure/dashboard/add; enter a Label and machine name (I gave my dashboard the machine name lorem), and click Save
  4. Click "Edit layout" on your newly-created dashboard's row at /admin/structure/dashboard, and add some blocks, and click "Save dashboard layout".
  5. Go to /admin/structure/dashboard/lorem (i.e.: click "Edit" in the Primary Tabs) — note that there are no links to the canonical URL, /admin/dashboard/lorem, not even in the page source.
  6. Go to /admin/structure/dashboard/lorem/layout (i.e.: click "Edit layout" in the Primary Tabs) — note that there are no links to the canonical URL, /admin/dashboard/lorem on the page, not even in the page source.
  7. Go to /admin/structure/dashboard/lorem/preview (i.e.: click "Preview" in the Primary Tabs) — note that there are no links to the canonical URL, /admin/dashboard/lorem on the page, not even in the page source.
  8. Go to /admin/structure/dashboard/lorem/permissions (i.e.: click "Manage permissions" in the Primary Tabs) — note that there are no links to the canonical URL, /admin/dashboard/lorem on the page, not even in the page source.
  9. Go to /admin/structure/dashboard — note that there are no links to the canonical URL, /admin/dashboard/lorem on the page, not even in the page source.
  10. Visit all the top-level links in the Toolbar (installed by default in the Standard install profile, e.g.: Content, Structure, Appearance, Extend, Configuration, People, Reports, Help). Note that there are no links to the canonical URL, /admin/dashboard/lorem, nor the Dashboard "entry page" at /admin/dashboard anywhere in the toolbar.

Proposed resolution

At the very least, link each dashboard's label to its canonical URL from the dashboard's row in the entity.dashboard.collection page.

Discuss if we should add a "View" link to the Primary Tabs that will take the user to view the page.

Discuss if we should add a "Dashboards" link to Drupal core's Toolbar that links to /admin/dashboard

Remaining tasks

  1. Write a patch to link the dashboard label to the canonical URL from entity.dashboard.collection
  2. Discuss if we should add a "View" link to the Primary Tabs that will take the user to view the page and update the patch
  3. Discuss if we should add a "Dashboards" link to Drupal core's Toolbar that links to /admin/dashboard and update the patch
  4. Review and feedback
  5. RTBC and feedback
  6. Commit
  7. Release

User interface changes

Link to each dashboard's canonical URL from it's row from the entity.dashboard.collection page.

API changes

None.

Data model changes

None.

Feature request
Status

Active

Version

2.0

Component

Code

Created by

🇨🇦Canada mparker17 UTC-4

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @mparker17
  • 🇨🇦Canada mparker17 UTC-4

    Interesting! After manually flushing caches for the first time, a "Dashboards" link appeared in my Toolbar, so I've deleted that part from the issue summary.

  • Pipeline finished with Success
    10 days ago
    Total: 275s
    #470429
  • 🇨🇦Canada mparker17 UTC-4

    I've made a patch to link the dashboard label to the canonical URL from entity.dashboard.collection.

    Reviews welcome!

    In \Drupal\dashboard\DashboardListBuilder, I was forced to change the name of the label column to link in both DashboardListBuilder::buildHeader() and DashboardListBuilder::buildRow(), because I discovered that \Drupal\Core\Entity\DraggableListBuilderTrait forces a column named label (if it exists) to be plain text with the following code in DraggableListBuilderTrait::buildForm():

          if (isset($row['label'])) {
            $row['label'] = ['#plain_text' => $row['label']];
          }
    
  • 🇨🇦Canada mparker17 UTC-4

    Discuss if we should add a "View" link to the Primary Tabs that will take the user to view the page.

    I'm not sure where this is recorded, but it looks like the "View" link is missing from dashboard.links.task.yml because the page at /admin/dashboard uses the primary links to allow users to switch between the dashboards they are allowed to see — and when you add it, you get tabs for other dashboards and the current dashboard all mixed together, which is confusing, and likely a bad idea.

    Maybe a link from /admin/structure/dashboard is sufficient? But I'd be interested to hear feedback from the maintainers, who have put a lot more thought/work into this module than I have.

  • 🇨🇦Canada mparker17 UTC-4

    Updating the title

  • 🇨🇦Canada mparker17 UTC-4

    I still need to add tests for this change.

  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    🐛 Wrong redirect after Dashboard layout edition Active would definitely help here. Once you save, you are redirected to the dashboard canonical url instead of the listing.

    The toolbar caching is definitely an issue, can you create a separate one? We've been mostly focusing on the new navigation.
    The idea is that the toolbar/new navigation "Dashboard" link gives you the entry point to all the dashboards.

  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    An option could be having on DashboardListBuilder:

      public function buildForm(array $form, FormStateInterface $form_state) {
        $form = parent::buildForm($form, $form_state);
        foreach ($this->entities as $entity) {
          $form[$this->entitiesKey][$entity->id()]['label'] = [
            '#type' => 'link',
            '#title' => $entity->label(),
            '#url' => $entity->toUrl('canonical'),
          ];
        }
        return $form;
      }
    
    
  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺
  • 🇪🇸Spain plopesc Valladolid

    Hi!

    Removing the "View" local task was made on purpose because having the ability to create or edit a dashboard does not give the access to it.
    That's why the "Preview" local task was created, ensuring that users that can create/edit the dashboard can get access to preview, even if they don't have access to it from /admin/dashboard local tasks.

    Regarding the penyaskito's approach, that could be an option, but that link would point to a 404 error if the current user does not have access to the dashboard. We might just only make links to those dashboards the current user has access to, but it could be confusing.

    I don't have a clear answer to this request that would make everybody happy.

  • 🇨🇦Canada mparker17 UTC-4

    @penyaskito, @plopesc, thank you for the quick replies; I apologize for my own delay in getting back to you!

    @penyaskito wrote,

    🐛 Wrong redirect after Dashboard layout edition Active would definitely help here. Once you save, you are redirected to the dashboard canonical url instead of the listing.

    I agree, this would help, as it would have cleared up some of my own misunderstanding while I was testing.

    @penyaskito wrote,

    The toolbar caching is definitely an issue, can you create a separate one?

    Okay! I will edit this message and post a link here when I've done so.

    @penyaskito wrote,

    An option could be having on DashboardListBuilder:

      public function buildForm(array $form, FormStateInterface $form_state) {
        $form = parent::buildForm($form, $form_state);
        foreach ($this->entities as $entity) {
          $form[$this->entitiesKey][$entity->id()]['label'] = [
            '#type' => 'link',
            '#title' => $entity->label(),
            '#url' => $entity->toUrl('canonical'),
          ];
        }
        return $form;
      }
    

    I like this code better; I'll change my merge request shortly!

    I'll reply to @plopesc's message soon.

  • Pipeline finished with Success
    3 days ago
    Total: 239s
    #476122
  • 🇨🇦Canada mparker17 UTC-4

    @plopesc wrote,

    Removing the "View" local task was made on purpose because having the ability to create or edit a dashboard does not give the access to it.
    That's why the "Preview" local task was created, ensuring that users that can create/edit the dashboard can get access to preview, even if they don't have access to it from /admin/dashboard local tasks.

    Regarding the penyaskito's approach, that could be an option, but that link would point to a 404 error if the current user does not have access to the dashboard. We might just only make links to those dashboards the current user has access to, but it could be confusing.

    Interesting... I hadn't considered that specific scenario.

    @penyaskito's buildForm() code alters the table row to add the link... would it be an acceptable compromise to check $entity->toUrl('canonical')->access() before transforming the label into a link, like this...?

    public function buildForm(array $form, FormStateInterface $form_state) {
        $form = parent::buildForm($form, $form_state);
        foreach ($this->entities as $entity) {
          $dashboardUrl = $entity->toUrl('canonical');
          if ($dashboardUrl->access()) {
            $form[$this->entitiesKey][$entity->id()]['label'] = [
              '#type' => 'link',
              '#title' => $entity->label(),
              '#url' => $dashboardUrl,
            ];
          }
        }
        return $form;
      }
    
  • 🇨🇦Canada mparker17 UTC-4

    (moving back to "needs review" to get feedback)

  • 🇪🇸Spain penyaskito Seville 💃, Spain 🇪🇸, UTC+2 🇪🇺

    (We can check in tugboat for this MR: https://mr59-be4pskurppwvqfqo7pjfutudyzyllyze.tugboatqa.com/en/admin/str..., login as admin/admin)

    I think it makes sense to just wrap in a $dashboard->access('view') check.

    It could look weird if you don't have access to a given dashboard that won't be linked, but I guess we can live with that.

    Just found that we don't have any test for the listing, so might be a good opportunity to add one.

Production build 0.71.5 2024