ContentModerationTestTrait.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace Drupal\Tests\content_moderation\Traits;
  3. use Drupal\workflows\Entity\Workflow;
  4. /**
  5. * Trait ContentModerationTestTraint.
  6. */
  7. trait ContentModerationTestTrait {
  8. /**
  9. * Creates the editorial workflow.
  10. *
  11. * @return \Drupal\workflows\Entity\Workflow
  12. * The editorial workflow entity.
  13. */
  14. protected function createEditorialWorkflow() {
  15. $workflow = Workflow::create([
  16. 'type' => 'content_moderation',
  17. 'id' => 'editorial',
  18. 'label' => 'Editorial',
  19. 'type_settings' => [
  20. 'states' => [
  21. 'archived' => [
  22. 'label' => 'Archived',
  23. 'weight' => 5,
  24. 'published' => FALSE,
  25. 'default_revision' => TRUE,
  26. ],
  27. 'draft' => [
  28. 'label' => 'Draft',
  29. 'published' => FALSE,
  30. 'default_revision' => FALSE,
  31. 'weight' => -5,
  32. ],
  33. 'published' => [
  34. 'label' => 'Published',
  35. 'published' => TRUE,
  36. 'default_revision' => TRUE,
  37. 'weight' => 0,
  38. ],
  39. ],
  40. 'transitions' => [
  41. 'archive' => [
  42. 'label' => 'Archive',
  43. 'from' => ['published'],
  44. 'to' => 'archived',
  45. 'weight' => 2,
  46. ],
  47. 'archived_draft' => [
  48. 'label' => 'Restore to Draft',
  49. 'from' => ['archived'],
  50. 'to' => 'draft',
  51. 'weight' => 3,
  52. ],
  53. 'archived_published' => [
  54. 'label' => 'Restore',
  55. 'from' => ['archived'],
  56. 'to' => 'published',
  57. 'weight' => 4,
  58. ],
  59. 'create_new_draft' => [
  60. 'label' => 'Create New Draft',
  61. 'to' => 'draft',
  62. 'weight' => 0,
  63. 'from' => [
  64. 'draft',
  65. 'published',
  66. ],
  67. ],
  68. 'publish' => [
  69. 'label' => 'Publish',
  70. 'to' => 'published',
  71. 'weight' => 1,
  72. 'from' => [
  73. 'draft',
  74. 'published',
  75. ],
  76. ],
  77. ],
  78. ],
  79. ]);
  80. $workflow->save();
  81. return $workflow;
  82. }
  83. }