getBundleInfo example


  public function contentPermissions() {
    $permissions = [];
    // Create a translate permission for each enabled entity type and (optionally)     // bundle.     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      if ($permission_granularity = $entity_type->getPermissionGranularity()) {
        switch ($permission_granularity) {
          case 'bundle':
            foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type_id) as $bundle => $bundle_info) {
              if ($this->contentTranslationManager->isEnabled($entity_type_id$bundle)) {
                $permissions["translate $bundle $entity_type_id"] = $this->buildBundlePermission($entity_type$bundle$bundle_info);
              }
            }
            break;

          case 'entity_type':
            if ($this->contentTranslationManager->isEnabled($entity_type_id)) {
              $permissions["translate $entity_type_id"] = [
                'title' => $this->t('Translate @entity_label', ['@entity_label' => $entity_type->getSingularLabel()]),
                'dependencies' => ['module' => [$entity_type->getProvider()]],
              ];

  public function buildForm(array $form, FormStateInterface $form_state, WorkflowInterface $workflow = NULL, $entity_type_id = NULL) {
    $this->workflow = $workflow;
    try {
      $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']]],
          
public static function fieldSettingsSummary(FieldDefinitionInterface $field_definition): array {
    $summary = parent::fieldSettingsSummary($field_definition);
    $target_type = $field_definition->getFieldStorageDefinition()->getSetting('target_type');
    $handler_settings = $field_definition->getSetting('handler_settings');

    if (!isset($handler_settings['target_bundles'])) {
      return $summary;
    }

    /** @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entity_bundle_information */
    $entity_bundle_information = \Drupal::service('entity_type.bundle.info');
    $bundle_info = $entity_bundle_information->getBundleInfo($target_type);
    $bundles = array_map(fn($bundle) => $bundle_info[$bundle]['label']$handler_settings['target_bundles']);
    $bundle_label = \Drupal::entityTypeManager()->getDefinition($target_type)->getBundleLabel();

    if (!empty($bundles)) {
      $summary[] = new FormattableMarkup('@bundle: @entity_type', [
        '@bundle' => $bundle_label ?: new TranslatableMarkup('Bundle'),
        '@entity_type' => implode(', ', $bundles),
      ]);
    }

    return $summary;
  }
/** * {@inheritdoc} */
  public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition, MigrationInterface $migration = NULL) {
    $entity_type = static::getEntityTypeId($plugin_id);
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $migration,
      $container->get('entity_type.manager')->getStorage($entity_type),
      array_keys($container->get('entity_type.bundle.info')->getBundleInfo($entity_type)),
      $container->get('entity_field.manager'),
      $container->get('plugin.manager.field.field_type'),
      $container->get('account_switcher')
    );
  }

  /** * {@inheritdoc} * * @throws \Drupal\migrate\MigrateException * When an entity cannot be looked up. * @throws \Drupal\migrate\Exception\EntityValidationException * When an entity validation hasn't been passed. */

  public function setupModerationBundleInfo($bundle$workflow = NULL) {
    $bundle_info_array = [];
    if ($workflow) {
      $bundle_info_array['workflow'] = $workflow;
    }
    $bundle_info = $this->prophesize(EntityTypeBundleInfoInterface::class);
    $bundle_info->getBundleInfo("test_entity_type")->willReturn([$bundle => $bundle_info_array]);
    $bundle_info->getBundleInfo("unmoderated_test_type")->willReturn([$bundle => []]);

    return $bundle_info->reveal();
  }

  /** * @covers ::isModeratedEntityType */
  public function testIsModeratedEntityType() {
    $moderation_information = new ModerationInformation($this->getEntityTypeManager()$this->setupModerationBundleInfo('test_bundle', 'workflow'));

    
/** * {@inheritdoc} */
  public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition, MigrationInterface $migration = NULL) {
    $entity_type = static::getEntityTypeId($plugin_id);
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $migration,
      $container->get('entity_type.manager')->getStorage($entity_type),
      array_keys($container->get('entity_type.bundle.info')->getBundleInfo($entity_type)),
      $container->get('entity_field.manager'),
      $container->get('plugin.manager.field.field_type'),
      $container->get('state'),
      $container->get('account_switcher')
    );
  }

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    

  public function getRevisionId() {
    return $this->getEntityKey('revision');
  }

  /** * {@inheritdoc} */
  public function isTranslatable() {
    // Check the bundle is translatable, the entity has a language defined, and     // the site has more than one language.     $bundles = $this->entityTypeBundleInfo()->getBundleInfo($this->entityTypeId);
    return !empty($bundles[$this->bundle()]['translatable']) && !$this->getUntranslated()->language()->isLocked() && $this->languageManager()->isMultilingual();
  }

  /** * {@inheritdoc} */
  public function preSave(EntityStorageInterface $storage) {
    // An entity requiring validation should not be saved if it has not been     // actually validated.     assert(!$this->validationRequired || $this->validated, 'Entity validation was skipped.');

    


    $this->ensureMyTable();

    $entity_type = $this->entityTypeManager->getDefinition($this->getEntityType());
    $bundle_condition = NULL;
    if ($entity_type->hasKey('bundle')) {
      // Get a list of bundles that are being moderated by the workflows       // configured in this filter.       $workflow_ids = $this->getWorkflowIds();
      $moderated_bundles = [];
      foreach ($this->bundleInfo->getBundleInfo($this->getEntityType()) as $bundle_id => $bundle) {
        if (isset($bundle['workflow']) && in_array($bundle['workflow']$workflow_ids, TRUE)) {
          $moderated_bundles[] = $bundle_id;
        }
      }

      // If we have a list of moderated bundles, restrict the query to show only       // entities in those bundles.       if ($moderated_bundles) {
        $entity_base_table_alias = $this->relationship ?: $this->table;

        // The bundle field of an entity type is not revisionable so we need to
$container->get('entity_type.bundle.info'),
      $container->get('messenger')
    );
  }

  /** * {@inheritdoc} */
  public function access($entity, AccountInterface $account = NULL, $return_as_object = FALSE) {
    /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
    if ($entity && $this->moderationInfo->isModeratedEntity($entity)) {
      $bundle_info = $this->bundleInfo->getBundleInfo($entity->getEntityTypeId());
      $bundle_label = $bundle_info[$entity->bundle()]['label'];
      $this->messenger->addWarning($this->t("@bundle @label were skipped as they are under moderation and may not be directly unpublished.", [
        '@bundle' => $bundle_label,
        '@label' => $entity->getEntityType()->getPluralLabel(),
      ]));
      $result = AccessResult::forbidden('Cannot directly unpublish moderated entities.');
      return $return_as_object ? $result : $result->isAllowed();
    }
    return parent::access($entity$account$return_as_object);
  }

}
// Add definitions for each entity type and bundle.     foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      $class = $entity_type->entityClassImplements(ConfigEntityInterface::class) ? ConfigEntityAdapter::class D EntityAdapter::class;
      $this->derivatives[$entity_type_id] = [
        'class' => $class,
        'label' => $entity_type->getLabel(),
        'constraints' => $entity_type->getConstraints(),
        'internal' => $entity_type->isInternal(),
      ] + $base_plugin_definition;

      // Incorporate the bundles as entity:$entity_type:$bundle, if any.       $bundle_info = $this->bundleInfoService->getBundleInfo($entity_type_id);
      if (count($bundle_info) > 1 || $entity_type->getKey('bundle')) {
        foreach ($bundle_info as $bundle => $info) {
          $this->derivatives[$entity_type_id . ':' . $bundle] = [
            'class' => $class,
            'label' => $info['label'],
            'constraints' => $this->derivatives[$entity_type_id]['constraints'],
          ] + $base_plugin_definition;
        }
      }
    }
    return $this->derivatives;
  }
