function ModerationStateTestBase::enableModerationThroughUi

Same name and namespace in other branches
  1. 11.x core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php \Drupal\Tests\content_moderation\Functional\ModerationStateTestBase::enableModerationThroughUi()
  2. 10 core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php \Drupal\Tests\content_moderation\Functional\ModerationStateTestBase::enableModerationThroughUi()
  3. 8.9.x core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php \Drupal\Tests\content_moderation\Functional\ModerationStateTestBase::enableModerationThroughUi()

Enable moderation for a specified content type, using the UI.

Parameters

string $content_type_id: Machine name.

string $workflow_id: The workflow to attach to the bundle.

File

core/modules/content_moderation/tests/src/Functional/ModerationStateTestBase.php, line 137

Class

ModerationStateTestBase
Defines a base class for moderation state tests.

Namespace

Drupal\Tests\content_moderation\Functional

Code

public function enableModerationThroughUi($content_type_id, $workflow_id = 'editorial') {
  $this->drupalGet('/admin/config/workflow/workflows');
  $this->assertSession()
    ->linkByHrefExists('admin/config/workflow/workflows/manage/' . $workflow_id);
  $edit['bundles[' . $content_type_id . ']'] = TRUE;
  $this->drupalGet('admin/config/workflow/workflows/manage/' . $workflow_id . '/type/node');
  $this->submitForm($edit, 'Save');
  // Ensure the parent environment is up-to-date.
  // @see content_moderation_workflow_insert()
  \Drupal::service('entity_type.bundle.info')->clearCachedBundles();
  \Drupal::service('entity_field.manager')->clearCachedFieldDefinitions();
  /** @var \Drupal\Core\Routing\RouteBuilderInterface $router_builder */
  $router_builder = $this->container
    ->get('router.builder');
  $router_builder->rebuildIfNeeded();
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.