It appears that hook_workflow('transition post') is not getting called. I need to send emails after the transition is completed, but the Execute method in WorkflowTransition.php seems to be missing that code. Is there a reason why this was left out?

CommentFileSizeAuthor
#8 workflow_notify.zip7.87 KBNancyDru
#6 2546152-6.patch881 bytesNancyDru
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

NancyDru created an issue. See original summary.

johnv’s picture

This hook is removed in workflow_field, since hook_entity_save() does the same thing. It seemed superfluous.

See node_save():

// Let modules modify the node before it is saved to the database.
    module_invoke_all('node_presave', $node);
    module_invoke_all('entity_presave', $node, 'node');
//...
drupal_write_record('node', $node, 'nid');
//...
         module_invoke_all('node_' . $op, $node);
         module_invoke_all('entity_' . $op, $node, 'node');

johnv’s picture

It should still work for workflow_node.

NancyDru’s picture

This is workflow_field. I have at least two cases where I specifically need to know that the transition has been done, and to which state. (See the workflow_notify module in 7.x-1.x). While I might be able to detect this situation in hook_entity_save(), it would be with considerably more effort.

NancyDru’s picture

Line 433:
// module_invoke_all('workflow', 'transition post', $old_sid, $new_sid, $entity, $force, $entity_type, $field_name, $this);
// We have a problem here with Rules, Trigger, etc. when invoking
// 'transition post': the entity has not been saved, yet. we are still
// IN the transition, not AFTER. Alternatives:
// 1. Save the field here explicitely, using field_attach_save;
// 2. Move the invoke to another place: hook_entity_insert(), hook_entity_update();
// 3. Rely on the entity hooks. This works for Rules, not for Trigger.
// --> We choose option 2:
// - First, $entity->workflow_transitions[] is set for easy re-fetching.
// - Then, post_execute() is invoked via workflowfield_entity_insert(), _update().

Note that those hooks also occur before the actual writing to the database (node_save is a db transaction).

NancyDru’s picture

FileSize
881 bytes

This works for me.

NancyDru’s picture

Status: Active » Needs review
NancyDru’s picture

FileSize
7.87 KB

BTW, here is a 7.x-2.x version of workflow_notify.

  • johnv committed 1905cd3 on 7.x-2.x authored by NancyDru
    Issue #2546152 by NancyDru: Added workflow_notify submodule
    
johnv’s picture

The workflow_notify module is now added to the repository.

johnv’s picture

This is my documentation in workflow.api.php for removing hook_post:

    case 'transition post':
      // This is called by Workflow Node during update of the state, directly
      // after updating {workflow_node}. Workflow Field does not call this,
      // since you can call a hook_entity_* event after saving the entity.
      // @see https://api.drupal.org/api/drupal/includes%21module.inc/group/hooks/7
      break;
NancyDru’s picture

deleted

johnv’s picture

Status: Needs review » Closed (works as designed)

Are you OK with this?
(In D8 even more custom hooks are removed, in favour of hook_entity_CRUD() and hook_ENTITY-TYPE_CRUD(). )

NancyDru’s picture

I kind of like the original hooks because they are straightforward, but I understand why you're taking them away.