You are here

class ContentModerationState in Drupal 9

Same name in this branch
  1. 9 core/modules/content_moderation/src/ContentModerationState.php \Drupal\content_moderation\ContentModerationState
  2. 9 core/modules/content_moderation/src/Entity/ContentModerationState.php \Drupal\content_moderation\Entity\ContentModerationState
Same name and namespace in other branches
  1. 8 core/modules/content_moderation/src/ContentModerationState.php \Drupal\content_moderation\ContentModerationState

A value object representing a workflow state for content moderation.

Hierarchy

Expanded class hierarchy of ContentModerationState

2 files declare their use of ContentModerationState
ContentModeration.php in core/modules/content_moderation/src/Plugin/WorkflowType/ContentModeration.php
content_moderation.module in core/modules/content_moderation/content_moderation.module
Contains content_moderation.module.

File

core/modules/content_moderation/src/ContentModerationState.php, line 10

Namespace

Drupal\content_moderation
View source
class ContentModerationState implements StateInterface {

  /**
   * The vanilla state object from the Workflow module.
   *
   * @var \Drupal\workflows\StateInterface
   */
  protected $state;

  /**
   * If entities should be published if in this state.
   *
   * @var bool
   */
  protected $published;

  /**
   * If entities should be the default revision if in this state.
   *
   * @var bool
   */
  protected $defaultRevision;

  /**
   * ContentModerationState constructor.
   *
   * Decorates state objects to add methods to determine if an entity should be
   * published or made the default revision.
   *
   * @param \Drupal\workflows\StateInterface $state
   *   The vanilla state object from the Workflow module.
   * @param bool $published
   *   (optional) TRUE if entities should be published if in this state, FALSE
   *   if not. Defaults to FALSE.
   * @param bool $default_revision
   *   (optional) TRUE if entities should be the default revision if in this
   *   state, FALSE if not. Defaults to FALSE.
   */
  public function __construct(StateInterface $state, $published = FALSE, $default_revision = FALSE) {
    $this->state = $state;
    $this->published = $published;
    $this->defaultRevision = $default_revision;
  }

  /**
   * Determines if entities should be published if in this state.
   *
   * @return bool
   */
  public function isPublishedState() {
    return $this->published;
  }

  /**
   * Determines if entities should be the default revision if in this state.
   *
   * @return bool
   */
  public function isDefaultRevisionState() {
    return $this->defaultRevision;
  }

  /**
   * {@inheritdoc}
   */
  public function id() {
    return $this->state
      ->id();
  }

  /**
   * {@inheritdoc}
   */
  public function label() {
    return $this->state
      ->label();
  }

  /**
   * {@inheritdoc}
   */
  public function weight() {
    return $this->state
      ->weight();
  }

  /**
   * {@inheritdoc}
   */
  public function canTransitionTo($to_state_id) {
    return $this->state
      ->canTransitionTo($to_state_id);
  }

  /**
   * {@inheritdoc}
   */
  public function getTransitionTo($to_state_id) {
    return $this->state
      ->getTransitionTo($to_state_id);
  }

  /**
   * {@inheritdoc}
   */
  public function getTransitions() {
    return $this->state
      ->getTransitions();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentModerationState::$defaultRevision protected property If entities should be the default revision if in this state.
ContentModerationState::$published protected property If entities should be published if in this state.
ContentModerationState::$state protected property The vanilla state object from the Workflow module.
ContentModerationState::canTransitionTo public function Determines if the state can transition to the provided state ID. Overrides StateInterface::canTransitionTo
ContentModerationState::getTransitions public function Gets all the possible transition objects for the state. Overrides StateInterface::getTransitions
ContentModerationState::getTransitionTo public function Gets the Transition object for the provided state ID. Overrides StateInterface::getTransitionTo
ContentModerationState::id public function Gets the state's ID. Overrides StateInterface::id
ContentModerationState::isDefaultRevisionState public function Determines if entities should be the default revision if in this state.
ContentModerationState::isPublishedState public function Determines if entities should be published if in this state.
ContentModerationState::label public function Gets the state's label. Overrides StateInterface::label
ContentModerationState::weight public function Gets the state's weight. Overrides StateInterface::weight
ContentModerationState::__construct public function ContentModerationState constructor.
StateInterface::PLUGIN_FORM_KEY constant The key of the state plugin form.