class WorkflowConfigTransition in Workflow 7.2
Implements a configurated Transition.
Hierarchy
- class \Entity implements EntityInterface
- class \WorkflowConfigTransition
Expanded class hierarchy of WorkflowConfigTransition
8 string references to 'WorkflowConfigTransition'
- Workflow::createTransition in includes/
Entity/ Workflow.php - Creates a Transition for this workflow.
- Workflow::getTransitions in includes/
Entity/ Workflow.php - @inheritdoc
- Workflow::rebuildInternals in includes/
Entity/ Workflow.php - Rebuild internals that get saved separately.
- WorkflowConfigTransition::__construct in includes/
Entity/ WorkflowConfigTransition.php - workflow_entity_info in ./
workflow.entity.inc - Implements hook_entity_info().
File
- includes/
Entity/ WorkflowConfigTransition.php, line 12 - Contains workflow\includes\Entity\WorkflowConfigTransition. Contains workflow\includes\Entity\WorkflowConfigTransitionController.
View source
class WorkflowConfigTransition extends Entity {
// Transition data.
public $tid = 0;
// public $old_sid = 0;
// public $new_sid = 0;
public $sid = 0;
// @todo D8: remove $sid, use $new_sid. (requires conversion of Views displays.)
public $target_sid = 0;
public $roles = array();
// Extra fields.
public $wid = 0;
// The following must explicitely defined, and not be public, to avoid errors when exporting with json_encode().
protected $workflow = NULL;
/**
* Entity class functions.
*/
/*
// Implementing clone needs a list of tid-less transitions, and a conversion
// of sids for both States and ConfigTransitions.
// public function __clone() {}
*/
public function __construct(array $values = array(), $entityType = NULL) {
// Please be aware that $entity_type and $entityType are different things!
return parent::__construct($values, $entityType = 'WorkflowConfigTransition');
}
/**
* Permanently deletes the entity.
*/
public function delete() {
// Notify any interested modules before we delete, in case there's data needed.
// @todo D8: this can be replaced by a hook_entity_delete(?)
module_invoke_all('workflow', 'transition delete', $this->tid, NULL, NULL, FALSE);
return parent::delete();
}
protected function defaultLabel() {
return isset($this->label) ? t('@label', array(
'@label' => $this->label,
)) : '';
}
protected function defaultUri() {
$wid = $this->wid;
return array(
'path' => WORKFLOW_ADMIN_UI_PATH . "/manage/{$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.
*
* @param string|array $user_roles
* The string 'ALL' to force allowing the transition, or an array of role
* IDs to compare against the roles allowed for the transition.
*
* @return bool
* If the transition is allowed, this function returns TRUE. Otherwise, it
* returns 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();
}
}
/**
* Helper debugging function to easily show the contents of a transition.
*/
public function dpm($function = 'not_specified') {
$transition = $this;
$time = NULL;
// Do this extensive $user_name lines, for some troubles with Action.
$t_string = get_class($this) . ' ' . $this
->identifier() . " in function '{$function}'";
//$output[] = 'Entity = ' . ((!$entity) ? 'NULL' : ($entity_type . '/' . $entity_bundle . '/' . $entity_id));
//$output[] = 'Field = ' . $transition->getFieldName();
$output[] = 'From/To = ' . $transition->sid . ' > ' . $transition->target_sid . ' @ ' . $time;
//$output[] = 'Comment = ' . $user_name . ' says: ' . $transition->getComment();
//$output[] = 'Forced = ' . ($transition->isForced() ? 'yes' : 'no');
if (function_exists('dpm')) {
dpm($output, $t_string);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Entity:: |
protected | property | 1 | |
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
protected | property | ||
Entity:: |
public | function |
Builds a structured array representing the entity's content. Overrides EntityInterface:: |
1 |
Entity:: |
public | function |
Returns the bundle of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the info of the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the type of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Exports the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Gets the raw, translated value of a property or field. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks if the entity has a certain exportable status. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the entity identifier, i.e. the entities name or numeric id. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the internal, numeric identifier. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Checks whether the entity is the default revision. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the label of the entity. Overrides EntityInterface:: |
|
Entity:: |
protected | function | Set up the object instance on construction or unserializiation. | |
Entity:: |
public | function |
Returns the uri of the entity just as entity_uri(). Overrides EntityInterface:: |
|
Entity:: |
public | function |
Generate an array for rendering the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function |
Returns the EntityMetadataWrapper of the entity. Overrides EntityInterface:: |
|
Entity:: |
public | function | Magic method to only serialize what's necessary. | |
Entity:: |
public | function | Magic method to invoke setUp() on unserialization. | |
WorkflowConfigTransition:: |
public | property | ||
WorkflowConfigTransition:: |
public | property | ||
WorkflowConfigTransition:: |
public | property | ||
WorkflowConfigTransition:: |
public | property | ||
WorkflowConfigTransition:: |
public | property | ||
WorkflowConfigTransition:: |
protected | property | ||
WorkflowConfigTransition:: |
protected | function |
Defines the entity label if the 'entity_class_label' callback is used. Overrides Entity:: |
|
WorkflowConfigTransition:: |
protected | function |
Override this in order to implement a custom default URI and specify
'entity_class_uri' as 'uri callback' hook_entity_info(). Overrides Entity:: |
|
WorkflowConfigTransition:: |
public | function |
Permanently deletes the entity. Overrides Entity:: |
|
WorkflowConfigTransition:: |
public | function | Helper debugging function to easily show the contents of a transition. | |
WorkflowConfigTransition:: |
public | function | ||
WorkflowConfigTransition:: |
public | function | ||
WorkflowConfigTransition:: |
public | function | ||
WorkflowConfigTransition:: |
public | function | Verifies if the given transition is allowed. | |
WorkflowConfigTransition:: |
public static | function | Generate a machine name for a transition. | |
WorkflowConfigTransition:: |
public | function |
Permanently saves the entity. Overrides Entity:: |
|
WorkflowConfigTransition:: |
public | function | Returns the Workflow object of this State. | |
WorkflowConfigTransition:: |
public | function |
Overrides Entity:: |