getBundleLabel example

$form['settings'] = ['#tree' => TRUE];

    foreach ($labels as $entity_type_id => $label) {
      $entity_type = $entity_types[$entity_type_id];

      $form['settings'][$entity_type_id] = [
        '#title' => $label,
        '#type' => 'container',
        '#entity_type' => $entity_type_id,
        '#theme' => 'language_content_settings_table',
        '#bundle_label' => $entity_type->getBundleLabel() ?: $label,
        '#states' => [
          'visible' => [
            ':input[name="entity_types[' . $entity_type_id . ']"]' => ['checked' => TRUE],
          ],
        ],
      ];

      foreach ($bundles[$entity_type_id] as $bundle => $bundle_info) {
        $form['settings'][$entity_type_id][$bundle]['settings'] = [
          '#type' => 'item',
          '#label' => $bundle_info['label'],
          
foreach ($bundles as $bundle_name => $bundle_info) {
        $bundle_options[$bundle_name] = $bundle_info['label'];
      }
      natsort($bundle_options);
      $selected_bundles = array_intersect_key(
        $bundle_options,
        array_filter((array) $configuration['target_bundles'])
      );

      $form['target_bundles'] = [
        '#type' => 'checkboxes',
        '#title' => $entity_type->getBundleLabel(),
        '#options' => $bundle_options,
        '#default_value' => (array) $configuration['target_bundles'],
        '#required' => TRUE,
        '#size' => 6,
        '#multiple' => TRUE,
        '#element_validate' => [[static::class, 'elementValidateFilter']],
        '#ajax' => TRUE,
        '#limit_validation_errors' => [],
      ];

      $form['target_bundles_update'] = [
        
return '';
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $entityTypeId = $this->revision->getEntityTypeId();
    $entityStorage = $this->entityTypeManager->getStorage($entityTypeId);
    $entityStorage->deleteRevision($this->revision->getRevisionId());

    $bundleLabel = $this->getBundleLabel($this->revision);
    $messengerArgs = [
      '@type' => $bundleLabel ?? $this->revision->getEntityType()->getLabel(),
      '%title' => $this->revision->label(),
    ];
    if ($this->revision instanceof RevisionLogInterface) {
      $messengerArgs['%revision-date'] = $this->dateFormatter->format($this->revision->getRevisionCreationTime());
      $this->messenger->addStatus($this->t('Revision from %revision-date of @type %title has been deleted.', $messengerArgs));
    }
    else {
      $this->messenger->addStatus($this->t('Revision of @type %title has been deleted.', $messengerArgs));
    }

    
$container->get('entity_type.manager')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      if ($entity_type->hasKey('bundle')) {
        $this->derivatives[$entity_type_id] = $base_plugin_definition;
        $this->derivatives[$entity_type_id]['label'] = $entity_type->getBundleLabel();
        $this->derivatives[$entity_type_id]['provider'] = $entity_type->getProvider();
        $this->derivatives[$entity_type_id]['context_definitions'] = [
          $entity_type_id => EntityContextDefinition::fromEntityType($entity_type),
        ];
      }
    }
    return $this->derivatives;
  }

}
    // removal.     $this->assertSession()->pageTextContains('node.type.' . $node_type->id());
    $this->assertSession()->pageTextContains('field.field.node.' . $node_type->id() . '.body');
    $this->assertSession()->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.teaser');
    $this->assertSession()->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.default');
    $this->assertSession()->pageTextContains('core.entity_form_display.node.' . $node_type->id() . '.default');

    // Attempt to import configuration and verify that an error message appears     // and the node type, body field and entity displays are still scheduled for     // removal.     $this->submitForm([], 'Import all');
    $validation_message = "Entities exist of type {$node->getEntityType()->getLabel()} and {$node->getEntityType()->getBundleLabel()} {$node_type->label()}. These entities need to be deleted before importing.";
    $this->assertSession()->pageTextContains($validation_message);
    $this->assertSession()->pageTextContains('node.type.' . $node_type->id());
    $this->assertSession()->pageTextContains('field.field.node.' . $node_type->id() . '.body');
    $this->assertSession()->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.teaser');
    $this->assertSession()->pageTextContains('core.entity_view_display.node.' . $node_type->id() . '.default');
    $this->assertSession()->pageTextContains('core.entity_form_display.node.' . $node_type->id() . '.default');

    // Delete the node and try to import again.     $node->delete();
    $this->submitForm([], 'Import all');
    $this->assertSession()->pageTextNotContains($validation_message);
    
    $sanitized_id = ArgumentPluginBase::encodeValidatorId($this->definition['id']);
    $entity_type = $this->entityTypeManager->getDefinition($entity_type_id);

    // If the entity has bundles, allow option to restrict to bundle(s).     if ($entity_type->hasKey('bundle')) {
      $bundle_options = [];
      foreach ($this->entityTypeBundleInfo->getBundleInfo($entity_type_id) as $bundle_id => $bundle_info) {
        $bundle_options[$bundle_id] = $bundle_info['label'];
      }

      $form['bundles'] = [
        '#title' => $entity_type->getBundleLabel() ?: $this->t('Bundles'),
        '#default_value' => $this->options['bundles'],
        '#type' => 'checkboxes',
        '#options' => $bundle_options,
        '#description' => $this->t('If none are selected, all are allowed.'),
      ];
    }

    // Offer the option to filter by access to the entity in the argument.     $form['access'] = [
      '#type' => 'checkbox',
      '#title' => $this->t('Validate user has access to the %name', ['%name' => $entity_type->getLabel()]),
      
    $ids = \Drupal::entityQuery('field_config')
      ->condition('id', $this->baseEntityType . '.', 'STARTS_WITH')
      ->execute();
    return $this->storage->loadMultiple($ids);
  }

  /** * {@inheritdoc} */
  public function getFilterLabels() {
    $info = parent::getFilterLabels();
    $bundle = $this->baseEntityInfo->getBundleLabel() ?: $this->t('Bundle');
    $bundle = mb_strtolower($bundle);

    $info['placeholder'] = $this->t('Enter field or @bundle', ['@bundle' => $bundle]);
    $info['description'] = $this->t('Enter a part of the field or @bundle to filter by.', ['@bundle' => $bundle]);

    return $info;
  }

  /** * {@inheritdoc} */
  
        if ($bundle_of = $entity_type->getBundleOf()) {
          // Work out if there are entities with this bundle.           $bundle_of_entity_type = $this->entityTypeManager->getDefinition($bundle_of);
          $bundle_id = ConfigEntityStorage::getIDFromConfigName($config_name$entity_type->getConfigPrefix());
          $entity_query = $this->entityTypeManager->getStorage($bundle_of)->getQuery();
          $entity_ids = $entity_query->condition($bundle_of_entity_type->getKey('bundle')$bundle_id)
            ->accessCheck(FALSE)
            ->range(0, 1)
            ->execute();
          if (!empty($entity_ids)) {
            $entity = $this->entityTypeManager->getStorage($entity_type_id)->load($bundle_id);
            $event->getConfigImporter()->logError($this->t('Entities exist of type %entity_type and %bundle_label %bundle. These entities need to be deleted before importing.', ['%entity_type' => $bundle_of_entity_type->getLabel(), '%bundle_label' => $bundle_of_entity_type->getBundleLabel(), '%bundle' => $entity->label()]));
          }
        }
      }
    }
  }

}

      if ($entity_type->isRevisionable()) {
        $fields[$entity_type->getKey('langcode')]->setRevisionable(TRUE);
      }
      if ($entity_type->isTranslatable()) {
        $fields[$entity_type->getKey('langcode')]->setTranslatable(TRUE);
      }
    }
    if ($entity_type->hasKey('bundle')) {
      if ($bundle_entity_type_id = $entity_type->getBundleEntityType()) {
        $fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('entity_reference')
          ->setLabel($entity_type->getBundleLabel())
          ->setSetting('target_type', $bundle_entity_type_id)
          ->setRequired(TRUE)
          ->setReadOnly(TRUE);
      }
      else {
        $fields[$entity_type->getKey('bundle')] = BaseFieldDefinition::create('string')
          ->setLabel($entity_type->getBundleLabel())
          ->setRequired(TRUE)
          ->setReadOnly(TRUE);
      }
    }

    


  /** * Tests the ::getBundleLabel() method. * * @covers ::getBundleLabel * @dataProvider providerTestGetBundleLabel */
  public function testGetBundleLabel($definition$expected) {
    $entity_type = $this->setUpEntityType($definition);
    $entity_type->setStringTranslation($this->getStringTranslationStub());
    $this->assertEquals($expected$entity_type->getBundleLabel());
  }

  /** * Provides test data for ::testGetBundleLabel(). */
  public function providerTestGetBundleLabel() {
    return [
      [['label' => 'Entity Label Foo'], 'Entity Label Foo bundle'],
      [['bundle_label' => 'Bundle Label Bar'], 'Bundle Label Bar'],
    ];
  }

  
$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;
  }

  
'::save',
    ];
    return $form;
  }

  /** * {@inheritdoc} */
  public function submitForm(array &$form, FormStateInterface $form_state) {
    $revisionId = $this->revision->getRevisionId();
    $revisionLabel = $this->revision->label();
    $bundleLabel = $this->getBundleLabel($this->revision);
    if ($this->revision instanceof RevisionLogInterface) {
      $originalRevisionTimestamp = $this->revision->getRevisionCreationTime();
    }

    $this->revision = $this->prepareRevision($this->revision, $form_state);

    if (isset($originalRevisionTimestamp)) {
      $date = $this->dateFormatter->format($originalRevisionTimestamp);
      $this->messenger->addMessage($this->t('@type %title has been reverted to the revision from %revision-date.', [
        '@type' => $bundleLabel,
        '%title' => $revisionLabel,
        
Home | Imprint | This part of the site doesn't use cookies.