protected function ContentModerationWorkbenchEmailTest::setupModerationForNodeType in Workbench Email 8
Same name and namespace in other branches
- 2.x tests/src/Functional/ContentModerationWorkbenchEmailTest.php \Drupal\Tests\workbench_email\Functional\ContentModerationWorkbenchEmailTest::setupModerationForNodeType()
Enables moderation for a given node type.
Parameters
\Drupal\node\NodeTypeInterface $node_type: Node type to enable moderation for.
Overrides WorkbenchEmailTestBase::setupModerationForNodeType
File
- tests/
src/ Functional/ ContentModerationWorkbenchEmailTest.php, line 26
Class
- ContentModerationWorkbenchEmailTest
- Defines a class for testing workbench email with content moderation.
Namespace
Drupal\Tests\workbench_email\FunctionalCode
protected function setupModerationForNodeType(NodeTypeInterface $node_type) {
$node_type
->save();
$typeSettings = [
'states' => [
'archived' => [
'label' => 'Archived',
'weight' => 5,
'published' => FALSE,
'default_revision' => TRUE,
],
'draft' => [
'label' => 'Draft',
'published' => FALSE,
'default_revision' => FALSE,
'weight' => -5,
],
'needs_review' => [
'label' => 'Needs review',
'published' => FALSE,
'default_revision' => FALSE,
'weight' => -4,
],
'published' => [
'label' => 'Published',
'published' => TRUE,
'default_revision' => TRUE,
'weight' => 0,
],
],
'transitions' => [
'archive' => [
'label' => 'Archive',
'from' => [
'published',
],
'to' => 'archived',
'weight' => 2,
],
'archived_draft' => [
'label' => 'Restore to Draft',
'from' => [
'archived',
],
'to' => 'draft',
'weight' => 3,
],
'draft_needs_review' => [
'label' => 'Request Review',
'from' => [
'draft',
],
'to' => 'needs_review',
'weight' => 3,
],
'archived_published' => [
'label' => 'Restore',
'from' => [
'archived',
],
'to' => 'published',
'weight' => 4,
],
'create_new_draft' => [
'label' => 'Create New Draft',
'to' => 'draft',
'weight' => 0,
'from' => [
'draft',
'published',
'needs_review',
],
],
'needs_review_published' => [
'label' => 'Publish',
'to' => 'published',
'weight' => 1,
'from' => [
'needs_review',
'draft',
'published',
],
],
],
];
if (!($workflow = Workflow::load('editorial'))) {
$workflow = Workflow::create([
'type' => 'content_moderation',
'id' => 'editorial',
'label' => 'Editorial',
'type_settings' => $typeSettings,
]);
}
else {
if ($node_type
->id() === 'test') {
// Only do this the first time around.
$workflow
->getTypePlugin()
->setConfiguration($typeSettings);
}
}
$workflow
->getTypePlugin()
->addEntityTypeAndBundle('node', $node_type
->id());
$workflow
->save();
}