State.php in Drupal 8
File
core/modules/workflows/src/State.php
View source
<?php
namespace Drupal\workflows;
class State implements StateInterface {
protected $workflow;
protected $id;
protected $label;
protected $weight;
public function __construct(WorkflowTypeInterface $workflow, $id, $label, $weight = 0) {
$this->workflow = $workflow;
$this->id = $id;
$this->label = $label;
$this->weight = $weight;
}
public function id() {
return $this->id;
}
public function label() {
return $this->label;
}
public function weight() {
return $this->weight;
}
public function canTransitionTo($to_state_id) {
return $this->workflow
->hasTransitionFromStateToState($this->id, $to_state_id);
}
public function getTransitionTo($to_state_id) {
if (!$this
->canTransitionTo($to_state_id)) {
throw new \InvalidArgumentException("Can not transition to '{$to_state_id}' state");
}
return $this->workflow
->getTransitionFromStateToState($this
->id(), $to_state_id);
}
public function getTransitions() {
return $this->workflow
->getTransitionsForState($this->id);
}
public static function labelCallback(StateInterface $state) {
return $state
->label();
}
}
Classes
Name |
Description |
State |
A value object representing a workflow state. |