/**
  * Extract WorkflowTransition or WorkflowScheduledTransition from the form.
  *
  * This merely extracts the transition from the form/widget. No validation.
  */
 public function getTransition($old_sid, array $items, $field_name, stdClass $user)
 {
     $entity_type = $this->entity_type;
     $entity = $this->entity;
     // $entity_id = entity_id($entity_type, $entity);
     $field_name = !empty($this->field) ? $this->field['field_name'] : '';
     if (isset($items[0]['transition'])) {
         // a complete transition was already passed on.
         $transition = $items[0]['transition'];
     } else {
         // Get the new Transition properties. First the new State ID.
         if (isset($items[0]['workflow']['workflow_sid'])) {
             // We have shown a workflow form.
             $new_sid = $items[0]['workflow']['workflow_sid'];
         } elseif (isset($items[0]['value'])) {
             // We have shown a core options widget (radios, select).
             $new_sid = $items[0]['value'];
         } else {
             // This may happen if only 1 option is left, and a formatter is shown.
             $state = workflow_state_load_single($old_sid);
             if (!$state->isCreationState()) {
                 $new_sid = $old_sid;
             } else {
                 // This only happens on workflows, when only one transition from
                 // '(creation)' to another state is allowed.
                 $workflow = $state->getWorkflow();
                 $new_sid = $workflow->getFirstSid($this->entity_type, $this->entity, $field_name, $user, FALSE);
             }
         }
         $comment = isset($items[0]['workflow']['workflow_comment']) ? $items[0]['workflow']['workflow_comment'] : '';
         // Remember, the workflow_scheduled element is not set on 'add' page.
         $scheduled = !empty($items[0]['workflow']['workflow_scheduled']);
         if (!$scheduled) {
             $transition = new WorkflowTransition();
             $transition->setValues($entity_type, $entity, $field_name, $old_sid, $new_sid, $user->uid, REQUEST_TIME, $comment);
         } else {
             // Schedule the time to change the state.
             // If Field Form is used, use plain values;
             // If Node Form is used, use fieldset 'workflow_scheduled_date_time'.
             $schedule = isset($items[0]['workflow']['workflow_scheduled_date_time']) ? $items[0]['workflow']['workflow_scheduled_date_time'] : $items[0]['workflow'];
             if (!isset($schedule['workflow_scheduled_hour'])) {
                 $schedule['workflow_scheduled_hour'] = '00:00';
             }
             $scheduled_date_time = $schedule['workflow_scheduled_date']['year'] . substr('0' . $schedule['workflow_scheduled_date']['month'], -2, 2) . substr('0' . $schedule['workflow_scheduled_date']['day'], -2, 2) . ' ' . $schedule['workflow_scheduled_hour'] . ' ' . $schedule['workflow_scheduled_timezone'];
             if ($stamp = strtotime($scheduled_date_time)) {
                 $transition = new WorkflowScheduledTransition();
                 $transition->setValues($entity_type, $entity, $field_name, $old_sid, $new_sid, $user->uid, $stamp, $comment);
             } else {
                 $transition = NULL;
             }
         }
     }
     return $transition;
 }
 public function getNewState()
 {
     return workflow_state_load_single($this->target_sid);
 }
Beispiel #3
0
 /**
  * Gets a state for a given workflow.
  *
  * @param mixed $key
  *   A state ID or state Name.
  *
  * @return WorkflowState
  *   A WorkflowState object.
  */
 public function getState($key)
 {
     if (is_numeric($key)) {
         return workflow_state_load_single($key, $this->wid);
     } else {
         return workflow_state_load_by_name($key, $this->wid);
     }
 }