Example #1
0
 /**
  * {@inheritdoc}
  */
 public function createTransition($from_sid, $to_sid, $values = array())
 {
     $config_transition = NULL;
     $workflow = $this;
     // First check if this transition already exists.
     if ($transitions = $this->getTransitionsByStateId($from_sid, $to_sid)) {
         $config_transition = reset($transitions);
     } else {
         $values['wid'] = $workflow->id();
         $values['from_sid'] = $from_sid;
         $values['to_sid'] = $to_sid;
         $config_transition = WorkflowConfigTransition::create($values);
         $config_transition->save();
     }
     // Maintain the new object in the workflow.
     $this->transitions[$config_transition->id()] = $config_transition;
     return $config_transition;
 }
Example #2
0
/**
 * Implements hook_workflow_permitted_state_transitions_alter().
 *
 * @param array $transitions
 *  An array of allowed transitions from the current state (as provided in
 *  $context). They are already filtered by the settings in Admin UI.
 * @param array $context
 *  An array of relevant objects. Currently:
 *    $context = array(
 *      'user' => $user,
 *      'workflow' => $workflow,
 *      'state' => $current_state,
 *      'force' => $force,
 *    );
 *
 * This hook allows you to add custom filtering of allowed target states, add
 * new custom states, change labels, etc.
 * It is invoked in WorkflowState::getOptions().
 */
function hook_workflow_permitted_state_transitions_alter(array &$transitions, array $context)
{
    //  workflow_debug(__FILE__, __FUNCTION__, __LINE__, '', '');
    $user = $context['user'];
    // user may have the custom role AUTHOR.
    // The following could be fetched from each transition.
    $workflow = $context['workflow'];
    $current_state = $context['state'];
    // The following could be fetched from the $user and $transition objects.
    $force = $context['force'];
    // Implement here own permission logic.
    foreach ($transitions as $key => $transition) {
        if (!$transition->isAllowed($user, $force)) {
            //unset($transitions[$key]);
        }
    }
    // This example creates a new custom target state.
    $values = array('wid' => $context['workflow']->id(), 'from_sid' => $context['state']->id(), 'to_sid' => '998', 'label' => 'go to my new fantasy state');
    $new_transition = WorkflowConfigTransition::create($values);
    //  $transitions[] = $new_transition;
}