Auto-save function if field has value on new content/node creation

Created on 1 August 2023, over 1 year ago
Updated 2 April 2024, 9 months ago

I want a node to be saved if a field has a value. The use case is to collect feedback for a charity. The content type has only 2 fields.

  • title: is hidden and is auto generated using current time and a random string
  • field_feedback: is a select list of 5 items - Excellent, Good, Fair, Poor, Very Poor

ECA 1:
'initialize content entity' - field_feedback is empty (not/negated)- save content

nothing happens and when save button clicked, get a error message as below

The website encountered an unexpected error. Please try again later.

Drupal\Core\Entity\EntityStorageException: Update existing 'node' entity while changing the ID is not supported. in Drupal\Core\Entity\Sql\SqlContentEntityStorage->save() (line 817 of core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php).
Drupal\Core\Entity\EntityStorageBase->save(Object) (Line: 806)
Drupal\Core\Entity\Sql\SqlContentEntityStorage->save(Object) (Line: 339)
Drupal\Core\Entity\EntityBase->save() (Line: 270)
Drupal\node\NodeForm->save(Array, Object)
call_user_func_array(Array, Array) (Line: 114)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 52)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 597)
Drupal\Core\Form\FormBuilder->processForm('node_feedback_on_a_node_form', Array, Object) (Line: 325)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 73)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 583)
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: 166)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 74)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
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: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 51)
Drupal\Core\StackMiddleware\StackedHttpKernel->handle(Object, 1, 1) (Line: 704)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

ECA 2:
'presave content entity' - field_feedback is empty (not/negated)- save content

nothing happens

What should be the opening step? I have tried with 'initialize content entity bundle' and 'presave content' as above without success

💬 Support request
Status

Closed: outdated

Version

1.1

Component

Miscellaneous

Created by

🇦🇫Afghanistan lovedrupal6

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

Comments & Activities

  • Issue created by @lovedrupal6
  • Status changed to Postponed: needs info over 1 year ago
  • 🇩🇪Germany jurgenhaas Gottmadingen

    Not exactly sure what and how you would like to lay out your workflow here. Is this about a form, that the user fills in and then hits "Save" or "Submit"? In those cases, you're most likely interested in form submit or form validation events. If not, could you please describe, in more detail, how the flow should be?

    To learn more about forms in ECA, please have a look here: https://ecaguide.org/plugins/eca/form/#usage

  • 🇦🇫Afghanistan lovedrupal6

    Apologies for the delay in replying. Dont think I am any closer to getting this working.

    The purpose of the page is to collect feedback (airport/superstore style with 5 images depicting a likert scale from Excellent, Good, Fair, Poor, Very Poor. Completing the form is to be as quick as possible.

    Have a webform with a image select field of 5 images. Want the webform to be saved/submitted as soon as an option is selected without the need to hit save/submit button.

    Intent to have the webpage with this form themed with only the image select options displayed similar to https://techcrunch.com/wp-content/uploads/2019/09/HappyOrNot-3.png?w=139.... The user filling this will only need to make a selection and the webform should then be saved/submitted. The page then reloads itself with a new form and this function is available within webform itself.

    Have tried with 'presave content entity' and 'initialize content entity' as the starting point.

  • 🇩🇪Germany jurgenhaas Gottmadingen

    Well, ECA is a processor in the backend of your Drupal site. What you're trying to do is some automation in the browser, i.e. in the frontend. That's not something that ECA was build for. You would have to find something which reacts in the browser to one of the options being selected and submitting that form by some javascript in the browser.

    ECA can react upon events in the backend, but selecting an option ion the webform does not trigger any event. That's why ECA can't do anything about that.

  • Status changed to Closed: outdated 9 months ago
  • 🇩🇪Germany jurgenhaas Gottmadingen
Production build 0.71.5 2024