Hi,
While saving a new node , I am getting the error below:

Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 227 of core\lib\Drupal\Core\Entity\EntityStorageBase.php)

Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array) (Line: 212)
Drupal\Core\Entity\EntityStorageBase->load() (Line: 524)
Drupal\Core\Entity\Entity::load() (Line: 126)
Drupal\workflow_moderation\ModerationInformation->isPublishedState() (Line: 70)
Drupal\workflow_moderation\EntityOperations->entityPresave(Object) (Line: 17)
workflow_moderation_entity_presave(Object)
call_user_func_array('workflow_moderation_entity_presave', Array) (Line: 402)
Drupal\Core\Extension\ModuleHandler->invokeAll('entity_presave', Array) (Line: 169)
Drupal\Core\Entity\EntityStorageBase->invokeHook('presave', Object) (Line: 730)
Drupal\Core\Entity\ContentEntityStorageBase->invokeHook('presave', Object) (Line: 435)
Drupal\Core\Entity\EntityStorageBase->doPreSave(Object) (Line: 587)
Drupal\Core\Entity\ContentEntityStorageBase->doPreSave(Object) (Line: 389)
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 820)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 387)
Drupal\Core\Entity\Entity->save() (Line: 281)
Drupal\node\NodeForm->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: 585)
Drupal\Core\Form\FormBuilder->processForm('node_article_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm('node_article_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: 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: 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: 664)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I was looking for the reason and it seems in "getPerviousStateId" function, when is a new node, is not returning a value, because there is not transition history for new nodes.

Comments

noelia_11 created an issue. See original summary.

noelia_11’s picture

Title: Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 230 of core\lib\Drupal\Core\Entity\EntityStorageBase.php) » Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 227 of core\lib\Drupal\Core\Entity\EntityStorageBase.php)
Issue summary: View changes
punamshelke’s picture

Hi noelia_11,

Can provide details for issue?

bala.addweb’s picture

Status: Active » Needs review

@noelia_11, You just need to change the code

$passed_ids = !empty($ids)  ? array_flip($ids) : FALSE;  
to 
$passed_ids = !empty($ids) && is_array($ids) ? array_flip($ids) : FALSE;

on line 227
It occurs because you use Entity in your custom code and pass a string to it. Hope this helps you
Thanks.

singhrt’s picture

It's not working anymore with drupal 8.8.3.