ContentModerationState.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace Drupal\content_moderation;
  3. use Drupal\workflows\StateInterface;
  4. /**
  5. * A value object representing a workflow state for content moderation.
  6. */
  7. class ContentModerationState implements StateInterface {
  8. /**
  9. * The vanilla state object from the Workflow module.
  10. *
  11. * @var \Drupal\workflows\StateInterface
  12. */
  13. protected $state;
  14. /**
  15. * If entities should be published if in this state.
  16. *
  17. * @var bool
  18. */
  19. protected $published;
  20. /**
  21. * If entities should be the default revision if in this state.
  22. *
  23. * @var bool
  24. */
  25. protected $defaultRevision;
  26. /**
  27. * ContentModerationState constructor.
  28. *
  29. * Decorates state objects to add methods to determine if an entity should be
  30. * published or made the default revision.
  31. *
  32. * @param \Drupal\workflows\StateInterface $state
  33. * The vanilla state object from the Workflow module.
  34. * @param bool $published
  35. * (optional) TRUE if entities should be published if in this state, FALSE
  36. * if not. Defaults to FALSE.
  37. * @param bool $default_revision
  38. * (optional) TRUE if entities should be the default revision if in this
  39. * state, FALSE if not. Defaults to FALSE.
  40. */
  41. public function __construct(StateInterface $state, $published = FALSE, $default_revision = FALSE) {
  42. $this->state = $state;
  43. $this->published = $published;
  44. $this->defaultRevision = $default_revision;
  45. }
  46. /**
  47. * Determines if entities should be published if in this state.
  48. *
  49. * @return bool
  50. */
  51. public function isPublishedState() {
  52. return $this->published;
  53. }
  54. /**
  55. * Determines if entities should be the default revision if in this state.
  56. *
  57. * @return bool
  58. */
  59. public function isDefaultRevisionState() {
  60. return $this->defaultRevision;
  61. }
  62. /**
  63. * {@inheritdoc}
  64. */
  65. public function id() {
  66. return $this->state->id();
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function label() {
  72. return $this->state->label();
  73. }
  74. /**
  75. * {@inheritdoc}
  76. */
  77. public function weight() {
  78. return $this->state->weight();
  79. }
  80. /**
  81. * {@inheritdoc}
  82. */
  83. public function canTransitionTo($to_state_id) {
  84. return $this->state->canTransitionTo($to_state_id);
  85. }
  86. /**
  87. * {@inheritdoc}
  88. */
  89. public function getTransitionTo($to_state_id) {
  90. return $this->state->getTransitionTo($to_state_id);
  91. }
  92. /**
  93. * {@inheritdoc}
  94. */
  95. public function getTransitions() {
  96. return $this->state->getTransitions();
  97. }
  98. }