/** * {@inheritdoc} */
  public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition, MigrationInterface $migration = NULL) {
    $entity_type_id = static::getEntityTypeId($plugin_id);
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $migration,
      $container->get('entity_type.manager')->getStorage($entity_type_id),
      array_keys($container->get('entity_type.bundle.info')->getBundleInfo($entity_type_id)),
      $container->get('language_manager'),
      $container->get('config.factory')
    );
  }

  /** * {@inheritdoc} */
  public function import(Row $row, array $old_destination_id_values = []) {
    if ($row->isStub()) {
      throw new MigrateException('Config entities can not be stubbed.');
    }
/** * Returns the bundle label of an entity. * * @param \Drupal\Core\Entity\RevisionableInterface $entity * The entity. * * @return string|null * The bundle label. */
  protected function getBundleLabel(RevisionableInterface $entity): ?string {
    $bundleInfo = $this->bundleInformation->getBundleInfo($entity->getEntityTypeId());
    return isset($bundleInfo[$entity->bundle()]['label']) ? (string) $bundleInfo[$entity->bundle()]['label'] : NULL;
  }

  /** * {@inheritdoc} */
  public function setOperation($operation) {
    $this->operation = $operation;
    return $this;
  }

  
$configuration,
      $plugin_id,
      $plugin_definition,
      $container->get('entity_type.bundle.info')
    );
  }

  /** * {@inheritdoc} */
  public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
    $bundles = $this->entityTypeBundleInfo->getBundleInfo($this->getDerivativeId());
    $form['bundles'] = [
      '#title' => $this->pluginDefinition['label'],
      '#type' => 'checkboxes',
      '#options' => array_combine(array_keys($bundles)array_column($bundles, 'label')),
      '#default_value' => $this->configuration['bundles'],
    ];
    return parent::buildConfigurationForm($form$form_state);
  }

  /** * {@inheritdoc} */
/** * {@inheritdoc} */
  public static function create(ContainerInterface $container, array $configuration$plugin_id$plugin_definition, MigrationInterface $migration = NULL) {
    $entity_type = static::getEntityTypeId($plugin_id);
    return new static(
      $configuration,
      $plugin_id,
      $plugin_definition,
      $migration,
      $container->get('entity_type.manager')->getStorage($entity_type),
      array_keys($container->get('entity_type.bundle.info')->getBundleInfo($entity_type)),
      $container->get('entity_field.manager'),
      $container->get('plugin.manager.field.field_type'),
      $container->get('password'),
      $container->get('account_switcher')
    );
  }

  /** * {@inheritdoc} * @throws \Drupal\migrate\MigrateException */
  
'#header' => $header,
      '#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'),
      ];
      
Home | Imprint | This part of the site doesn't use cookies.