createEditorialWorkflow example

parent::setUp();
    ConfigurableLanguage::createFromLangcode('fr')->save();
    $this->rebuildContainer();

    // Created a content type.     $this->drupalCreateContentType([
      'name' => 'moderated',
      'type' => 'moderated',
    ]);

    // Set the content type as moderated.     $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated');
    $workflow->save();

    $this->drupalLogin($this->rootUser);

    // Enable URL language detection and selection.     $edit = ['language_interface[enabled][language-url]' => 1];
    $this->drupalGet('admin/config/regional/language/detection');
    $this->submitForm($edit, 'Save settings');

    // Enable translation for moderated node.
    $this->installSchema('forum', ['forum_index']);
    $this->installSchema('node', ['node_access']);
    $this->installSchema('search', ['search_dataset']);
    $this->installSchema('system', ['sequences']);
    // @todo Remove tracker in https://www.drupal.org/project/drupal/issues/3261452     $this->installSchema('tracker', ['tracker_node', 'tracker_user']);

    // Enable content moderation for nodes of type page.     $this->installEntitySchema('content_moderation_state');
    $this->installConfig('content_moderation');
    NodeType::create(['type' => 'page'])->save();
    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
    $workflow->save();
  }

  /** * Tests multiple migrations to the same destination with no ID conflicts. */
  public function testMultipleMigrationWithoutIdConflicts() {
    // Create a node of type page.     $node = Node::create(['type' => 'page', 'title' => 'foo']);
    $node->moderation_state->value = 'published';
    
$this->installEntitySchema('user');
    $this->installConfig(['content_moderation', 'filter']);
    $this->installSchema('system', ['sequences']);
    $this->installSchema('node', ['node_access']);

    // Add a moderated node type.     $node_type = NodeType::create([
      'type' => 'page',
      'label' => 'Page',
    ]);
    $node_type->save();
    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
    $workflow->save();
  }

  /** * Tests access cacheability. */
  public function testAccessCacheability() {
    $node = $this->createNode(['type' => 'page']);

    /** @var \Drupal\user\RoleInterface $authenticated */
    
NodeType::create([
      'type' => 'example_a',
    ])->save();
    NodeType::create([
      'type' => 'example_b',
    ])->save();
    NodeType::create([
      'type' => 'example_c',
    ])->save();

    $this->createEditorialWorkflow();

    $new_workflow = Workflow::create([
      'type' => 'content_moderation',
      'id' => 'new_workflow',
      'label' => 'New workflow',
    ]);
    $new_workflow->getTypePlugin()->addState('bar', 'Bar');
    $new_workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example_c');
    $new_workflow->save();

    $this->drupalLogin($this->drupalCreateUser([
      
$this->installEntitySchema('content_moderation_state');
    $this->installEntitySchema('user');
    $this->installConfig(['content_moderation', 'system']);

    NodeType::create([
      'type' => 'moderated',
    ])->save();
    NodeType::create([
      'type' => 'unmoderated',
    ])->save();

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'moderated');
    $workflow->save();
  }

  /** * Tests the widget does not impact a non-moderated entity. */
  public function testWidgetNonModeratedEntity() {
    // Create an unmoderated entity and build a form display which will include     // the ModerationStateWidget plugin, in a hidden state.     $entity = Node::create([
      
'type' => 'example',
      'title' => 'Published node',
      'status' => 1,
    ]);
    $published_node->save();

    // Test with an entity type that doesn't implement EntityPublishedInterface.     $entity_test = EntityTestRev::create();
    $entity_test->save();

    \Drupal::service('module_installer')->install(['content_moderation'], TRUE);
    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
    $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
    $workflow->save();

    $loaded_unpublished_node = Node::load($unpublished_node->id());
    $loaded_published_node = Node::load($published_node->id());
    $loaded_entity_test = EntityTestRev::load($entity_test->id());
    $this->assertEquals('draft', $loaded_unpublished_node->moderation_state->value);
    $this->assertEquals('published', $loaded_published_node->moderation_state->value);
    $this->assertEquals('draft', $loaded_entity_test->moderation_state->value);

    
$this->grantPermissionsToTestedRole(['use editorial transition publish', 'use editorial transition create_new_draft']);
        break;
    }
  }

  /** * {@inheritdoc} */
  protected function createEntity() {
    $entity = parent::createEntity();
    if (!$this->workflow) {
      $this->workflow = $this->createEditorialWorkflow();
    }
    $this->workflow->getTypePlugin()->addEntityTypeAndBundle($entity->getEntityTypeId()$entity->bundle());
    $this->workflow->save();

    return $entity;
  }

  /** * {@inheritdoc} */
  protected function getExpectedNormalizedEntity() {
    

  protected function setUp(): void {
    parent::setUp();

    $node_type = NodeType::create([
      'type' => 'test',
      'label' => 'Test',
    ]);
    $node_type->save();

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'test');
    $workflow->save();

    $this->container->get('module_installer')->install(['content_moderation_test_views']);
  }

  /** * Tests the view operation access handler with the view permission. */
  public function testViewShowsCorrectStates() {
    $permissions = [
      


  /** * Tests removal of content moderation state entities for preexisting content. */
  public function testExistingContentModerationStateDataRemoval() {
    $storage = $this->entityTypeManager->getStorage('entity_test_mulrevpub');

    $entity = $this->createEntity('entity_test_mulrevpub', 'published', FALSE);
    $original_revision_id = $entity->getRevisionId();

    $workflow = $this->createEditorialWorkflow();
    $this->addEntityTypeAndBundleToWorkflow($workflow$entity->getEntityTypeId()$entity->bundle());

    $entity = $this->reloadEntity($entity);
    $entity->moderation_state = 'draft';
    $entity->save();

    $storage->deleteRevision($entity->getRevisionId());

    $entity = $this->reloadEntity($entity);
    $this->assertEquals('published', $entity->moderation_state->value);
    $this->assertEquals($original_revision_id$storage->getLatestRevisionId($entity->id()));
  }
    // @see \Drupal\content_moderation\Entity\Handler\ModerationHandler::onPresave()     // @see \Drupal\content_moderation\EntityTypeInfo::$moderationHandlers     if ($updated_entity instanceof EntityPublishedInterface) {
      $updated_entity->setPublished()->save();
    }
    $this->assertTrue($this->container->get('module_installer')->install(['content_moderation'], TRUE), 'Installed modules.');

    if (!\Drupal::service('content_moderation.moderation_information')->canModerateEntitiesOfEntityType($this->entity->getEntityType())) {
      return;
    }

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle(static::$entityTypeId$this->entity->bundle());
    $workflow->save();
    $this->grantPermissionsToTestedRole(['use editorial transition publish']);
    $doc_add_items['data']['attributes']['field_rest_test_multivalue'][2] = ['value' => '3'];
    $request_options[RequestOptions::BODY] = Json::encode($doc_add_items);
    $response = $this->request('PATCH', $url$request_options);
    $this->assertResourceResponse(200, FALSE, $response);
    $expected_document = [
      0 => ['value' => 'One'],
      1 => ['value' => 'Two'],
      2 => ['value' => '3'],
    ];

  protected function getTranslatorPermissions() {
    return array_merge(parent::getTranslatorPermissions()$this->commonPermissions);
  }

  /** * {@inheritdoc} */
  protected function setupBundle() {
    parent::setupBundle();
    $this->createContentType(['type' => $this->bundle]);
    $this->createEditorialWorkflow();
  }

  /** * Loads the active revision translation for the specified entity. * * @param \Drupal\Core\Entity\ContentEntityInterface $entity * The entity being edited. * @param string $langcode * The translation language code. * * @return \Drupal\Core\Entity\ContentEntityInterface|null * The active revision translation or NULL if none could be identified. */
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->installEntitySchema('entity_test_rev');
    $this->installEntitySchema('content_moderation_state');
    $this->installConfig('content_moderation');

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('entity_test_rev', 'entity_test_rev');
    $workflow->save();
  }

  /** * Tests the embed field. * * @dataProvider formatterTestCases */
  public function testStateFieldFormatter($field_value$formatter_settings$expected_output) {
    $entity = EntityTestRev::create([
      

  public function testMultilingual() {
    // Enable French.     ConfigurableLanguage::createFromLangcode('fr')->save();
    $node_type = NodeType::create([
      'type' => 'example',
    ]);
    $node_type->save();

    $this->container->get('content_translation.manager')->setEnabled('node', 'example', TRUE);

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
    $workflow->save();

    $english_node = Node::create([
      'type' => 'example',
      'title' => 'Test title',
    ]);
    // Revision 1 (en).     $english_node
      ->setUnpublished()
      ->save();
    
/** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->drupalCreateContentType(['type' => 'page', 'name' => 'Basic page'])->save();
    $this->drupalCreateContentType(['type' => 'article', 'name' => 'Article'])->save();
    $this->drupalCreateContentType(['type' => 'unmoderated_type', 'name' => 'Unmoderated type'])->save();

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'article');
    $workflow->save();

    $this->adminUser = $this->drupalCreateUser([
      'access administration pages',
      'view any unpublished content',
      'administer nodes',
      'bypass node access',
    ]);
  }

  
protected $defaultTheme = 'stark';

  /** * {@inheritdoc} */
  protected function setUp(): void {
    parent::setUp();

    $this->drupalPlaceBlock('system_breadcrumb_block');
    $this->drupalPlaceBlock('page_title_block');

    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'book');
    $workflow->save();

    // We need a user with additional content moderation permissions.     $this->bookAuthor = $this->drupalCreateUser([
      'create new books',
      'create book content',
      'edit own book content',
      'add content to books',
      'access printer-friendly version',
      'view any unpublished content',
      
Home | Imprint | This part of the site doesn't use cookies.