Views block duplicated contextual links

Created on 9 June 2017, almost 8 years ago
Updated 30 January 2023, over 2 years ago

Problem

When views are added as blocks the contextual link doesn't work as expected. The block outputs two contextual links with the same ID which causes some issues with the way that Backbone binds and creates the event handlers. Reviewing the event handlers in the inspect you can see that the element has 2 click handlers which triggers openToggle twice (once opening and once closing) which causes the contextual button to never show the menu.

Steps to reproduce

- Create a view as a block
- Add the block to the page (tested with Panels and with the default Block UI)
- View source for the page and you will see the duplicated contextual block

Proposed resolution

  • Move adding the contextual links to DisplayPluginBase
  • Remove adding the contextual links to the View element and the view block
  • Update contextual.js to filter the list of IDs so that it doesn't try to bind to the same element (ids should be unique on the page)

Remaining tasks

Testing and review the proposed fix.

Debugging notes

While debugging this I found

  • views adds contextual links in two places; \Drupal\views\Plugin\Block\ViewBlockBase and \Drupal\views\Element\View
  • Disabling the contextual link for the view block removes both instances of the link (on the block and the view)
  • Tracking a static for a given contextual ID in the views_add_contextual_links function didn't prevent it from duplicating
  • Seems to not be related to theme implementations (tried with Cog, Bootstrap, Bartik and all had the same issue)
  • Tested with both Block UI and Panels
  • Exposed form blocks still display contextual link after the proposed fix is applied
πŸ› Bug report
Status

Needs work

Version

10.1 ✨

Component
ViewsΒ  β†’

Last updated about 3 hours ago

Created by

πŸ‡¦πŸ‡ΊAustralia steveworley

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • The Needs Review Queue Bot β†’ tested this issue. It either no longer applies to Drupal core, or fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

    Apart from a re-roll or rebase, this issue may need more work to address feedback in the issue or MR comments. To progress an issue, incorporate this feedback as part of the process of updating the issue. This helps other contributors to know what is outstanding.

    Consult the Drupal Contributor Guide β†’ to find step-by-step guides for working with issues.

  • First commit to issue fork.
  • Merge request !10887Apply patch 18 β†’ (Open) created by mortona2k
  • Pipeline finished with Failed
    4 months ago
    Total: 112s
    #393893
  • πŸ‡ΊπŸ‡ΈUnited States mortona2k Seattle

    I created an issue fork and added the patch.

    I am testing by placing the recent content block via block UI.

    What I'm seeing is duplicate contextual links for the block and for the view itself.

    The only duplicated link is edit view, which is the only one on the view links.

    I have any issues with opening the contextual links when the block title is visible.

    If the block title is hidden, the view links overlap the block links.

Production build 0.71.5 2024