Mercurial > hg > cmmr2012-drupal-site
diff core/modules/workflows/src/Transition.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/core/modules/workflows/src/Transition.php Thu Jul 05 14:24:15 2018 +0000 @@ -0,0 +1,112 @@ +<?php + +namespace Drupal\workflows; + +/** + * A transition value object that describes the transition between states. + */ +class Transition implements TransitionInterface { + + /** + * The workflow that this transition is attached to. + * + * @var \Drupal\workflows\WorkflowInterface + */ + protected $workflow; + + /** + * The transition's ID. + * + * @var string + */ + protected $id; + + /** + * The transition's label. + * + * @var string + */ + protected $label; + + /** + * The transition's from state IDs. + * + * @var string[] + */ + protected $fromStateIds; + + /** + * The transition's to state ID. + * + * @var string + */ + protected $toStateId; + + /** + * The transition's weight. + * + * @var int + */ + protected $weight; + + /** + * Transition constructor. + * + * @param \Drupal\workflows\WorkflowInterface $workflow + * The workflow the state is attached to. + * @param string $id + * The transition's ID. + * @param string $label + * The transition's label. + * @param array $from_state_ids + * A list of from state IDs. + * @param string $to_state_id + * The to state ID. + * @param int $weight + * (optional) The transition's weight. Defaults to 0. + */ + public function __construct(WorkflowTypeInterface $workflow, $id, $label, array $from_state_ids, $to_state_id, $weight = 0) { + $this->workflow = $workflow; + $this->id = $id; + $this->label = $label; + $this->fromStateIds = $from_state_ids; + $this->toStateId = $to_state_id; + $this->weight = $weight; + } + + /** + * {@inheritdoc} + */ + public function id() { + return $this->id; + } + + /** + * {@inheritdoc} + */ + public function label() { + return $this->label; + } + + /** + * {@inheritdoc} + */ + public function from() { + return $this->workflow->getStates($this->fromStateIds); + } + + /** + * {@inheritdoc} + */ + public function to() { + return $this->workflow->getState($this->toStateId); + } + + /** + * {@inheritdoc} + */ + public function weight() { + return $this->weight; + } + +}