Problem/Motivation
Trying my first recipe with an input and tried to use the prompt type "askHidden", which is listed as supported in \Drupal\Core\Recipe\Recipe and in https://git.drupalcode.org/project/distributions_recipes/-/blob/1.0.x/do....
However when attempting to apply a recipe, an error is displayed.
This is because the ConsoleInputCollector always provides "default" as a parameter to the prompt method, but askHidden is the only prompt that does not take the $default named parameter and fails with a PHP Error.
Error:
Error: Unknown named parameter $default in /var/www/html/webroot/core/lib/Drupal/Core/Recipe/ConsoleInputCollector.php on line 105
#0 /var/www/html/webroot/core/lib/Drupal/Core/Recipe/InputConfigurator.php(154): Drupal\Core\Recipe\ConsoleInputCollector->collectValue()
#1 /var/www/html/webroot/core/lib/Drupal/Core/Recipe/RecipeCommand.php(76): Drupal\Core\Recipe\InputConfigurator->collectAll()
#2 /var/www/html/vendor/symfony/console/Command/Command.php(279): Drupal\Core\Recipe\RecipeCommand->execute()
#3 /var/www/html/vendor/symfony/console/Application.php(1076): Symfony\Component\Console\Command\Command->run()
#4 /var/www/html/vendor/symfony/console/Application.php(342): Symfony\Component\Console\Application->doRunCommand()
#5 /var/www/html/vendor/symfony/console/Application.php(193): Symfony\Component\Console\Application->doRun()
#6 /var/www/html/webroot/core/scripts/drupal(32): Symfony\Component\Console\Application->run()
#7 {main}
Steps to reproduce
- Prepare a Drupal installation.
- Add a directory
recipes/askhidden - Add a recipe.yml
ddev ssh- Run
cd web - Run
php core/scripts/drupal recipe ../recipes/askhidden -v
I used the following minimal recipe to reproduce.
name: 'Ask Hidden Test'
description: 'Provides a minimal example for askHidden prompt.'
type: 'Test'
input:
foo:
data_type: string
description: 'Foo'
prompt:
method: askHidden
arguments:
question: 'What is foo?'
default:
source: value
value: 'bar'
config:
strict: false
Omitting arguments or trying to provide arguments.default does not matter. The same error is thrown.
Switching to "ask" works.
Proposed resolution
Do not provide a 'default' key to the arguments when the method is askHidden. This is the only prompt that does not take the named parameter default.
Remaining tasks
- Review approach and kernel test
- Commit
User interface changes
No
Introduced terminology
No
API changes
No
Data model changes
No
Release notes snippet
Issue fork drupal-3517481
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
mradcliffeBut not all of them do so adding default here causes the error for askHidden.
Comment #3
mradcliffeAdded the Needs tests issue tag. I think the recipe.yml above could be used. We don't need to install anything. We only need to confirm the recipe is applied message is displayed to the user.
Comment #4
mradcliffeWe can add a test recipe in
core/tests/fixtures/recipesandDrupal\KernelTests\Core\Recipe\InputTestwould be a good place to either add a new kernel test?Comment #6
mradcliffeRemoves Needs tests tag after I wrote a test. Removes Documentation tag because this is not a documentation issue.
Comment #7
smustgrave commentedNot as familiar with the recipe code as I'd like but looking at the summary it does line up with the MR
Shows the test coverage.
So I believe this should be good.
Comment #8
alexpottCommitted and pushed b43aae5dd67 to 11.x and 88dc606eba6 to 11.2.x and 8c347d75fe6 to 11.1.x. Thanks!
Comment #12
alexpott