diff --git a/src/Drupal/Commands/core/BaseFieldInfoCommands.php b/src/Drupal/Commands/core/BaseFieldInfoCommands.php new file mode 100644 index 0000000000..e97fab62cd --- /dev/null +++ b/src/Drupal/Commands/core/BaseFieldInfoCommands.php @@ -0,0 +1,76 @@ +entityTypeManager = $entityTypeManager; + $this->entityTypeBundleInfo = $entityTypeBundleInfo; + $this->entityFieldManager = $entityFieldManager; + } + + /** + * List all base fields of an entity type + * + * @command base-field:info + * @aliases base-field-info,bfi + * + * @param string $entityType + * The machine name of the entity type + * + * @option show-machine-names + * Show machine names instead of labels in option lists. + * + * @default-fields field_name,required,field_type,cardinality + * @field-labels + * label: Label + * description: Description + * field_name: Field name + * field_type: Field type + * required: Required + * translatable: Translatable + * cardinality: Cardinality + * default_value: Default value + * default_value_callback: Default value callback + * allowed_values: Allowed values + * allowed_values_function: Allowed values function + * handler: Selection handler + * target_bundles: Target bundles + * @filter-default-field field_name + * @table-style default + * + * @usage drush base-field-info taxonomy_term + * List all base fields. + * @usage drush base-field:info + * List all base fields and fill in the remaining information through prompts. + */ + public function info(string $entityType, array $options = [ + 'format' => 'table', + ]): RowsOfFields + { + $fieldDefinitions = $this->entityFieldManager->getBaseFieldDefinitions($entityType); + + return $this->getRowsOfFieldsByFieldDefinitions($fieldDefinitions); + } +} diff --git a/src/Drupal/Commands/core/drush.services.yml b/src/Drupal/Commands/core/drush.services.yml index e975013360..ecdd39b73b 100644 --- a/src/Drupal/Commands/core/drush.services.yml +++ b/src/Drupal/Commands/core/drush.services.yml @@ -42,6 +42,14 @@ services: - '@entity_type.bundle.info' tags: - { name: drush.command } + base-field.info.commands: + class: \Drush\Drupal\Commands\core\BaseFieldInfoCommands + arguments: + - '@entity_type.manager' + - '@entity_type.bundle.info' + - '@entity_field.manager' + tags: + - { name: drush.command } link.hooks: class: \Drush\Drupal\Commands\core\LinkHooks arguments: