Preview cannot display preprocessed nested paragraph type. The target_id is empty.

Created on 18 June 2024, 6 months ago
Updated 20 June 2024, 6 months ago

Problem/Motivation

When clicking "Save" in Mercury Editor, if a Paragraph type has a field which references another Paragraph type, the .theme preprocess function is not able to access the the Target IDs contained within the field. This causes the Mercury editor preview to fail to render the Paragraph type content.

Steps to reproduce

1.
Create a Paragraph type, "testing".
In this PT, create a field, ex: "field_paragraphs".
Have "field_paragraphs" reference another Paragraph Type:

  • Entity reference revisions
  • Reference type: Paragraph

2.
In your .theme file, create a paragraph preprocess function. Within this function, attempt to get the target IDs of the "field_paragraphs" field:

function my_theme_preprocess_paragraph(&$variables) {
  $paragraph = $variables['paragraph'];
  $paragraph_type = $paragraph->bundle();
  $field_paragraphs = $paragraph->get('field_paragraphs')->getValue();
      
  foreach ($field_paragraphs as $key=>$field_paragraph) {
    $field_paragraph_data[$key] = $field_paragraph['target_id'];
  }
  $variables['field_paragraph_data'] = implode(" ", $field_paragraph_data);

Have your template reference the data, ex: {{ field_paragraph_data }}
3.
Using Mercury Editor, create a new "testing" paragraph type.
Fill its 'field_paragraphs' sub-fields with several values.
Upon saving, the Mercury Editor preview page will not display the values.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Closed: works as designed

Version

2.1

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jim_b

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

Comments & Activities

  • Issue created by @jim_b
  • πŸ‡ΊπŸ‡ΈUnited States jim_b
  • πŸ‡ΊπŸ‡ΈUnited States jim_b
  • Status changed to Closed: works as designed 6 months ago
  • πŸ‡ΊπŸ‡ΈUnited States justin2pin

    @jim_b Assuming by "Upon saving" you mean "Upon saving the 'testing' paragraph by clicking the save button in the dialog", the issue is that the nested paragraphs don't have a target ID yet. They won't acquire an ID until you save the entity by clicking save in the top right.

    I'm going to close this, but please reopen if I am misunderstanding.

Production build 0.71.5 2024