public function WorkflowDefaultWidget::submit in Workflow 7
Same name and namespace in other branches
- 7.2 includes/Field/WorkflowDefaultWidget.php \WorkflowDefaultWidget::submit()
File
- includes/Field/WorkflowDefaultWidget.php, line 299
- Contains workflow\includes\Field\WorkflowDefaultWidget.
Class
- WorkflowDefaultWidget
- Plugin implementation of the 'workflow_default' widget.
@todo D8: Replace "extends WorkflowD7WidgetBase" by "extends WidgetBase"
or perhaps by "extends OptionsWidgetBase" from Options module.
Code
public function submit(array $form, array &$form_state, array &$items, $force = FALSE) {
global $user;
$entity_type = $this->entity_type;
$entity = $this->entity;
$entity_id = isset($entity->nid) ? $entity->nid : entity_id($entity_type, $entity);
$field = $this->field;
$field_name = isset($this->field['field_name']) ? $this->field['field_name'] : '';
$old_sid = workflow_node_current_state($entity, $entity_type, $field);
$new_sid = isset($items[0]['workflow']['workflow_options']) ? $items[0]['workflow']['workflow_options'] : $items[0]['value'];
$new_items = isset($items[0]['workflow']) ? $items[0]['workflow'] : $items;
$transition = $this
->getTransition($old_sid, $new_sid, $new_items);
if ($error = $transition
->isAllowed($force)) {
drupal_set_message($error, 'error');
}
elseif (!$transition
->isScheduled()) {
if ($field_name) {
$items = array();
$items[0]['value'] = $new_sid;
$entity->{$field_name}['und'] = $items;
}
$new_sid = $transition
->execute($force);
if ($field_name) {
$items = array();
$items[0]['value'] = $new_sid;
$entity->{$field_name}['und'] = $items;
}
}
else {
$transition
->save();
$new_sid = $old_sid;
}
if ($field_name) {
$items = array();
$items[0]['value'] = $new_sid;
$entity->{$field_name}['und'] = $items;
}
return $new_sid;
}