Problem/Motivation
Project Browser has a need to expose "follow-up" tasks for recipes; see #3322601-10: Make ModuleActivator expose a Configure follow-up task for modules which have one.
Core definitely should not have opinions about what kind of information a recipe might choose to expose to Project Browser, or any other module. But it should allow that information to be exposed, if a recipe chooses to. However, the validation of recipe.yml is currently very, very strict and doesn't allow any extra data.
Proposed resolution
Composer solved this problem by supporting an extra property in composer.json. The extra property, if it exists, is generally ignored by Composer; the stuff in it is usually only of interest to specific plugins and add-ons.
Let's borrow that same concept for recipes. We should allow something like this in recipe.yml:
extra:
project_browser:
# Some arbitrary stuff here
another_module:
# More other arbitrary stuff here
extra is always optional, but if it is defined, it has only two rules:
- It must be an associative array
- Its keys need to be valid module names. By "valid", I mean here that they need to follow the form of a valid extension name (i.e., match
\Drupal\Core\Extension\ExtensionDiscovery::PHP_FUNCTION_PATTERN). They do not need to be the name of an installed extension, or even an extant one.
As long as extra follows those rules, the recipe can have anything it wants in there.
The Recipe object will also get a new getExtra($module_name) method. It will not be possible to get the full contents of extra; it's internally namespaced to maintain the separation between different modules' use of extra data, and to prevent discourage accidental APIs from emerging.
Issue fork drupal-3503190
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:
- 3503190-allow-recipes-to
changes, plain diff MR !11043
Comments
Comment #2
phenaproximaComment #3
phenaproximaComment #4
phenaproximaComment #5
thejimbirch commentedComment #7
phenaproximaComment #8
quietone commentedComment #9
phenaproximaComment #10
thejimbirch commentedThe code in the MR looks good and the tests make sense.
My only concern is
"extra" field. Since fields are things already in Drupal, and we have a heavy lift educating folks around recipes, could we user "properties"? I don't want to bike shed or anything, just trying to lower the confusion.Comment #11
thejimbirch commentedI hit save too soon. Properties are what composer.json uses
https://getcomposer.org/doc/04-schema.md#properties
Comment #12
phenaproximaComment #13
thejimbirch commentedComment #14
phenaproximaComment #15
alexpottCommitted and pushed c92120799c4 to 11.x and b436c8c9c47 to 11.1.x. Thanks!
Backported to 11.1.x as it is pure addition, recipes is still experimental and helps unblock features for Drupal CMS.