function workflowfield_field_update in Workflow 7.2
Same name and namespace in other branches
- 7 workflow_field/workflowfield.field.inc \workflowfield_field_update()
Implements hook_field_update().
It is the D7-wrapper for D8-style WorkflowDefaultWidget::submit. It is called also from hook_field_insert, since we need $nid to store workflow_node_history. We cannot use hook_field_presave, since $nid is not yet known at that moment.
1 call to workflowfield_field_update()
- workflowfield_field_insert in workflow_field/
workflowfield.field.inc - Implements hook_field_insert().
File
- workflow_field/
workflowfield.field.inc, line 187 - Defines a Workflow field, widget and formatter. (copied from list field).
Code
function workflowfield_field_update($entity_type, $entity, array $field, $instance, $langcode, &$items) {
$form = array();
$form_state = array();
$field_name = $field['field_name'];
if ($entity_type == 'comment') {
// This happens when we are on an entity's comment.
// We save the field of the node. The comment is saved automatically.
$referenced_entity_type = 'node';
// Comments only exist on nodes.
$referenced_entity_id = $entity->nid;
// Load the node again, since the passed node doesn't contain proper 'type' field.
$referenced_entity = entity_load_single($referenced_entity_type, $referenced_entity_id);
// Normalize the contents of the workflow field.
$items[0]['value'] = _workflow_get_sid_by_items($items);
// Execute the transition upon the node. Afterwards, $items is in form as expected by Field API.
// Remember, we don't know if the transition is scheduled or not.
$widget = new WorkflowTransitionForm($field, $instance, $referenced_entity_type, $referenced_entity);
$widget
->submitForm($form, $form_state, $items);
// $items is a proprietary D7 parameter.
// // Since we are saving the comment only, we must save the node separately.
// entity_save($referenced_entity_type, $referenced_entity);
}
else {
$widget = new WorkflowTransitionForm($field, $instance, $entity_type, $entity);
$widget
->submitForm($form, $form_state, $items);
// $items is a proprietary D7 parameter.
}
}