Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function getTransitions(array $ids = NULL, array $conditions = array())
 {
     $config_transitions = array();
     // Get filters on 'from' states, 'to' states, roles.
     $from_sid = isset($conditions['from_sid']) ? $conditions['from_sid'] : FALSE;
     $to_sid = isset($conditions['to_sid']) ? $conditions['to_sid'] : FALSE;
     // Get valid states + creation state.
     $states = $this->getStates('CREATION');
     // Cache all transitions in the workflow.
     if (!$this->transitions) {
         $this->transitions = WorkflowConfigTransition::loadMultiple($ids);
         $this->sortTransitions();
     }
     /* @var $config_transition WorkflowConfigTransition */
     foreach ($this->transitions as &$config_transition) {
         if (!isset($states[$config_transition->getFromSid()])) {
             // Not a valid transition for this workflow. @todo: delete them.
         } elseif ($from_sid && $from_sid != $config_transition->getFromSid()) {
             // Not the requested 'from' state.
         } elseif ($to_sid && $to_sid != $config_transition->getToSid()) {
             // Not the requested 'to' state.
         } else {
             // Transition is allowed, permitted. Add to list.
             $config_transitions[$config_transition->id()] = $config_transition;
         }
     }
     return $config_transitions;
 }
Beispiel #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;
}