function workflowfield_field_widget_form_submit in Workflow 7
1 string reference to 'workflowfield_field_widget_form_submit'
- WorkflowDefaultWidget::formElement in includes/
Field/ WorkflowDefaultWidget.php - Implements hook_field_widget_form --> WidgetInterface::formElement().
File
- workflow_field/
workflowfield.widget.inc, line 111 - Defines a Workflow field, widget (sfrom options.module) and formatter (from list field). All hooks are wrapper functions for a D8-style WorkflowDefaultWidget object.
Code
function workflowfield_field_widget_form_submit($form, &$form_state) {
// Emulate the D7 arrays.
$field = $form_state['values']['workflow_field'];
$instance = $form_state['values']['workflow_instance'];
$entity_type = $form['#entity_type'];
$field_name = $field['field_name'];
$entity = $form['#entity'];
$items[0]['workflow'] = $form_state['values'];
$old_sid = _workflow_get_sid_by_items($entity->{$field_name}['und']);
// @todo: replace by currentState().
// Submit the data. $items is reset by reference to normal value, and is magically saved by the field itself.
$widget = new WorkflowDefaultWidget($field, $instance, $entity_type, $entity);
// $widget->submit($form, $form_state, $items); // $items is a proprietary D7 parameter.
// Remember: we are on an Entity view page, so the Widget->submit saves the scheduled transition,
// but not the new state of the entity itself.
// Widget::submit() returns the new value in a 'sane' state.
// Save the referenced entity, but only is transition succeeded, and is not scheduled.
$new_sid = _workflow_get_sid_by_items($items);
if ($old_sid != $new_sid) {
// $entity->{$field_name}['und'][0]['value'] = $new_sid;
$entity->{$field_name}['und'][0]['workflow'] = $form_state['values'];
$widget
->entitySave($entity_type, $entity);
}
}