Skip to content

Commit

Permalink
field-create: Skip the field-widget option if no widgets are available (
Browse files Browse the repository at this point in the history
  • Loading branch information
DieterHolvoet committed Jul 20, 2022
1 parent 79d461a commit 11324df
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Drupal/Commands/field/FieldCreateCommands.php
Expand Up @@ -179,7 +179,7 @@ public function create(?string $entityType = null, ?string $bundle = null, array

$this->ensureOption('field-label', [$this, 'askFieldLabel'], true);
$this->ensureOption('field-description', [$this, 'askFieldDescription'], false);
$this->ensureOption('field-widget', [$this, 'askFieldWidget'], true);
$this->ensureOption('field-widget', [$this, 'askFieldWidget'], false);
$this->ensureOption('is-required', [$this, 'askRequired'], false);
$this->ensureOption('is-translatable', [$this, 'askTranslatable'], false);
} else {
Expand All @@ -197,7 +197,7 @@ public function create(?string $entityType = null, ?string $bundle = null, array

$this->ensureOption('field-description', [$this, 'askFieldDescription'], false);
$this->ensureOption('field-type', [$this, 'askFieldType'], true);
$this->ensureOption('field-widget', [$this, 'askFieldWidget'], true);
$this->ensureOption('field-widget', [$this, 'askFieldWidget'], false);
$this->ensureOption('is-required', [$this, 'askRequired'], false);
$this->ensureOption('is-translatable', [$this, 'askTranslatable'], false);
$this->ensureOption('cardinality', [$this, 'askCardinality'], true);
Expand Down Expand Up @@ -294,7 +294,7 @@ protected function askFieldType(): string
return $this->io()->choice('Field type', $choices);
}

protected function askFieldWidget(): string
protected function askFieldWidget(): ?string
{
$formDisplay = $this->getEntityDisplay('form');

Expand All @@ -310,6 +310,11 @@ protected function askFieldWidget(): string
$fieldType = $this->input->getOption('field-type');
$widgets = $this->widgetPluginManager->getOptions($fieldType);

if ($widgets === []) {
$this->io()->comment('No widgets available for this field type. Skipping option.');
return null;
}

foreach ($widgets as $name => $label) {
$label = $this->input->getOption('show-machine-names') ? $name : $label->render();
$choices[$name] = $label;
Expand Down

0 comments on commit 11324df

Please sign in to comment.