getTypePlugin example

$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';
    $node->save();

    
$this->installSchema('node', 'node_access');
    $this->installEntitySchema('node');
    $this->installEntitySchema('entity_test');
    $this->installEntitySchema('user');
    $this->installEntitySchema('content_moderation_state');
    $this->installConfig('content_moderation');

    NodeType::create([
      'type' => 'example',
    ])->save();
    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'example');
    $workflow->save();
  }

  /** * Tests the ContentModerationState unique keys. * * @covers ::getEntitySchema */
  public function testUniqueKeys() {
    // Create a node which will create a new ContentModerationState entity.     $node = Node::create([
      

  protected function getModeratedEntityTypes() {
    if (!isset($this->moderatedEntityTypes)) {
      $entity_types = $this->entityTypeManager->getDefinitions();
      /** @var \Drupal\workflows\WorkflowInterface $workflow */
      foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) {
        /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $plugin */
        $plugin = $workflow->getTypePlugin();
        foreach ($plugin->getEntityTypes() as $entity_type_id) {
          $this->moderatedEntityTypes[$entity_type_id] = $entity_types[$entity_type_id];
        }
      }
    }
    return $this->moderatedEntityTypes;
  }

  /** * {@inheritdoc} */
  
/** * Creates a page node type to test with, ensuring that it's moderated. */
  protected function createNodeType() {
    $node_type = NodeType::create([
      'type' => 'page',
      'label' => 'Page',
    ]);
    $node_type->save();
    $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('node', 'page');
    $workflow->save();
  }

  /** * Verifies that the process of saving pending revisions works as expected. */
  public function testPendingRevisions() {
    // Create a new node in draft.     $page = Node::create([
      'type' => 'page',
      'title' => 'A',
    ]);
/** * Adds an entity type ID / bundle ID to the given workflow. * * @param \Drupal\workflows\WorkflowInterface $workflow * A workflow object. * @param string $entity_type_id * The entity type ID to add. * @param string $bundle * The bundle ID to add. */
  protected function addEntityTypeAndBundleToWorkflow(WorkflowInterface $workflow$entity_type_id$bundle) {
    $workflow->getTypePlugin()->addEntityTypeAndBundle($entity_type_id$bundle);
    $workflow->save();
  }

}

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

    $moderated_bundle = $this->createContentType(['type' => 'moderated_bundle']);
    $moderated_bundle->save();
    $standard_bundle = $this->createContentType(['type' => 'standard_bundle']);
    $standard_bundle->save();

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

    $admin = $this->drupalCreateUser([
      'access content overview',
      'administer nodes',
      'bypass node access',
    ]);
    $this->drupalLogin($admin);
  }

  /** * Tests the node status actions report moderation status to users correctly. * * @dataProvider nodeStatusActionsTestCases */
/** * {@inheritdoc} */
  protected function createEntity() {
    $workflow = Workflow::create([
      'id' => 'rest_workflow',
      'label' => 'REST Workflow',
      'type' => 'workflow_type_complex_test',
    ]);
    $workflow
      ->getTypePlugin()
      ->addState('draft', 'Draft')
      ->addState('published', 'Published');
    $configuration = $workflow->getTypePlugin()->getConfiguration();
    $configuration['example_setting'] = 'foo';
    $configuration['states']['draft']['extra'] = 'bar';
    $workflow->getTypePlugin()->setConfiguration($configuration);
    $workflow->save();
    return $workflow;
  }

  /** * {@inheritdoc} */
$this->drupalPlaceBlock('system_menu_block:main');

    // Create a 'page' content type.     $this->drupalCreateContentType([
      'type' => 'page',
      'name' => 'Basic page',
      'display_submitted' => FALSE,
    ]);

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

  /** * Tests that node drafts can not modify the menu settings. */
  public function testMenuUiWithPendingRevisions() {
    $editor = $this->drupalCreateUser([
      'administer nodes',
      'administer menu',
      'create page content',
      
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();
    $this->assertEquals('draft', $english_node->moderation_state->value);
    
/** * Returns an array of transition permissions. * * @return array * The transition permissions. */
  public function transitionPermissions() {
    $permissions = [];
    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) {
      foreach ($workflow->getTypePlugin()->getTransitions() as $transition) {
        $permissions['use ' . $workflow->id() . ' transition ' . $transition->id()] = [
          'title' => $this->t('%workflow workflow: Use %transition transition.', [
            '%workflow' => $workflow->label(),
            '%transition' => $transition->label(),
          ]),
          'description' => $this->formatPlural(
            count($transition->from()),
            'Move content from %from state to %to state.',
            'Move content from %from states to %to state.', [
              '%from' => implode(', ', array_map([State::class, 'labelCallback']$transition->from())),
              '%to' => $transition->to()->label(),
            ]
return parent::buildForm($form$form_state);
  }

  /** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form$form_state);

    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = $this->getEntity();
    $workflow_type = $workflow->getTypePlugin();
    $state = $workflow->getTypePlugin()->getState($this->stateId);

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('State label'),
      '#maxlength' => 255,
      '#default_value' => $state->label(),
      '#required' => TRUE,
    ];

    $form['id'] = [
      
$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 */
    $authenticated = Role::create([
      
'target_bundles' => ['image']],
      FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED
    );
    // Add the media field to the form display.     $form_display = \Drupal::service('entity_display.repository')->getFormDisplay('node', 'article', 'default');
    $form_display->setComponent('field_media', [
      'type' => 'media_library_widget',
    ])->save();

    // Configure the "Editorial" workflow to apply to image media.     $workflow = $this->createEditorialWorkflow();
    $workflow->getTypePlugin()->addEntityTypeAndBundle('media', 'image');
    $workflow->save();

    $image = File::create([
      'uri' => $this->getTestFiles('image')[0]->uri,
    ]);
    $image->setPermanent();
    $image->save();

    // Create a draft, published and archived media item.     $draft_media = Media::create([
      'name' => 'Hoglet',
      

  }

  /** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form$form_state);

    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = $this->entity;
    $workflow_type = $workflow->getTypePlugin();
    $form['#title'] = $this->t('Edit %label workflow', ['%label' => $workflow->label()]);

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Label'),
      '#maxlength' => 255,
      '#default_value' => $workflow->label(),
      '#required' => TRUE,
    ];

    $form['id'] = [
      
return 'workflow_transition_add_form';
  }

  /** * {@inheritdoc} */
  public function form(array $form, FormStateInterface $form_state) {
    $form = parent::form($form$form_state);

    /** @var \Drupal\workflows\WorkflowInterface $workflow */
    $workflow = $this->getEntity();
    $workflow_type = $workflow->getTypePlugin();

    $form['label'] = [
      '#type' => 'textfield',
      '#title' => $this->t('Transition label'),
      '#maxlength' => 255,
      '#default_value' => '',
      '#required' => TRUE,
    ];

    $form['id'] = [
      '#type' => 'machine_name',
      
Home | Imprint | This part of the site doesn't use cookies.