Drupal\helper\EntityType
Provides helpers for working with entity types.
Methods
| Name | Description |
|---|---|
| __construct | EntityType constructor. |
| getBundleLabel | Get the label for an entity type's bundle. |
| getBundleOptions | Gets an array of bundle labels for an entity type. |
| getEntityOptions | Get a list of entity options for a select field. |
| getEntityReferenceFieldSelection | Get an entity reference selection handler for an entity reference field. |
| getEntityReferenceSelection | Get an entity reference selection handler. |
EntityType::__construct
Description
public __construct (\Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager, \Drupal\Core\Entity\EntityTypeBundleInfoInterface $entityTypeBundleInfo, \Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface $selectionPluginManager)
EntityType constructor.
Parameters
(\Drupal\Core\Entity\EntityTypeManagerInterface) $entityTypeManager:
The entity type manager.(\Drupal\Core\Entity\EntityTypeBundleInfoInterface) $entityTypeBundleInfo:
The entity type bundle info.(\Drupal\Core\Entity\EntityReferenceSelection\SelectionPluginManagerInterface) $selectionPluginManager:
The entity reference selection plugin manager.
Return Values
void
EntityType::getBundleLabel
Description
public getBundleLabel (string $entity_type_id, string $bundle)
Get the label for an entity type's bundle.
Parameters
(string) $entity_type_id:
The entity type ID.(string) $bundle:
The bundle from the entity.
Return Values
string
The label of the bundle.
EntityType::getBundleOptions
Description
public getBundleOptions (string $entity_type_id)
Gets an array of bundle labels for an entity type.
Parameters
(string) $entity_type_id:
The entity type ID.
Return Values
string[]
An array of bundle labels, keyed by bundle id.
EntityType::getEntityOptions
Description
public getEntityOptions (string $entity_type_id, array|null $properties)
Get a list of entity options for a select field.
Parameters
(string) $entity_type_id:
The entity type ID.(array|null) $properties:
An optional array of properties to use when loading the entities.
Return Values
array|\Drupal\Core\StringTranslation\TranslatableMarkup[]|string[]
The list of entities keyed by entity ID.
EntityType::getEntityReferenceFieldSelection
Description
public getEntityReferenceFieldSelection (\Drupal\Core\Field\FieldDefinitionInterface $fieldDefinition, \Drupal\Core\Entity\EntityInterface|null $entity)
Get an entity reference selection handler for an entity reference field.
Parameters
(\Drupal\Core\Field\FieldDefinitionInterface) $fieldDefinition:
The entity reference field definition.(\Drupal\Core\Entity\EntityInterface|null) $entity:
The current entity context.
Return Values
\Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface
The entity reference selection handler.
Throws Exceptions
\InvalidArgumentException
If the field is not an entity reference field.
EntityType::getEntityReferenceSelection
Description
public getEntityReferenceSelection (string $entity_type_id, string|null $handler, array $settings, \Drupal\Core\Entity\EntityInterface|null $entity)
Get an entity reference selection handler.
Parameters
(string) $entity_type_id:
The entity type ID.(string|null) $handler:
The selection handler plugin ID.(array) $settings:
The selection handler plugin settings.(\Drupal\Core\Entity\EntityInterface|null) $entity:
The current entity context.
Return Values
\Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface
The entity reference selection handler.