addEntityTypeAndBundleToWorkflow example

unset($editorial_2_values['uuid']);
    $editorial_2_values['id'] = 'editorial_2';
    $editorial_2_values['type_settings']['states']['archived']['default_revision'] = FALSE;

    $editorial_2 = Workflow::create($editorial_2_values);
    $this->workspaceManager->executeOutsideWorkspace(function D) use ($editorial_2) {
      $editorial_2->save();
    });

    // Create two bundles and assign the two workflows for each of them.     $this->createContentType(['type' => 'page']);
    $this->addEntityTypeAndBundleToWorkflow($editorial, 'node', 'page');
    $this->createContentType(['type' => 'article']);
    $this->addEntityTypeAndBundleToWorkflow($editorial_2, 'node', 'article');

    // Create three entities for each bundle, covering all the available     // moderation states.     $page_archived = Node::create(['type' => 'page', 'title' => 'Test page - archived', 'moderation_state' => 'archived']);
    $page_archived->save();
    $page_draft = Node::create(['type' => 'page', 'title' => 'Test page - draft', 'moderation_state' => 'draft']);
    $page_draft->save();
    $page_published = Node::create(['type' => 'page', 'title' => 'Test page - published', 'moderation_state' => 'published']);
    $page_published->save();

    
/** * 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()));
  }

  

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

    $entity_type_id = 'entity_test_rev';

    $this->installEntitySchema('content_moderation_state');
    $this->installEntitySchema($entity_type_id);

    $workflow = $this->createEditorialWorkflow();
    $this->addEntityTypeAndBundleToWorkflow($workflow$entity_type_id$entity_type_id);

    /** @var \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager */
    $entity_type_manager = $this->container->get('entity_type.manager');
    $this->contentModerationStateStorage = $entity_type_manager->getStorage('content_moderation_state');
    $this->entityStorage = $entity_type_manager->getStorage($entity_type_id);
    $this->state = $this->container->get('state');
  }

  /** * Tests that Content Moderation works with entities being resaved. */
  
Home | Imprint | This part of the site doesn't use cookies.