Skip to content

Commit

Permalink
Add base-field:info command
Browse files Browse the repository at this point in the history
  • Loading branch information
DieterHolvoet committed Dec 15, 2021
1 parent 5794cdd commit e7977e1
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/Drupal/Commands/core/BaseFieldInfoCommands.php
@@ -0,0 +1,76 @@
<?php

namespace Drush\Drupal\Commands\core;

use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityTypeBundleInfo;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drush\Commands\DrushCommands;

class BaseFieldInfoCommands extends DrushCommands
{
use AskBundleTrait;
use FieldDefinitionRowsOfFieldsTrait;
use ValidateEntityTypeTrait;

/** @var EntityTypeManagerInterface */
protected $entityTypeManager;
/** @var EntityTypeBundleInfo */
protected $entityTypeBundleInfo;
/** @var EntityFieldManagerInterface */
protected $entityFieldManager;

public function __construct(
EntityTypeManagerInterface $entityTypeManager,
EntityTypeBundleInfo $entityTypeBundleInfo,
EntityFieldManagerInterface $entityFieldManager
) {
$this->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);
}
}
8 changes: 8 additions & 0 deletions src/Drupal/Commands/core/drush.services.yml
Expand Up @@ -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:
Expand Down

0 comments on commit e7977e1

Please sign in to comment.