- 🇱🇻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
about 1 year ago 5:52pm 23 October 2023 - last update
about 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
about 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
about 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
about 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
2 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.