tid, NULL, NULL, FALSE); return parent::delete(); } protected function defaultLabel() { return $this->label; } protected function defaultUri() { return array('path' => 'admin/config/workflow/workflow/manage/' . $this->wid . '/transitions/'); } /** * Property functions. */ /** * Returns the Workflow object of this State. * * @param Workflow $workflow * An optional workflow object. Can be used as a setter. * * @return Workflow * Workflow object. */ public function setWorkflow($workflow) { $this->wid = $workflow->wid; $this->workflow = $workflow; } public function getWorkflow() { if (isset($this->workflow)) { return $this->workflow; } return workflow_load_single($this->wid); } public function getOldState() { return workflow_state_load_single($this->sid); } public function getNewState() { return workflow_state_load_single($this->target_sid); } /** * Verifies if the given transition is allowed. * * - In settings; * - In permissions; * - By permission hooks, implemented by other modules. * * @return bool * TRUE if OK, else FALSE. */ public function isAllowed($user_roles) { if ($user_roles == 'ALL') { // Superuser. return TRUE; } elseif ($user_roles) { return array_intersect($user_roles, $this->roles) == TRUE; } return TRUE; } /** * Generate a machine name for a transition. */ public static function machineName($start_name, $end_name) { $new_name = sprintf("%s_to_%s", $start_name, $end_name); // Special case: replace parens in creation state transition names. $new_name = str_replace("(creation)", "_creation", $new_name); return $new_name; } public function save() { parent::save(); // Ensure Workflow is marked overridden. $workflow = $this->getWorkflow(); if ($workflow->status == ENTITY_IN_CODE) { $workflow->status = ENTITY_OVERRIDDEN; $workflow->save(); } } } /** * Implements a controller class for WorkflowConfigTransition. * * The 'true' controller class is 'Workflow'. */ class WorkflowConfigTransitionController extends EntityAPIController { /** * Overrides DrupalDefaultEntityController::cacheGet(). * * Override default function, due to core issue #1572466. */ protected function cacheGet($ids, $conditions = array()) { // Load any available entities from the internal cache. if ($ids === FALSE && !$conditions) { return $this->entityCache; } return parent::cacheGet($ids, $conditions); } public function save($entity, DatabaseTransaction $transaction = NULL) { $workflow = $entity->getWorkflow(); // To avoid double posting, check if this transition already exist. if (empty($entity->tid)) { if ($workflow) { $config_transitions = $workflow->getTransitionsBySidTargetSid($entity->sid, $entity->target_sid); $config_transition = reset($config_transitions); if ($config_transition) { $entity->tid = $config_transition->tid; } } } // Create the machine_name. This can be used to rebuild/revert the Feature in a target system. if (empty($entity->name)) { $entity->name = $entity->sid . '_' . $entity->target_sid; } $return = parent::save($entity, $transaction); if ($return) { // Save in current workflow for the remainder of this page request. // Keep in sync with Workflow::getTransitions() ! $workflow = $entity->getWorkflow(); if ($workflow) { $workflow->transitions[$entity->tid] = $entity; // $workflow->sortTransitions(); } } // Reset the cache for the affected workflow, to force reload upon next page_load. workflow_reset_cache($entity->wid); return $return; } }