Problem/Motivation
When the the map field widget is added to a paragraph entity as well as the address field, the widget is still looking for the address in the global form that the paragraph is embedded in, resulting in missing address field, as well as the following notice messages during submission.
Notice: Undefined index: #parents in Drupal\Core\Form\FormState->getError() (line 1112 of core/lib/Drupal/Core/Form/FormState.php).
Drupal\Core\Form\FormState->getError(Array) (Line: 160)
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object, Array) (Line: 120)
Drupal\Core\Form\FormErrorHandler->setElementErrorsFromFormState(Array, Object) (Line: 23)
Drupal\Core\Form\FormErrorHandler->handleFormErrors(Array, Object) (Line: 202)
Drupal\Core\Form\FormValidator->finalizeValidation(Array, Object, 'node_membership_form') (Line: 120)
Drupal\Core\Form\FormValidator->validateForm('node_membership_form', Array, Object) (Line: 571)
Drupal\Core\Form\FormBuilder->processForm('node_membership_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('node_membership_form', Object) (Line: 48)
Drupal\Core\Entity\EntityFormBuilder->getForm(Object) (Line: 113)
Drupal\node\Controller\NodeController->add(Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 576)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}()
call_user_func_array(Object, Array) (Line: 153)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 68)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 99)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 78)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 657)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Proposed resolution
Have the widget search for address field in the same entity form element.
For example:
1. If both are fields on the entity - work directly there. (curently works)
2. If both are fields on a sub entity (paragraph) - look in the sub-form for that entity for the address field. (currently breaks)
Open questions are still how to handle cross entity selection.
An option is to change the widget settings to point to the full name of the address element, so it can be anywhere in the form. This will have a complex upgrade path...
This can be achieved through the #array_parents and some management there.
Remaining tasks
Patch - coming shortly. I have a working solution locally.
Reviews...
Commit...
User interface changes
None.
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | 2936734-undefined-index-parents-in-paragraph-6.patch | 6.26 KB | itamair |
Comments
Comment #2
ndobromirov commentedHere is a patch that will find the address element based on the parents structure of the map field, so they should share an entity.
Removed an explicit type cast to string on 2 description texts, as this will cause rendering in a much sooner than needed context.
Added a check that will use the address field only if it is really found in the form, not only configured in the widget.
Comment #3
itamair commentedtnx @ndobromirov ... will review Asap
Comment #4
ndobromirov commentedThere is a small typo in the patch. Posting a new one in a bit...
Comment #5
ndobromirov commentedI've missed to add to the patch the management to the
$address_field_existsflag and so it will never enter in the condition, causing a regression.This is now fixed. Here is a new patch + a diff for the change.
Comment #6
itamair commentedHi @ndobromirov ... thanks for highlighting this specific use case, and providing an inspiration patch.
I reviewed it extensively and discovered that your patch was introducing some regressions in the module:
- the Geoaddress Field elements '#description' were lost;
- the Geoaddress Field elements hidden and readonly functionalities/options were lost;
- your solution was working but just if you had your paragraph entity_reference geofield as the unique one attached to the entity;
Also I noticed that for the paragraph entity some options should be filtered from the Geoaddress Field select.
Here is another patch that amends your last one. Al this applies at 8.x-1.29.
Please review ... then I will commit to a new dev and stable release.
Comment #7
itamair commentedComment #8
itamair commentedComment #10
itamair commentedRun some tests on this, and everything seems working great.
Commited to dev and into new release 8.x-1.30
Comment #11
itamair commented