Context:

  • some content-types has a dedicated field to hold workflow's state
  • updating node trigger a custom rule (set-up in a custom module): the action is presently correctly triggered
  • if node goes from state 'A' (old content) to state 'B' (content chosen when saving) the method performs some actions and then - under some conditions - makes a further change from state 'B' to state 'C' (or to another one).

It means that user sees a node in state 'A', change it to 'B', save and then he sees 'C' immediately.

WORKS-IN-PROGRESS:
No coding works.
The best result (being "$old_node" the variable holding the previous content and "$new_node" the one with data to be saved and "field_state" the name of the field) is achieved using:

  • $old_state = $old_node->get('field_state')->getValue()[0]['value'];
  • $new_state = $new_node->get('field_state')->getValue()[0]['value'];
  • then comparing the two, so that if $old_state is 'A' and $new-state is 'B' it goes on
  • setting the new value with something like $new_node->set('field_state', 'C');

PROBLEMS:
permissions: once a "permission error" was raised... we don't want to give users the permission to set nodes to state 'C' (it shouldn't be an option when editing)... this is a secondary problem. At first it seemed this was the real problem (there are some "user has no permission to set state to 'C'" but we cannot reproduce this again), but giving all permissions doesn't solve the next (bigger) one (and reverting to original permissions raises no other errors, anyway)
saving: 'C' state is not saved. It could be a matter of module's ordering (so that "workflow" save node with 'B' before the further update) but even changing module's weight worked at all.

Any solution to this would be glad.

Comments

Developer airpim created an issue. See original summary.

Developer airpim’s picture

Issue summary: View changes
johnv’s picture

johnv’s picture

Title: Change workflow's state in custom rule when updating node » How to change workflow's state in custom rule when updating node