/** * Returns the allowed values for the current state. * * @deprecated workflow_field_choices() --> WorkflowState->getOptions() */ public function getOptions($entity_type, $entity, $force = FALSE) { global $user; static $cache = array(); // Entity-specific cache per page load. $options = array(); if (!$entity) { // If no entity is given, no result (e.g., on a Field settings page). $options = array(); return $options; } $entity_id = entity_id($entity_type, $entity); $current_sid = $this->sid; // Get options from page cache. if (isset($cache[$entity_type][$entity_id][$force][$current_sid])) { $options = $cache[$entity_type][$entity_id][$force][$current_sid]; return $options; } $workflow = Workflow::load($this->wid); if ($workflow) { $roles = array_keys($user->roles); // If this is a new page, give the authorship role. if (!$entity_id) { $roles = array_merge(array('author'), $roles); } elseif (isset($entity->uid) && $entity->uid == $user->uid && $user->uid > 0) { $roles = array_merge(array('author'), $roles); } // Superuser is special. And $force allows Rules to cause transition. if ($user->uid == 1 || $force) { $roles = 'ALL'; } // Workflow_allowable_transitions() does not return the entire transition row. Would like it to, but doesn't. // Instead it returns just the allowable data as: // [tid] => 1 [state_id] => 1 [state_name] => (creation) [state_weight] => -50 $transitions = workflow_allowable_transitions($current_sid, 'to', $roles); // Include current state if it is not the (creation) state. foreach ($transitions as $transition) { if ($transition->sysid != WORKFLOW_CREATION && !$force) { // Invoke a callback indicating that we are collecting state choices. // Modules may veto a choice by returning FALSE. // In this case, the choice is never presented to the user. // @todo: for better performance, call a hook only once: can we find a way to pass all transitions at once $result = module_invoke_all('workflow', 'transition permitted', $current_sid, $transition->state_id, $entity, $field_name = ''); // Did anybody veto this choice? if (!in_array(FALSE, $result)) { // If not vetoed, add to list. $options[$transition->state_id] = check_plain(t($transition->state_name)); } } } // Save to entity-specific cache. $cache[$entity_type][$entity_id][$force][$current_sid] = $options; } return $options; }
/** * Validate the workflow. Generate a message if not correct. * * This function is used on the settings page of: * - Workflow node: workflow_admin_ui_type_map_form() * - Workflow field: WorkflowItem->settingsForm() * * @return bool $is_valid */ public function validate() { $is_valid = TRUE; // Don't allow workflows with no states. (There should always be a creation state.) $states = $this->getStates(); if (count($states) < 2) { // That's all, so let's remind them to create some states. $message = t('Workflow %workflow has no states defined, so it cannot be assigned to content yet.', array('%workflow' => ucwords($this->getName()))); drupal_set_message($message, 'warning'); // Skip allowing this workflow. $is_valid = FALSE; } // Also check for transitions at least out of the creation state. // This always gets at least the "from" state. $transitions = workflow_allowable_transitions($this->getCreationSid(), 'to'); if (count($transitions) < 2) { // That's all, so let's remind them to create some transitions. $message = t('Workflow %workflow has no transitions defined, so it cannot be assigned to content yet.', array('%workflow' => ucwords($this->getName()))); drupal_set_message($message, 'warning'); // Skip allowing this workflow. $is_valid = FALSE; } return $is_valid; }