Implement Contextual Links for Paragraphs

Created on 13 November 2023, 8 months ago
Updated 7 May 2024, about 2 months ago

Problem/Motivation

Users are often confused to find the right parent entity to edit a specific paragraph.

Steps to reproduce

Proposed resolution

Add contextual links using the parent entity. We could do this in PHP or Twig.

I've already tested this in Twig, and it seems to work very well so far:

Add wrapper class:

user.hasPermission('access content overview') ? 'contextual-region'

Inside the paragraph wrapper:

{% if view_mode != "preview" %}
        {% if user.hasPermission('access content overview') %}
          {% set parentEntity = paragraph.getParentEntity() %}
          {% if parentEntity %}
            {% set parentEntityId = parentEntity.id() %}
            {% set parentEntityBundle = parentEntity.bundle() %}
            {% set parentEntityTypeId = parentEntity.entityTypeId() %}
            {% if parentEntityId and parentEntityBundle and parentEntityTypeId %}
              {{ drupal_contextual_links(parentEntityTypeId ~ ':' ~ parentEntityTypeId ~ '=' ~ parentEntityId ~ ':') }}
            {% endif %}
          {% endif %}
        {% endif %}
      {% endif %}

Remaining tasks

  1. Check if there's a better permission to check
  2. PHP or Twig? => https://www.drupal.org/docs/drupal-apis/menu-api/providing-module-define... β†’
  3. Can we add paragraph.id() as anchor fragment to the contextual link? See: https://drupal.stackexchange.com/questions/273501/how-do-i-add-an-anchor...
  4. (Add further Contextual link icons for views & blocks in our DROWL base theme)

User interface changes

API changes

Data model changes

✨ Feature request
Status

Active

Version

1.0

Component

Code

Created by

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

Comments & Activities

Production build 0.69.0 2024