Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

field-create: Skip the field-widget option if no widgets are available #5187

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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