Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. State.php

class State

Same name in this branch
  1. 11.1.x core/lib/Drupal/Core/State/State.php \Drupal\Core\State\State

A value object representing a workflow state.

Hierarchy

  • class \Drupal\workflows\State implements \Drupal\workflows\StateInterface

Expanded class hierarchy of State

6 files declare their use of State
ContentModerationConfigureForm.php in core/modules/content_moderation/src/Form/ContentModerationConfigureForm.php
Permissions.php in core/modules/content_moderation/src/Permissions.php
WorkflowEditForm.php in core/modules/workflows/src/Form/WorkflowEditForm.php
WorkflowTransitionAddForm.php in core/modules/workflows/src/Form/WorkflowTransitionAddForm.php
WorkflowTransitionEditForm.php in core/modules/workflows/src/Form/WorkflowTransitionEditForm.php

... See full list

37 string references to 'State'
ContentModerationStateForm::buildConfigurationForm in core/modules/content_moderation/src/Form/ContentModerationStateForm.php
Form constructor.
CredentialForm::create in core/modules/migrate_drupal_ui/src/Form/CredentialForm.php
Instantiates a new instance of this class.
CronForm::create in core/modules/system/src/Form/CronForm.php
Instantiates a new instance of this class.
d6_language_content_taxonomy_vocabulary_settings.yml in core/modules/language/migrations/d6_language_content_taxonomy_vocabulary_settings.yml
core/modules/language/migrations/d6_language_content_taxonomy_vocabulary_settings.yml
DbUpdateController::create in core/modules/system/src/Controller/DbUpdateController.php
Instantiates a new instance of the implementing class using autowiring.

... See full list

File

core/modules/workflows/src/State.php, line 8

Namespace

Drupal\workflows
View source
class State implements StateInterface {
    
    /**
     * The workflow the state is attached to.
     *
     * @var \Drupal\workflows\WorkflowTypeInterface
     */
    protected $workflow;
    
    /**
     * The state's ID.
     *
     * @var string
     */
    protected $id;
    
    /**
     * The state's label.
     *
     * @var string
     */
    protected $label;
    
    /**
     * The state's weight.
     *
     * @var int
     */
    protected $weight;
    
    /**
     * State constructor.
     *
     * @param \Drupal\workflows\WorkflowTypeInterface $workflow
     *   The workflow the state is attached to.
     * @param string $id
     *   The state's ID.
     * @param string $label
     *   The state's label.
     * @param int $weight
     *   The state's weight.
     */
    public function __construct(WorkflowTypeInterface $workflow, $id, $label, $weight = 0) {
        $this->workflow = $workflow;
        $this->id = $id;
        $this->label = $label;
        $this->weight = $weight;
    }
    
    /**
     * {@inheritdoc}
     */
    public function id() {
        return $this->id;
    }
    
    /**
     * {@inheritdoc}
     */
    public function label() {
        return $this->label;
    }
    
    /**
     * {@inheritdoc}
     */
    public function weight() {
        return $this->weight;
    }
    
    /**
     * {@inheritdoc}
     */
    public function canTransitionTo($to_state_id) {
        return $this->workflow
            ->hasTransitionFromStateToState($this->id, $to_state_id);
    }
    
    /**
     * {@inheritdoc}
     */
    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);
    }
    
    /**
     * {@inheritdoc}
     */
    public function getTransitions() {
        return $this->workflow
            ->getTransitionsForState($this->id);
    }
    
    /**
     * Helper method to convert a State value object to a label.
     *
     * @param \Drupal\workflows\StateInterface $state
     *   The state.
     *
     * @return string
     *   The label of the state.
     */
    public static function labelCallback(StateInterface $state) {
        return $state->label();
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
State::$id protected property The state's ID.
State::$label protected property The state's label.
State::$weight protected property The state's weight.
State::$workflow protected property The workflow the state is attached to.
State::canTransitionTo public function Determines if the state can transition to the provided state ID. Overrides StateInterface::canTransitionTo
State::getTransitions public function Gets all the possible transition objects for the state. Overrides StateInterface::getTransitions
State::getTransitionTo public function Gets the Transition object for the provided state ID. Overrides StateInterface::getTransitionTo
State::id public function Gets the state's ID. Overrides StateInterface::id
State::label public function Gets the state's label. Overrides StateInterface::label
State::labelCallback public static function Helper method to convert a State value object to a label.
State::weight public function Gets the state's weight. Overrides StateInterface::weight
State::__construct public function State constructor.
StateInterface::PLUGIN_FORM_KEY constant The key of the state plugin form.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal