Problem/Motivation

When editing a Workflow which has been created with either no states or no transitions (or both)) an Invalid argument error will be displayed.

No states: Warning: Invalid argument supplied for foreach() in Drupal\workflows\Form\WorkflowEditForm->copyFormValuesToEntity() (line 276 of core/modules/workflows/src/Form/WorkflowEditForm.php).

No transitions: Warning: Invalid argument supplied for foreach() in Drupal\workflows\Form\WorkflowEditForm->copyFormValuesToEntity() (line 279 of core/modules/workflows/src/Form/WorkflowEditForm.php).

This will only occur in rare cases where the Workflow Plugin does no provide any required states and when creating the Workflow the user chooses not to create the initial state when prompted. In this scenario it appears that in some cases $form_state->getValues() may not contain the states or transitions keys, which results in the errors being shown.

Tested using the Workflows Field contrib module, which provides a plugin with no required states.

Currently this does not appear to be reliably reproducible, no other information is currently available which would indicate why this is not reliably reproducible.

Proposed resolution

Remaining tasks

Determine if code should be refactored to prevent the errors from being triggered, or wait until this can be more reliably reproduced.

User interface changes

API changes

Data model changes

Issue fork drupal-2899872

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Sam152 created an issue. See original summary.

sam152’s picture

Status: Active » Needs review
StatusFileSize
new957 bytes
sam152’s picture

Issue tags: +Novice, +Needs tests
sam152’s picture

Status: Needs review » Needs work
scott_euser’s picture

I couldn't see how to reproduce this in order to add a test for it. Steps I followed:

  1. Enable content moderation
  2. Delete all transitions from that workflow
  3. Apply the workflow to basic page
  4. Create a basic page, save
  5. Edit that basic page, save
  6. Error message shown 'Invalid state transition from Draft to Draft'

Doesn't that mean transitions are essentially required in practice?

sam152’s picture

Status: Needs work » Closed (cannot reproduce)

Perhaps you're right, the key would have to be missing from configuration to trigger this, instead of set to an empty array like your testing in #5 suggests.

I think this is fine to close.

aaronmchale’s picture

Title: Undefined index in \Drupal\workflows\Form\WorkflowEditForm::copyFormValuesToEntity » Invalid argument error when editing a workflow which was created with no states and/or transitions
Version: 8.5.x-dev » 8.8.x-dev
Issue summary: View changes

Updating this issue with more details as I did come across this but was only able to reproduce it a couple of times, now it no longer appears to be reproducible, will update again if I can reproduce this reliably.

spokje’s picture

Assigned: Unassigned » spokje
Status: Closed (cannot reproduce) » Needs work

I can reproduce it when saving a workflow which has states, but no transitions on Drupal 9.2.1 . Will circle back later to make a failing test for this.

spokje’s picture

Version: 8.8.x-dev » 9.3.x-dev
dhirendra.mishra’s picture

StatusFileSize
new963 bytes

Here re-rolled patches against 9.3.x

spokje’s picture

Issue tags: +Bug Smash Initiative
StatusFileSize
new916 bytes
spokje’s picture

Assigned: spokje » Unassigned
Status: Needs work » Needs review

Newly created MR has patches 2899872-10.patch and 2899872-test_only_should_fail.patch combined.

spokje’s picture

Issue tags: -Needs tests

Status: Needs review » Needs work

The last submitted patch, 11: 2899872-test_only_should_fail.patch, failed testing. View results

spokje’s picture

Status: Needs work » Needs review

Fail was expected (since it was a test_only_should_fail.patch), let's see if the MR makes TestBot happy

spokje’s picture

All green :)

spokje’s picture

- Rebased MR on 9.4.x-dev
- Merged latest commits

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

smustgrave’s picture

Status: Needs review » Needs work

before testing can you update the MR to point to 9.5.x or rebase it? Currently it's saying it's not mergable.

One reason I don't like the MR. Could be easily fixed via patches but MR no one can edit them just push code.

spokje’s picture

Status: Needs work » Needs review

One reason I don't like the MR. Could be easily fixed via patches but MR no one can edit them just push code.

You can't always get what you want
(But if you try sometime you'll find
You get what you need)

Anyway: Added a 9.5.x MR and made the 9.4.x more up-to-date.
I like MRs, one reason: The pretty colors when showing the changes. :)

smustgrave’s picture

Tried testing the issue before the patch

Created a new workflow which came with draft and published states and some transitions
Manually deleted the transitions so I have 0 now
But don't seem to be able to delete the draft and published states

And I'm not seeing an error about there being no transitions.

Is there a step I'm missing?

smustgrave’s picture

Status: Needs review » Postponed (maintainer needs more info)

Moving PNMI for #24

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

spokje’s picture

Can't reproduce in the UI,
However fail-test still fails and updated MR still passes.

Unsure what to do, TBH being almost 2 years ago after the first NR (all other activity are rerolls for new branches), I don't really care anymore at this time.

smustgrave’s picture

Status: Postponed (maintainer needs more info) » Closed (outdated)

Hopefully didn't discourage anyone.

But if the bug can be reproduced please reopen updating issue summary with steps to reproduce.

Thanks!