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
Comment #2
realityloop commentedComment #3
realityloop commentedUsing 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
Comment #4
berdirWe 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.
Comment #5
realityloop commentedVideo demonstrating issue.
Comment #6
a-fro commentedI'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
$formargument in WidgetBase$values = $this->massageFormValues($values, $form, $form_state);is as follows:However, if I choose my custom block with the paragraphs field as the entity type, I get the following $form:
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
Comment #7
oknateI 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.
Comment #8
oknateI'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.
Comment #9
miro_dietikerIf we need IEF specific tweaks in paragraphs, we need test coverage.
First pushing to needs-review to see if this already breaks existing tests.
Comment #11
johnchqueBug fixes need to go in both widgets.
Comment #12
oknateI 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.