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

Command icon 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

mradcliffe created an issue. See original summary.

mradcliffe’s picture

    // Most of the input-collecting methods of StyleInterface have a `default`
    // parameter.
    $arguments += [
      'default' => $default_value,
    ];

But not all of them do so adding default here causes the error for askHidden.

mradcliffe’s picture

Issue summary: View changes
Issue tags: +Needs tests

Added 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.

mradcliffe’s picture

We can add a test recipe in core/tests/fixtures/recipes and Drupal\KernelTests\Core\Recipe\InputTest would be a good place to either add a new kernel test?

mradcliffe’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: -Documentation, -Needs tests

Removes Needs tests tag after I wrote a test. Removes Documentation tag because this is not a documentation issue.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Not as familiar with the recipe code as I'd like but looking at the summary it does line up with the MR

1) Drupal\KernelTests\Core\Recipe\InputTest::testAskHiddenPromptArgumentsForwarded
Failed asserting that exception of type "Error" matches expected exception "ArgumentCountError". Message was: "Unknown named parameter $default" at
/builds/issue/drupal-3517481/core/lib/Drupal/Core/Recipe/ConsoleInputCollector.php:105
/builds/issue/drupal-3517481/core/lib/Drupal/Core/Recipe/InputConfigurator.php:154
/builds/issue/drupal-3517481/core/tests/Drupal/KernelTests/Core/Recipe/InputTest.php:319
.

Shows the test coverage.

So I believe this should be good.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed and pushed b43aae5dd67 to 11.x and 88dc606eba6 to 11.2.x and 8c347d75fe6 to 11.1.x. Thanks!

  • alexpott committed 8c347d75 on 11.1.x
    Issue #3517481 by mradcliffe, smustgrave: askHidden prompt fails with "...

  • alexpott committed 88dc606e on 11.2.x
    Issue #3517481 by mradcliffe, smustgrave: askHidden prompt fails with "...

  • alexpott committed b43aae5d on 11.x
    Issue #3517481 by mradcliffe, smustgrave: askHidden prompt fails with "...
alexpott’s picture

Version: 11.x-dev » 11.1.x-dev

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.