enableModerationThroughUi example

$edit = [
      'name' => $content_type_name,
      'type' => $content_type_id,
    ];
    $this->submitForm($edit, 'Save content type');

    // Check the content type has been set to create new revisions.     $this->assertTrue(NodeType::load($content_type_id)->shouldCreateNewRevision());

    if ($moderated) {
      $this->enableModerationThroughUi($content_type_id$workflow_id);
    }
  }

  /** * Enable moderation for a specified content type, using the UI. * * @param string $content_type_id * Machine name. * @param string $workflow_id * The workflow to attach to the bundle. */
  
    $this->drupalGet('node/add/not_moderated');
    $this->submitForm([
      'title[0][value]' => 'Test',
    ], 'Save');
    $this->assertSession()->pageTextContains('Not moderated Test has been created.');

    // Check that the 'Create new revision' is not disabled.     $this->drupalGet('/admin/structure/types/manage/not_moderated');
    $this->assertNull($this->assertSession()->fieldExists('options[revision]')->getAttribute('disabled'));

    // Now enable moderation state.     $this->enableModerationThroughUi('not_moderated');

    // Check that the 'Create new revision' checkbox is checked and disabled.     $this->drupalGet('/admin/structure/types/manage/not_moderated');
    $this->assertSession()->checkboxChecked('options[revision]');
    $this->assertSession()->fieldDisabled('options[revision]');

    // And make sure it works.     $nodes = \Drupal::entityTypeManager()->getStorage('node')
      ->loadByProperties(['title' => 'Test']);
    if (empty($nodes)) {
      $this->fail('Could not load node with title Test');
      
    // node_access_test_node_access_records().     \Drupal::state()->set('node_access_test.private', TRUE);

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

    // Access the node form before moderation is enabled, the publication state     // should now be visible.     $this->drupalGet('node/add/moderated_content');
    $this->assertSession()->fieldExists('Published');

    // Now enable the workflow.     $this->enableModerationThroughUi('moderated_content', 'editorial');

    // Access that the status field is no longer visible.     $this->drupalGet('node/add/moderated_content');
    $this->assertSession()->fieldNotExists('Published');

    // Create a node to test with.     $this->submitForm([
      'title[0][value]' => 'moderated content',
      'moderation_state[0][state]' => 'draft',
    ], 'Save');
    $node = $this->getNodeByTitle('moderated content');
    
Home | Imprint | This part of the site doesn't use cookies.