loadMultipleByType example


  public static function isPendingRevisionSupportEnabled($entity_type_id$bundle_id = NULL) {
    if (!\Drupal::moduleHandler()->moduleExists('content_moderation')) {
      return FALSE;
    }

    foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) {
      /** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModeration $plugin */
      $plugin = $workflow->getTypePlugin();
      $entity_type_ids = array_flip($plugin->getEntityTypes());
      if (isset($entity_type_ids[$entity_type_id])) {
        if (!isset($bundle_id)) {
          return TRUE;
        }
        else {
          $bundle_ids = array_flip($plugin->getBundlesForEntityType($entity_type_id));
          if (isset($bundle_ids[$bundle_id])) {
            return TRUE;
          }
/** * Returns the moderated entity types. * * @return \Drupal\Core\Entity\ContentEntityTypeInterface[] * An associative array of moderated entity types keyed by ID. */
  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} */

  public function checkAccess(ContentEntityInterface $entity) {
    $result = AccessResult::allowed();

    $entity_type_id = $entity->getEntityTypeId();
    $result->addCacheableDependency($entity);
    // Add the cache dependencies used by     // ContentTranslationManager::isPendingRevisionSupportEnabled().     if (\Drupal::moduleHandler()->moduleExists('content_moderation')) {
      foreach (Workflow::loadMultipleByType('content_moderation') as $workflow) {
        $result->addCacheableDependency($workflow);
      }
    }
    if (!ContentTranslationManager::isPendingRevisionSupportEnabled($entity_type_id$entity->bundle())) {
      return $result;
    }

    if ($entity->isDefaultTranslation()) {
      return $result;
    }

    
use StringTranslationTrait;

  /** * 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())),
              
/** * @covers \Drupal\workflows\Entity\Workflow::loadMultipleByType */
  public function testLoadMultipleByType() {
    $workflow1 = Workflow::create(['id' => 'test1', 'type' => 'workflow_type_complex_test']);
    $workflow1->save();
    $workflow2 = Workflow::create(['id' => 'test2', 'type' => 'workflow_type_complex_test']);
    $workflow2->save();
    $workflow3 = Workflow::create(['id' => 'test3', 'type' => 'workflow_type_test']);
    $workflow3->save();

    $this->assertEquals(['test1', 'test2']array_keys(Workflow::loadMultipleByType('workflow_type_complex_test')));
    $this->assertEquals(['test3']array_keys(Workflow::loadMultipleByType('workflow_type_test')));
    $this->assertEquals([], Workflow::loadMultipleByType('a_type_that_does_not_exist'));
  }

}
Home | Imprint | This part of the site doesn't use cookies.