- π±π»Latvia Phonoman
This issue is clearly about altering the Paragraph Summary - aka, the closed "preview" of field values when editing some entity with paragraphs.
#2 is the UI description when checking the paragraph list, not related.
And altering this still seems like a big question mark - there seems to not be a straightforward way of doing this as you would, for example, with preprocessing variables.
There seems to be a preprocess summary method, which you can technically use to change the summary... However, it only contains the text elements and not the entity in question, so you cannot easily append it without fetching the entity from route, then loading/digging however deep you need with tons of if's./** * Prepares variables for. * * Default template: paragraphs-summary.html.twig * * @param array $variables * An associative array containing: * - buttons: An array of buttons to display in the modal form. */ function template_preprocess_paragraphs_summary(&$variables) { $variables['content'] = $variables['element']['#summary']['content']; $variables['behaviors'] = $variables['element']['#summary']['behaviors']; $variables['expanded'] = !empty($variables['element']['#expanded']); }
- π¦πΊAustralia sime Melbourne
Yes, I'm wondering why the paragraphs entity is not attached to the variables that reach the preprocess and twig template.
- π¦πΊAustralia sime Melbourne
I propose that in
ParagraphsSummaryFormatter->viewElements()
, the entity, or the entity ID/Revision is attached to$elements['#attached']
. - π¦πΊAustralia sime Melbourne
Speculative to try it out...
/** * Implements TEMPLATE_preprocess_paragraphs_summary */ function mymodule_preprocess_paragraphs_summary(&$variables) { var_dump($variables['element']['#paragraph']); }
- π¦πΊAustralia sime Melbourne
Using the module paragraph_view_mode.
/** * Implements TEMPLATE_preprocess_paragraphs_summary */ function MYMODULE_preprocess_paragraphs_summary(&$variables) { // Requires https://www.drupal.org/project/paragraphs/issues/3157819#comment-15149289 $paragraph = $variables['element']['#paragraph']; $view_modes = \Drupal::service('entity_display.repository')->getViewModeOptionsByBundle('paragraph', $paragraph->getType()); $view = $paragraph->get('paragraph_view_mode')->value; $variables['content'] = array_merge(['as ' . $view_modes[$view]], $variables['content']); }
- Status changed to Needs review
over 1 year ago 5:52pm 23 October 2023 - last update
over 1 year ago 152 pass, 24 fail - πͺπΈSpain interdruper
Patch for 8.x-1.16 with the approach suggested by @sime in #9 is provided.
- last update
over 1 year ago 152 pass, 24 fail The last submitted patch, 11: add_the_paragraph_to_summary_preprocess_variables-3157819-11.patch, failed testing. View results β
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.- last update
over 1 year ago 160 pass, 14 fail - πͺπΈSpain interdruper
Summary renderization was not covered in all cases in the patch #11. New patch attached.
- last update
over 1 year ago 160 pass, 14 fail The last submitted patch, 13: add_the_paragraph_to_summary_preprocess_variables-3157819-12.patch, failed testing. View results β
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.- Status changed to Needs work
5 months ago 3:11pm 21 September 2024 - π«π·France Grimreaper France π«π·
Hi,
Thanks for the patch comment 13 (and also the work done previously in the issue too!).
Impossible to customize properly paragraphs summary without that.
- Status changed to RTBC
2 months ago 3:52pm 6 December 2024 - πΊπΈUnited States scotwith1t Birmingham, AL
Super helpful stuff, thanks all! +1 and setting to RTBC unless there's some reason it should not be committed...?
- π«π·France luukyb
We're using this too. Would love to see this committed. Thanks!