You are here

function workflowfield_field_update in Workflow 7

Same name and namespace in other branches
  1. 7.2 workflow_field/workflowfield.field.inc \workflowfield_field_update()

Implements hook_field_update(). 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 98
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();
  if ($entity_type == 'comment') {

    // This happens when we are on an entity's comment.
    $nid = isset($entity->nid) ? $entity->nid : 0;
    $referenced_entity_type = 'node';

    // Comments only exist on nodes.
    $referenced_entities = entity_load($referenced_entity_type, array(
      $nid,
    ));
    $referenced_entity = $referenced_entities[$nid];

    // @todo: when changing Workflow via comment, the history is saved twice.
    $widget = new WorkflowDefaultWidget($field, $instance, $referenced_entity_type, $referenced_entity);
    $widget
      ->submit($form, $form_state, $items);

    // $items is a proprietary D7 parameter.
    // We must save the node, too.
    $widget
      ->entitySave($referenced_entity_type, $referenced_entity);
  }
  else {
    $widget = new WorkflowDefaultWidget($field, $instance, $entity_type, $entity);
    $widget
      ->submit($form, $form_state, $items);

    // $items is a proprietary D7 parameter.
    //    $widget->setEntity($entity_type, $entity);
    //    $widget->entitySave($entity_type, $entity);
  }
}