I have a paragraph type for adding a video (which is a referenced media entity added via a modal popup, allowing select from existing video or create new), when you are creating a new video there are also paragraphs as a field on the media entity, when I try to save I get the following error.

Fatal error: Call to undefined method Drupal\entity_browser\Form\EntityBrowserForm::getEntity() in /var/beetbox/docroot/modules/contrib/paragraphs/src/Plugin/Field/FieldWidget/InlineParagraphsWidget.php on line 1236

If I delete the paragraph field on the media entity the erro goes away.

The code in question is the following line in the code below:
$entity = $form_state->getFormObject()->getEntity();

  /**
   * {@inheritdoc}
   */
  public function massageFormValues(array $values, array $form, FormStateInterface $form_state) {
    $entity = $form_state->getFormObject()->getEntity();
    $field_name = $this->fieldDefinition->getName();
    $widget_state = static::getWidgetState($form['#parents'], $field_name, $form_state);
    $element = NestedArray::getValue($form_state->getCompleteForm(), $widget_state['array_parents']);

Comments

realityloop created an issue. See original summary.

realityloop’s picture

Issue summary: View changes
realityloop’s picture

Using xdebug to step through I never end up getting a result for the getEntity call when adding the media entity in the modal (Entity Browser), but it does when I add a Video via /media/add

berdir’s picture

We need the host entity for a number of things, that not existing is going to be a problem. We can easily add an interface check to make sure that we don' t fatal if the method doesn't exists but I'm not sure what should happen then.

realityloop’s picture

StatusFileSize
new9.28 MB

Video demonstrating issue.

a-fro’s picture

I'm running into the same issue. In my case, I've created a custom block that includes a paragraphs field, which I'm trying to integrate with an entity embed button configured to use an entity browser. I can get the interface to work if I choose Paragraph as the entity type in the entity browser entity form interface. In that case, the $form argument in WidgetBase $values = $this->massageFormValues($values, $form, $form_state); is as follows:

  '#type' => string 'inline_entity_form' (length=18)
  '#op' => string 'add' (length=3)
  '#entity_type' => string 'paragraph' (length=9)
  '#bundle' => string 'blockquote' (length=10)
  '#form_mode' => string 'default' (length=7)
  ...

However, if I choose my custom block with the paragraphs field as the entity type, I get the following $form:

  '#type' => string 'container' (length=9)
  '#parents' => 
    array (size=4)
      0 => string 'inline_entity_form' (length=18)
      1 => string 'field_block_paragraph' (length=21)
      2 => int 0
      3 => string 'subform' (length=7)
      ...

It would be possible to use paragraphs as the target entity type if the user were able to choose the paragraph type they want to add from the interface. The current entity browser entity form only allows choosing a single paragraph type, however, which would require a different button for each paragraph type.

It's not clear to me how to resolve this at this time, but if I can dig in deeper, I'll try to create a patch.

This may be a related issue

oknate’s picture

I have encountered this error as well. When you use an entity browser loading an inline_entity_form, the call to $form_state->getFormObject() returns the entity browser, not the nested form. I see that in the dev version the call to getEntity has been removed. The bug there isn't fixed either though, because it fails to set the language properly on the paragraph and then the write to database fails.

This patch is for the 8.1 version and fixes my specific use case. I think the real solution needs to be before this when we are dealing with the paragraphs and the entity together.

oknate’s picture

I'm adding a new version of the patch that fixes this bug when using an inline entity from in the entity browser with nested paragraphs.

miro_dietiker’s picture

Status: Active » Needs review

If we need IEF specific tweaks in paragraphs, we need test coverage.

First pushing to needs-review to see if this already breaks existing tests.

Status: Needs review » Needs work
johnchque’s picture

Bug fixes need to go in both widgets.

oknate’s picture

I tried to rework my patch for the 8.x-dev branch, but the code has changed quite a bit.

This issue was resolved for me in the 8.x-dev branch, but I was getting a new error, so I created a separate issue for it.