diff --git a/src-symfony-compatibility/v6/Style/DrushStyle.php b/src-symfony-compatibility/v6/Style/DrushStyle.php index 2efbabf814..8f51b6a90c 100644 --- a/src-symfony-compatibility/v6/Style/DrushStyle.php +++ b/src-symfony-compatibility/v6/Style/DrushStyle.php @@ -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 $options + * @param \Closure(string): array|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 $options + * @param \Closure(string): array|array $options * @return array */ - 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(); } diff --git a/src/Commands/ConfiguresPrompts.php b/src/Commands/ConfiguresPrompts.php index 0afbae202a..31059ae120 100644 --- a/src/Commands/ConfiguresPrompts.php +++ b/src/Commands/ConfiguresPrompts.php @@ -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, ); diff --git a/src/Commands/core/ImageCommands.php b/src/Commands/core/ImageCommands.php index 87f7636594..f3b0a09ec4 100644 --- a/src/Commands/core/ImageCommands.php +++ b/src/Commands/core/ImageCommands.php @@ -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); } diff --git a/src/Commands/field/EntityTypeBundleAskTrait.php b/src/Commands/field/EntityTypeBundleAskTrait.php index ba973fa858..67a40034d8 100644 --- a/src/Commands/field/EntityTypeBundleAskTrait.php +++ b/src/Commands/field/EntityTypeBundleAskTrait.php @@ -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.')); } @@ -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.')); } diff --git a/src/Commands/field/FieldBaseOverrideCreateCommands.php b/src/Commands/field/FieldBaseOverrideCreateCommands.php index 3106d1198e..9cf33d9edb 100644 --- a/src/Commands/field/FieldBaseOverrideCreateCommands.php +++ b/src/Commands/field/FieldBaseOverrideCreateCommands.php @@ -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 diff --git a/src/Commands/field/FieldCreateCommands.php b/src/Commands/field/FieldCreateCommands.php index cfc98de37e..e14cb5164e 100644 --- a/src/Commands/field/FieldCreateCommands.php +++ b/src/Commands/field/FieldCreateCommands.php @@ -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 @@ -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 @@ -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 diff --git a/src/Commands/field/FieldEntityReferenceHooks.php b/src/Commands/field/FieldEntityReferenceHooks.php index 83c811804e..2aaef6d3c9 100644 --- a/src/Commands/field/FieldEntityReferenceHooks.php +++ b/src/Commands/field/FieldEntityReferenceHooks.php @@ -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 @@ -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); } } diff --git a/src/Commands/field/FieldTextHooks.php b/src/Commands/field/FieldTextHooks.php index 6352d5dd33..96b376338f 100644 --- a/src/Commands/field/FieldTextHooks.php +++ b/src/Commands/field/FieldTextHooks.php @@ -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); } }