Add a trait for forms that want to collect input on behalf of a recipe

Created on 25 October 2024, 3 months ago

Problem/Motivation

Recipes can accept input, but there is only one way to for a user to provide it: at the command line, either interactively or via drupal recipe FOO --input=FOO.var_name=value.

We need some way to collect recipe inputs in the UI, both to allow Project Browser to apply recipes that require input, and to enable this use case in other situations (for example, during Drupal CMS's installer, if there's a recipe that needs an API key or similar).

Proposed resolution

Create a trait for forms that want to collect input on behalf of recipes. This will have two methods:

  • getRecipeInputForm(): This will go through a recipe's inputs (and those of its dependencies), and for any that define a form setting, it will expose that setting as an element in a tree.
  • collectRecipeInputValues(): This is meant to run on form submission, and will go through a recipe's inputs (and those of its dependencies), setting whatever input values are found in the form state.

This also means that recipe inputs will be able to define how they should be viewable in a form. For example:

input:
  recipient:
    data_type: email
    description: 'The email address that should receive submissions from the feedback form.'
    constraints:
      NotBlank: []
    form:
      '#type': textfield
    prompt:
      method: ask
      arguments:
        question: 'What email address should receive website feedback?'
    default:
      source: config
      config: ['system.site', 'mail']

Everything in the form array will be used to construct the form element - this syntax is similar to what you see in Webform. The element cannot contain sub-elements (this will be validated by the recipe system). If an input doesn't have a form array, it won't be visible in a form at all.

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component

recipe system

Created by

πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024