- 🇮🇳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'; } }
- Status changed to Needs review
8 months ago 10:42am 31 May 2024 - Status changed to RTBC
5 months ago 5:17pm 11 September 2024 - 🇮🇳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.