When i try to save a child entity with a set weight, the function loadSiblingEntityWeights() generates the following warning:
Warning: array_combine(): Both parameters should have an equal number of elements in Drupal\entity_hierarchy\Plugin\Field\FieldType\EntityReferenceHierarchy->loadSiblingEntityWeights() (line 250 of modules/contrib/entity_hierarchy/src/Plugin/Field/FieldType/EntityReferenceHierarchy.php).
Drupal\entity_hierarchy\Plugin\Field\FieldType\EntityReferenceHierarchy->loadSiblingEntityWeights(Array) (Line: 283)
Drupal\entity_hierarchy\Plugin\Field\FieldType\EntityReferenceHierarchy->getSiblingEntityWeights(Object, Object, Object) (Line: 166)
Drupal\entity_hierarchy\Plugin\Field\FieldType\EntityReferenceHierarchy->postSave(1)
call_user_func_array(Array, Array) (Line: 233)
Drupal\Core\Field\FieldItemList->delegateMethod('postSave', 1) (Line: 198)
Drupal\Core\Field\FieldItemList->postSave(1) (Line: 33)
Drupal\entity_hierarchy\Plugin\Field\FieldType\EntityReferenceHierarchyFieldItemList->postSave(1)
call_user_func_array(Array, Array) (Line: 873)
Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldMethod('postSave', Object, 1) (Line: 905)
Drupal\Core\Entity\ContentEntityStorageBase->invokeFieldPostSave(Object, 1) (Line: 831)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('update', Object) (Line: 526)
Drupal\Core\Entity\EntityStorageBase->doPostSave(Object, 1) (Line: 720)
Drupal\Core\Entity\ContentEntityStorageBase->doPostSave(Object, 1) (Line: 451)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 838)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 394)
Drupal\Core\Entity\EntityBase->save() (Line: 71)
Drupal\sapros_filter\Form\FilterAttributeForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 111)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 590)
Drupal\Core\Form\FormBuilder->processForm('sapros_filter_attribute_edit_form', Array, Object) (Line: 319)
Drupal\Core\Form\FormBuilder->buildForm('sapros_filter_attribute_edit_form', Object) (Line: 93)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 582)
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}() (Line: 151)
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: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 693)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
In my opinion the problem can be fixed by changing $parentField . '_weight' to $parentField . '__weight'
Comments
Comment #2
megadesk3000 commentedComment #3
megadesk3000 commentedComment #5
larowlanI think I've seen this before too.
I think it might be that core generates these names randomly, we might need a more robust way of doing it
Comment #6
larowlanComment #7
nanakThe separator being incorrect depends of the type of field you use. If you add it through the UI, as FieldConfig, the separator will be the one expected by the code, a single underscore. But if you create it as a BaseFieldDefinition, then the separator becomes a double underscore, because it's a compound field.
Attached, a patch that uses "__" or "_" depending on the type of field.
Comment #8
larowlanGreat find @nanak
Here's a failing test to verify that base fields are indeed the issue.
Comment #11
larowlanThanks, this will go out as 3.0.1
Comment #13
larowlanThis went out as 3.0.1 and 8.x-2.27
Thanks