Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add base-field:info command * WIP tests. * Rename command to field:base-info + change class type hints to interfaces + fix renamed traits + make entityType argument optional * Add tests Co-authored-by: Moshe Weitzman <weitzman@tejasa.com>
- Loading branch information
1 parent
5f44e6f
commit 8730cdb
Showing
4 changed files
with
101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
|
||
namespace Drush\Drupal\Commands\core; | ||
|
||
use Consolidation\OutputFormatters\StructuredData\RowsOfFields; | ||
use Drupal\Core\Entity\EntityFieldManagerInterface; | ||
use Drupal\Core\Entity\EntityTypeBundleInfoInterface; | ||
use Drupal\Core\Entity\EntityTypeManagerInterface; | ||
use Drush\Commands\DrushCommands; | ||
|
||
class FieldBaseInfoCommands extends DrushCommands | ||
{ | ||
use EntityTypeBundleAskTrait; | ||
use EntityTypeBundleValidationTrait; | ||
use FieldDefinitionRowsOfFieldsTrait; | ||
|
||
/** @var EntityTypeManagerInterface */ | ||
protected $entityTypeManager; | ||
/** @var EntityTypeBundleInfoInterface */ | ||
protected $entityTypeBundleInfo; | ||
/** @var EntityFieldManagerInterface */ | ||
protected $entityFieldManager; | ||
|
||
public function __construct( | ||
EntityTypeManagerInterface $entityTypeManager, | ||
EntityTypeBundleInfoInterface $entityTypeBundleInfo, | ||
EntityFieldManagerInterface $entityFieldManager | ||
) { | ||
$this->entityTypeManager = $entityTypeManager; | ||
$this->entityTypeBundleInfo = $entityTypeBundleInfo; | ||
$this->entityFieldManager = $entityFieldManager; | ||
} | ||
|
||
/** | ||
* List all base fields of an entity type | ||
* | ||
* @command field:base-info | ||
* @aliases field-base-info,fbi | ||
* | ||
* @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 field:base-info taxonomy_term | ||
* List all base fields. | ||
* @usage drush field:base-info | ||
* List all base fields and fill in the remaining information through prompts. | ||
* | ||
* @version 11.0 | ||
*/ | ||
public function info(?string $entityType = null, array $options = [ | ||
'format' => 'table', | ||
]): RowsOfFields | ||
{ | ||
$this->input->setArgument('entityType', $entityType = $entityType ?? $this->askEntityType()); | ||
$this->validateEntityType($entityType); | ||
|
||
$fieldDefinitions = $this->entityFieldManager->getBaseFieldDefinitions($entityType); | ||
|
||
return $this->getRowsOfFieldsByFieldDefinitions($fieldDefinitions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters