Skip to content

EntityCommands

Provides entity commands.


  • Full name: \Drupal\helper\Drush\Commands\EntityCommands
  • Parent class: DrushCommands

Constants

Constant Visibility Type Value
ENTITY_LOAD_CHUNK_SIZE protected 50
QUERY_CHUNK_SIZE protected 1000

Properties

entityTypeManager

protected \Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager

database

protected \Drupal\Core\Database\Connection $database

moduleHandler

protected \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler

entityFieldManager

protected \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager

entityTypeHelper

protected \Drupal\helper\EntityType $entityTypeHelper

Methods

__construct

public __construct(\Drupal\Core\Entity\EntityTypeManagerInterface $entityTypeManager, \Drupal\Core\Database\Connection $database, \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler, \Drupal\Core\Entity\EntityFieldManagerInterface $entityFieldManager, \Drupal\helper\EntityType $entityTypeHelper): mixed

Parameters:

Parameter Type Description
$entityTypeManager \Drupal\Core\Entity\EntityTypeManagerInterface
$database \Drupal\Core\Database\Connection
$moduleHandler \Drupal\Core\Extension\ModuleHandlerInterface
$entityFieldManager \Drupal\Core\Entity\EntityFieldManagerInterface
$entityTypeHelper \Drupal\helper\EntityType

entityCount

Show a summary of entity counts by bundle.

public entityCount(string $entityTypeId = 'node', array $options = []): \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Parameters:

Parameter Type Description
$entityTypeId string
$options array

entityFieldValue

Shows entities that have a field value or a specific field value.

public entityFieldValue(string $fieldCondition, mixed $fieldValue = null, ?string $operator = null, array $options = []): \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Parameters:

Parameter Type Description
$fieldCondition string
$fieldValue mixed
$operator ?string
$options array

entityFieldMinimumValues

Show entities that have a minimum number of values for a field.

public entityFieldMinimumValues(string $fieldName, int $minimum = 1, array $options = []): \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Parameters:

Parameter Type Description
$fieldName string
$minimum int
$options array

entityFieldIsEmpty

Show entities that do not have a value for a field.

public entityFieldIsEmpty(string $fieldName, array $options = []): \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Parameters:

Parameter Type Description
$fieldName string
$options array

entityFieldTypeValue

Shows entities that have a field value or a specific field value.

public entityFieldTypeValue(mixed $fieldTypes, mixed $fieldValue = null, ?string $propertyName = null, ?string $operator = null): \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Parameters:

Parameter Type Description
$fieldTypes mixed
$fieldValue mixed
$propertyName ?string
$operator ?string

entityTaxonomy

Show a summary of taxonomy term usage.

public entityTaxonomy(string $fieldName): \Consolidation\OutputFormatters\StructuredData\RowsOfFields

Parameters:

Parameter Type Description
$fieldName string

redirects

Show a summary of redirects.

public redirects(): \Consolidation\OutputFormatters\StructuredData\RowsOfFields

loadEntitiesInChunks

Loads entities in chunks to keep memory usage low.

protected loadEntitiesInChunks(\Drupal\Core\Entity\EntityStorageInterface $storage, array $ids): \Generator<int|string,\Drupal\Core\Entity\EntityInterface>

The entity static cache is reset after each chunk, so entities yielded from an earlier chunk should not be used after moving on to the next one.

Parameters:

Parameter Type Description
$storage \Drupal\Core\Entity\EntityStorageInterface
The entity storage.
$ids array
The entity IDs to load.

Return Value:

The loaded entities, keyed by entity ID.


getValidEntityTypesForField

Retrieves a list of valid entity types for a given field.

protected getValidEntityTypesForField(string $fieldName, array $options): string[]

Parameters:

Parameter Type Description
$fieldName string
The name of the field to check for associated entity types.
$options array
An array of options, including a possible 'entity-type' key containing
a list of entity type IDs as a CSV string.

Return Value:

An array of valid entity type IDs for the specified field. If the 'entity-type' option is provided, only the valid subset of the specified entity types is returned.

Throws:

Thrown if the field does not exist or if the 'entity-type' option contains invalid entity type IDs for the field. - InvalidArgumentException


Inherited methods

includeTrashedEntities

Sets a flag to include trashed entities.

public includeTrashedEntities(bool $include = true): $this

Parameters:

Parameter Type Description
$include bool
TRUE to include trashed entities, or FALSE to skip them.

skipTrashedEntities

Skip trashed entities.

public skipTrashedEntities(): $this

executeIgnoringTrash

Executes a callback in the trash 'ignore' context.

protected executeIgnoringTrash(callable $callback): mixed

Entity queries and loads inside the callback will include entities that are in the trash. The previous trash context is restored afterwards. If the Trash module is not installed, or trashed entities are skipped with ::skipTrashedEntities(), the callback is called directly.

Parameters:

Parameter Type Description
$callback callable
The callback to execute.

Return Value:

The return value of the callback.

See Also:

  • \Drupal\trash\TrashManagerInterface::executeInTrashContext()