Breaks layout paragraphs editing functions

Created on 28 November 2023, about 1 year ago
Updated 30 May 2024, 8 months ago

Problem/Motivation

When this module is installed alongside Layout Paragraphs, the editing controls of layout paragraphs do not render because this module changes the id in the code

function ptoc_preprocess_paragraph(&$variables) {
  if ('default' == $variables['elements']['#view_mode']) {
    $variables['attributes']['id'] = 'paragraph-' . $variables['paragraph']->id();
  }...
}

Steps to reproduce

Install both modules and create a content type which uses layout paragraphs on a field. When editing the the controls will not render.

🐛 Bug report
Status

Active

Version

1.2

Component

Code

Created by

🇬🇧United Kingdom ded

Live updates comments and jobs are added and updated live.
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.

  • 🇮🇳India santhosh@21

    The same issue I got when using Layout Paragraphs and Paragraphs module as the preprocess paragraph is changing the default id values to "pargraph-id" and it is affecting the Layout Paragraphs and losing the editing controls of layout paragraphs.

    The below code fixed the issue for Layout editing

    Also Attached the patch for someone who is looking for

    function ptoc_preprocess_paragraph(&$variables) {
      // Check if the ID attribute is already set.
      if (!isset($variables['attributes']['id'])) {
        // Generate a new ID only for paragraphs in the default view mode.
        if ('default' == $variables['elements']['#view_mode']) {
          $variables['attributes']['id'] = 'paragraph-' . $variables['paragraph']->id();
        }
      }
     
      if (Drupal::config('ptoc.settings')->get('debug')) {
        $variables['attributes']['class'][] = 'ptoc-debug';
        $variables['#attached']['library'][] = 'ptoc/ptoc-debug';
      }
    }
    
    
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to Needs review 8 months ago
  • 🇮🇹Italy apaderno Brescia, 🇮🇹
  • Status changed to RTBC 5 months ago
  • 🇮🇳India rifas-ali-pbi Kerala

    I have tested this patch. After applying this patch now Paragraph is working fine.

  • First commit to issue fork.
  • 🇺🇸United States benjifisher Boston area

    Thanks to all for reporting this problem and proposing a fix.

    Unfortunately, the patch in Comment #2 conflicts with the latest changes on the dev branch, from 🐛 Extra, unnecessary anchor links in ToC Fixed . I added a MR with a slightly different approach:

    function ptoc_preprocess_paragraph(&$variables) {
      // Generate an id attribute for paragraphs in the default view mode unless
      // they already have one.
      if ($variables['elements']['#view_mode'] === 'default') {
        $variables['attributes']['id'] ??= 'paragraph-' . $variables['paragraph']->id();
      }
      // ...
    }
    

    I replaced the "Yoda conditional" and, instead of explicitly testing isset(), I used the null coalescing assignment operator ??=.

    I tested that this change does not break anything, but I did not test that it fixes the problem with Layout Paragraphs. I think that module needs some configuration, and the "steps to reproduce" in the issue summary are not explicit enough for me. So back to NR.

    If you prefer to work with a patch instead of a merge request, then you can use the plain diff link just above the comments section.

Production build 0.71.5 2024