diff --git a/src/Drupal/Commands/field/FieldCreateCommands.php b/src/Drupal/Commands/field/FieldCreateCommands.php index 6a81d98562..66914e6095 100644 --- a/src/Drupal/Commands/field/FieldCreateCommands.php +++ b/src/Drupal/Commands/field/FieldCreateCommands.php @@ -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 { @@ -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); @@ -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'); @@ -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;