H5P content lost when collapsing/opening in Paragraphs

Created on 16 February 2018, almost 7 years ago
Updated 4 December 2023, 12 months ago

Drupal 8.4.4
PHP 5.6.32

I noticed an issue with HP5 content and Paragraphs, when collapsing en re-opening H5P content in an edit form, H5P content is lost.

  • Add a paragraph to a content type.
  • Set Manage Form Display to complex (experimental), so you are able to collapse the paragraphs in the form.
  • Add a field to your paragraph entity for HP5 content.
  • Create a node with HP5 content (in a parapraph), eg. HP5 multiple choise widget
  • Try collapsing and re-opening the H5P Paragraph
  • H5P content is not preserved and lost when the form changes

I thought it was an issue in Paragraphs, but saw a similar case with inline entity forms.

🐛 Bug report
Status

Active

Component

Code

Created by

🇧🇪Belgium yazzbe

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

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇩🇪Germany snitch182 Hannover

    Hello,
    This still happens in Drupal 9. Any recommendations ? So far one can work "around" this with saving the whole page once you openend a h5p part. Once you unfold another part the h5p is "emptied".

  • 🇫🇮Finland jhuhta

    I just wanted to point out that there's a similar issue with a patch: 🐛 Paragraphs module compatibility Needs review . Maybe one of these could be closed as duplicate?

    The data is not lost only when opening/closing paragraphs, but also when adding/deleting unrelated paragraph types from the entity.

  • 🇺🇸United States partdigital

    I also ran into this issue when expanding/collapsing paragraphs:

    • Drupal Core: 10.1.6
    • Paragraphs: 1.16
    • H5P: 2.0.x

    It seems to be caused by the submitted form values not being properly formatted upon Expand/Collapse. A quick fix for this was to simply remove some code in H5PWidgetBase::massageFormValues.

    public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    
       // Remove this condition.
       if (!$form_state->isValidationComplete()) {
          return $values;
        }
    
        // ... Code removed for brevity ...
    
        // The condition is preventing this method from running which properly formats the code. 
          $return_values[$delta] = $this->massageFormValue($value['h5p_content'], $delta, $do_new_revision);
        }
    
        return $return_values;
    }
    

    I've attached a patch for this however since it's removing some code there is the possibility of introducing a regression. It could definitely use some extra review/testing.

Production build 0.71.5 2024