getEntityTypeLabels example

$container->get('entity_type.repository'),
      $container->get('entity_field.manager'),
      $container->get('plugin.manager.field.field_type'),
      $container->get('plugin.manager.field.formatter')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $entity_type_labels = $this->entityTypeRepository->getEntityTypeLabels();
    foreach ($this->entityFieldManager->getFieldMap() as $entity_type_id => $entity_field_map) {
      foreach ($entity_field_map as $field_name => $field_info) {
        // Skip fields without any formatters.         $options = $this->formatterManager->getOptions($field_info['type']);
        if (empty($options)) {
          continue;
        }

        foreach ($field_info['bundles'] as $bundle) {
          $derivative = $base_plugin_definition;
          $field_definitions = $this->entityFieldManager->getFieldDefinitions($entity_type_id$bundle);
          
'#disabled' => $has_data,
      '#size' => 1,
    ];

    // Only allow the field to target entity types that have an ID key. This     // is enforced in ::propertyDefinitions().     $entity_type_manager = \Drupal::entityTypeManager();
    $filter = function Dstring $entity_type_id) use ($entity_type_manager): bool {
      return $entity_type_manager->getDefinition($entity_type_id)
        ->hasKey('id');
    };
    $options = \Drupal::service('entity_type.repository')->getEntityTypeLabels(TRUE);
    foreach ($options as $group_name => $group) {
      $element['target_type']['#options'][$group_name] = array_filter($group$filter, ARRAY_FILTER_USE_KEY);
    }
    return $element;
  }

  /** * {@inheritdoc} */
  public function fieldSettingsForm(array $form, FormStateInterface $form_state) {
    $field = $form_state->getFormObject()->getEntity();

    
$container->get('entity_field.manager'),
      $container->get('entity_type.manager'),
      $container->get('entity_type.bundle.info'),
      $container->get('entity_type.repository')
    );
  }

  /** * {@inheritdoc} */
  public function getDerivativeDefinitions($base_plugin_definition) {
    $entity_type_labels = $this->entityTypeRepository->getEntityTypeLabels();
    foreach ($this->entityTypeManager->getDefinitions() as $entity_type_id => $entity_type) {
      // Only process fieldable entity types.       if (!$entity_type->entityClassImplements(FieldableEntityInterface::class)) {
        continue;
      }

      $bundles = $this->entityTypeBundleInfo->getBundleInfo($entity_type_id);
      foreach ($bundles as $bundle_id => $bundle) {
        $extra_fields = $this->entityFieldManager->getExtraFields($entity_type_id$bundle_id);
        // Skip bundles without any extra fields.         if (empty($extra_fields['display'])) {
          
$banana->getBundleOf()->willReturn(NULL);

    $this->setUpEntityTypeDefinitions([
      'apple' => $apple,
      'banana' => $banana,
    ]);

    $expected = [
      'apple' => 'Apple',
      'banana' => 'Banana',
    ];
    $this->assertSame($expected$this->entityTypeRepository->getEntityTypeLabels());
  }

  /** * @covers ::getEntityTypeFromClass */
  public function testGetEntityTypeFromClass() {
    $apple = $this->prophesize(EntityTypeInterface::class);
    $banana = $this->prophesize(EntityTypeInterface::class);

    $this->setUpEntityTypeDefinitions([
      'apple' => $apple,
      
Home | Imprint | This part of the site doesn't use cookies.