Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src-symfony-compatibility/v6/Style/DrushStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,22 +108,28 @@ public function suggest(string $label, array|\Closure $options, string $placehol
/**
* Allow the user to search for an option.
*
* @param \Closure(string): array<int|string, string> $options
* @param \Closure(string): array<int|string, string>|array $options
* @param true|string $required
*/
public function search(string $label, \Closure $options, string $placeholder = '', int $scroll = 10, ?\Closure $validate = null, string $hint = '', bool|string $required = true): int|string
public function search(string $label, \Closure|array $options, string $placeholder = '', int $scroll = 10, ?\Closure $validate = null, string $hint = '', bool|string $required = true): int|string|null
{
if (is_array($options)) {
$options = fn (?string $query) => array_filter($options, fn ($option) => str_contains(strtolower($option), strtolower((string) $query)));
}
return (new SearchPrompt($label, $options, $placeholder, $scroll, $validate, $hint, $required))->prompt();
}

/**
* Allow the user to search for multiple option.
*
* @param \Closure(string): array<int|string, string> $options
* @param \Closure(string): array<int|string, string>|array $options
* @return array<int|string>
*/
public function multisearch(string $label, \Closure $options, string $placeholder = '', int $scroll = 10, bool|string $required = false, ?\Closure $validate = null, string $hint = 'Use the space bar to select options.'): array
public function multisearch(string $label, \Closure|array $options, string $placeholder = '', int $scroll = 10, bool|string $required = false, ?\Closure $validate = null, string $hint = 'Use the space bar to select options.'): array
{
if (is_array($options)) {
$options = fn (?string $query) => array_filter($options, fn ($option) => str_contains(strtolower($option), strtolower((string) $query)));
}
return (new MultiSearchPrompt($label, $options, $placeholder, $scroll, $required, $validate, $hint))->prompt();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ConfiguresPrompts.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ function () use ($prompt) {
}

return array_filter(
$style->choice($prompt->label, ['' => 'None', ...$options], '', true),
$style->choice($prompt->label, ['' => 'None', ...$options], null, true),
fn ($option, $key) => $key !== '',
ARRAY_FILTER_USE_BOTH,
);
Expand Down
2 changes: 1 addition & 1 deletion src/Commands/core/ImageCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function interactFlush(InputInterface $input, $output): void
$styles_all = $styles;
array_unshift($styles_all, 'all');
$choices = array_combine($styles_all, $styles_all);
$style_names = $this->io()->select(dt("Choose a style to flush"), $choices, 'all', scroll: 20);
$style_names = $this->io()->{count($choices) > 20 ? 'search' : 'select'}(dt("Choose a style to flush"), $choices, 'all', scroll: 20);
if ($style_names == 'all') {
$style_names = implode(',', $styles);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/field/EntityTypeBundleAskTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ protected function askEntityType(): ?string
: $entityTypeDefinition->getLabel();
}

if (!$answer = $this->io()->select('Entity type', $choices, required: true)) {
if (!$answer = $this->io()->search('Entity type', $choices, required: true)) {
throw new \InvalidArgumentException(dt('The entityType argument is required.'));
}

Expand Down Expand Up @@ -71,7 +71,7 @@ protected function askBundle(): ?string
$choices[$bundle] = $label;
}

if (!$answer = $this->io()->select('Bundle', $choices)) {
if (!$answer = $this->io()->search('Bundle', $choices)) {
throw new \InvalidArgumentException(dt('The bundle argument is required.'));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/field/FieldBaseOverrideCreateCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ protected function askFieldName(string $entityType): ?string
$choices[$definition->getName()] = $label;
}

return $this->io()->select('Field name', $choices);
return $this->io()->search('Field name', $choices);
}

protected function askFieldLabel(string $default): string
Expand Down
6 changes: 3 additions & 3 deletions src/Commands/field/FieldCreateCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ protected function askExistingFieldName(): ?string
return null;
}

return $this->io()->select('Choose an existing field', $choices);
return $this->io()->search('Choose an existing field', $choices);
}

protected function askFieldName(): string
Expand Down Expand Up @@ -324,7 +324,7 @@ protected function askFieldType(): string
$choices[$definition['id']] = $label;
}

return $this->io()->select('Field type', $choices, scroll: 25);
return $this->io()->search('Field type', $choices, scroll: 25);
}

protected function askFieldWidget(): ?string
Expand Down Expand Up @@ -355,7 +355,7 @@ protected function askFieldWidget(): ?string

$default = $this->input->getOption('show-machine-names') ? key($choices) : current($choices);

return $this->io()->select('Field widget', $choices, $default);
return $this->io()->search('Field widget', $choices, $default);
}

protected function askRequired(): bool
Expand Down
4 changes: 2 additions & 2 deletions src/Commands/field/FieldEntityReferenceHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function askReferencedEntityType(): string
$choices[$name] = $label;
}

return $this->io()->select('Referenced entity type', $choices);
return $this->io()->search('Referenced entity type', $choices);
}

protected function askReferencedBundles(string $targetType): ?array
Expand All @@ -114,6 +114,6 @@ protected function askReferencedBundles(string $targetType): ?array
$choices[$bundle] = $label;
}

return $this->io()->multiselect('Referenced bundles', $choices);
return $this->io()->multisearch('Referenced bundles', $choices);
}
}
4 changes: 2 additions & 2 deletions src/Commands/field/FieldTextHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,12 @@ protected function hasAllowedFormats(?string $fieldType = null): bool
protected function askAllowedFormats(): array
{
$formats = filter_formats();
$choices = ['_none' => '- None -'];
$choices = [];

foreach ($formats as $format) {
$choices[$format->id()] = $format->label();
}

return $this->io()->multiselect('Allowed formats', $choices, ['_none']);
return $this->io()->multisearch('Allowed formats', $choices);
}
}