appliesToEntityTypeAndBundle example

/** * @covers ::appliesToEntityTypeAndBundle * @covers ::addEntityTypeAndBundle * @covers ::removeEntityTypeAndBundle */
  public function testAppliesToEntityTypeAndBundle() {
    /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $workflow_plugin */
    $workflow_plugin = $this->workflow->getTypePlugin();
    // The content moderation plugin does not validate the existence of the     // entity type or bundle.     $this->assertFalse($workflow_plugin->appliesToEntityTypeAndBundle('fake_node', 'fake_page'));
    $workflow_plugin->addEntityTypeAndBundle('fake_node', 'fake_page');
    $this->assertTrue($workflow_plugin->appliesToEntityTypeAndBundle('fake_node', 'fake_page'));
    $this->assertFalse($workflow_plugin->appliesToEntityTypeAndBundle('fake_block', 'fake_custom'));
    $workflow_plugin->removeEntityTypeAndBundle('fake_node', 'fake_page');
    $this->assertFalse($workflow_plugin->appliesToEntityTypeAndBundle('fake_node', 'fake_page'));
  }

  /** * @covers ::addEntityTypeAndBundle */
  public function testAddEntityTypeAndBundle() {
    
$this->entityType = $this->entityTypeManager->getDefinition($entity_type_id);
    }
    catch (PluginNotFoundException $e) {
      throw new NotFoundHttpException();
    }

    $options = $defaults = [];
    foreach ($this->bundleInfo->getBundleInfo($this->entityType->id()) as $bundle_id => $bundle) {
      // Check if moderation is enabled for this bundle on any workflow.       $moderation_enabled = $this->moderationInformation->shouldModerateEntitiesOfBundle($this->entityType, $bundle_id);
      // Check if moderation is enabled for this bundle on this workflow.       $workflow_moderation_enabled = $this->workflow->getTypePlugin()->appliesToEntityTypeAndBundle($this->entityType->id()$bundle_id);
      // Only show bundles that are not enabled anywhere, or enabled on this       // workflow.       if (!$moderation_enabled || $workflow_moderation_enabled) {
        // Add the bundle to the options if it's not enabled on a workflow,         // unless the workflow it's enabled on is this one.         $options[$bundle_id] = [
          'title' => ['data' => ['#title' => $bundle['label']]],
          'type' => $bundle['label'],
        ];
        // Add the bundle to the list of default values if it's enabled on this         // workflow.

      else {
        $this->configuration['entity_types'][$entity_type_id] = array_values($this->configuration['entity_types'][$entity_type_id]);
      }
    }
  }

  /** * {@inheritdoc} */
  public function addEntityTypeAndBundle($entity_type_id$bundle_id) {
    if (!$this->appliesToEntityTypeAndBundle($entity_type_id$bundle_id)) {
      $this->configuration['entity_types'][$entity_type_id][] = $bundle_id;
      sort($this->configuration['entity_types'][$entity_type_id]);
      ksort($this->configuration['entity_types']);
    }
  }

  /** * {@inheritdoc} */
  public function defaultConfiguration() {
    return [
      
'#empty' => $this->t('There are no entity types.'),
    ];

    $entity_types = $this->entityTypeManager->getDefinitions();
    foreach ($entity_types as $entity_type) {
      if (!$this->moderationInfo->canModerateEntitiesOfEntityType($entity_type)) {
        continue;
      }

      $selected_bundles = [];
      foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type->id()) as $bundle_id => $bundle) {
        if ($this->workflowType->appliesToEntityTypeAndBundle($entity_type->id()$bundle_id)) {
          $selected_bundles[$bundle_id] = $bundle['label'];
        }
      }

      $selected_bundles_list = [
        '#theme' => 'item_list',
        '#items' => $selected_bundles,
        '#context' => ['list_style' => 'comma-list'],
        '#empty' => $this->t('none'),
      ];
      $form['entity_types_container']['entity_types'][$entity_type->id()] = [
        
Home | Imprint | This part of the site doesn't use cookies.