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

megadesk3000 created an issue. See original summary.

megadesk3000’s picture

megadesk3000’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: fix-wrong-weight-column-name-in-3067304-2.patch, failed testing. View results

larowlan’s picture

I 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

larowlan’s picture

nanak’s picture

Version: 8.x-2.6 » 8.x-2.x-dev
Status: Needs work » Needs review
Issue tags: -Needs steps to reproduce
StatusFileSize
new1.17 KB

The 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.

larowlan’s picture

StatusFileSize
new2.15 KB
new3.31 KB

Great find @nanak

Here's a failing test to verify that base fields are indeed the issue.

The last submitted patch, 8: 3067304-8-fail.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • larowlan committed 053d9bc on 3.x
    Issue #3067304 by larowlan, megadesk3000, nanak: Try to access $...
larowlan’s picture

Status: Needs review » Fixed

Thanks, this will go out as 3.0.1

  • larowlan committed c1d464b on 8.x-2.x
    Issue #3067304 by larowlan, megadesk3000, nanak: Try to access $...
larowlan’s picture

This went out as 3.0.1 and 8.x-2.27

Thanks

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.