Save entity variable in a Loop through a view result variable saves only 1 entity

Created on 27 March 2019, over 5 years ago
Updated 17 February 2023, almost 2 years ago

Hi,
Issue: Save entity variable in a Loop through a view result variable saves only 1 entity
The first loop goes ok, the second loop re-saves the first entity with new values.

So my issue is when you have a save entity variable action on a loop it's saving the same entity instead of creating a new entity. I believe it has something to do with the uuid.

Also receive an warning when you loop:

Warning: array_flip(): Can only flip STRING and INTEGER values! in Drupal\Core\Entity\EntityStorageBase->loadMultiple() (line 264 of core/lib/Drupal/Core/Entity/EntityStorageBase.php).
Drupal\Core\Entity\EntityStorageBase->loadMultiple(Array) (Line: 249)
Drupal\Core\Entity\EntityStorageBase->load(NULL) (Line: 527)
Drupal\Core\Entity\Entity::load(NULL) (Line: 643)
Drupal\business_rules\Util\BusinessRulesProcessor->evaluateVariables(Object, Object) (Line: 473)
Drupal\business_rules\Util\BusinessRulesProcessor->executeAction(Object, Object) (Line: 316)
Drupal\business_rules\Util\BusinessRulesProcessor->processItems(Array, Object, 'entity_insert_ato') (Line: 261)
Drupal\business_rules\Util\BusinessRulesProcessor->processTriggeredRules(Array, Object) (Line: 168)
Drupal\business_rules\Util\BusinessRulesProcessor->process(Object) (Line: 136)
Drupal\business_rules\EventSubscriber\BusinessRulesListener->process(Object, 'business_rules.entity_insert', Object)
call_user_func(Array, Object, 'business_rules.entity_insert', Object) (Line: 111)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch('business_rules.entity_insert', Object) (Line: 115)
business_rules_entity_insert(Object)
call_user_func_array('business_rules_entity_insert', Array) (Line: 403)
πŸ› Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

πŸ‡¬πŸ‡§United Kingdom lexsoft00

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΈπŸ‡°Slovakia coaston

    Hi djween,

    I tried to replicate your case #27 due to learning process, however I am getting following issue once I want to create a new node with User Agenda Parent

    Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'title' cannot be null: INSERT INTO "node_field_data" ("nid", "vid", "type", "langcode", "status", "uid", "title", "created", "changed", "promote", "sticky", "default_langcode", "revision_translation_affected") VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12); Array ( [:db_insert_placeholder_0] => 157630 [:db_insert_placeholder_1] => 219667 [:db_insert_placeholder_2] => user_agenda_children [:db_insert_placeholder_3] => en [:db_insert_placeholder_4] => 1 [:db_insert_placeholder_5] => 3 [:db_insert_placeholder_6] => [:db_insert_placeholder_7] => 1676649418 [:db_insert_placeholder_8] => 1676649418 [:db_insert_placeholder_9] => 0 [:db_insert_placeholder_10] => 0 [:db_insert_placeholder_11] => 1 [:db_insert_placeholder_12] => 1 ) in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 811 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).

    I am not sure why the title is null - i have configured "set values to entity variable action" with {{setup_a_view_results_variable_->title}}

    Also I am not sure about contextual filter , have you configured "provide the default value" ??

  • πŸ‡ΊπŸ‡ΈUnited States djween

    @coaston
    --First check your view outside of business rules. As in create a page from your view and make sure there are actual results.
    --yes, in my case I have provided default value in the contextual filter. I am using "content id from url" in my particular case to filter the view.
    --And in BR in the views variable, for the argument I have: [node:nid].
    --Also make sure you have patch #9 installed.

Production build 0.71.5 2024