Drupal core recipes should use the createIfNotExists action where possible to allow for better composability and reusability

Created on 1 July 2024, 5 months ago
Updated 3 July 2024, 5 months ago

Problem/Motivation

Because core's recipe uses the config folder to create the configuration, the recipe cannot be re-applied because that configuration already exists in the Drupal site.

This is bad as two recipes cannot depend on the same recipe, as is expected to be possible. This will quickly become apparent in Starshot when users try to add more "site feature" recipes on top of their "site" recipes.

Steps to reproduce

Create two recipes that have dependencies on core/recipes/image_media_type
Apply the first
Then, apply the second and verify it fails.

Proposed resolution

Rework the standard recipes to to use the createIfNotExists (formerly ensure_exist) config action to create the needed configs.

This is already done in the administrator_role and content_editor_role recipes.

Recreating all of the configs using this method may not be completely possible now. We will most likely need additional config actions, a lot of which are being worked on in πŸ“Œ Determine which core config entity methods should be config actions Fixed .

Remaining tasks

Doing it.

User interface changes

N/A

API changes

TBD

Data model changes

TBD

Release notes snippet

TBD

✨ Feature request
Status

Active

Version

11.0 πŸ”₯

Component
recipe systemΒ  β†’

Last updated about 18 hours ago

Created by

πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

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

Merge Requests

Comments & Activities

  • Issue created by @thejimbirch
  • Pipeline finished with Failed
    5 months ago
    Total: 596s
    #214805
  • Pipeline finished with Canceled
    5 months ago
    Total: 482s
    #214836
  • Pipeline finished with Canceled
    5 months ago
    #214848
  • Pipeline finished with Canceled
    5 months ago
    #214854
  • Pipeline finished with Canceled
    5 months ago
    Total: 261s
    #214855
  • Pipeline finished with Failed
    5 months ago
    Total: 543s
    #214863
  • Status changed to Needs review 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    Drupal core' Standard recipes have been converted from importing configuration from the /config folder, to being created only if they do not exist via the createIfNotExists config action. This allows multiple recipes to depend on, and build upon these recipes.

    To validate, apply each recipe twice.

  • Pipeline finished with Failed
    5 months ago
    Total: 597s
    #214887
  • Pipeline finished with Failed
    5 months ago
    Total: 510s
    #214920
  • Pipeline finished with Failed
    5 months ago
    Total: 658s
    #214934
  • Pipeline finished with Failed
    5 months ago
    Total: 1360s
    #214952
  • Pipeline finished with Failed
    5 months ago
    #214973
  • Pipeline finished with Failed
    5 months ago
    Total: 512s
    #214986
  • Pipeline finished with Failed
    5 months ago
    Total: 600s
    #214993
  • Status changed to Needs work 5 months ago
  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Appears the standard install recipe test is failing.

  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    Adding some ideas for tests. This is the first. If I try applying core's recipes to a site that has been created with the standard profile, or re-applying recipes, I get the following errors:

    1. Install Standard

    2. Apply core/recipes/article_comment

    The configuration 'core.entity_form_display.node.article.default' exists already and does not match the recipe's configuration

    3. Apply core/recipes/article_tags

    The configuration 'core.entity_form_display.node.article.default' exists already and does not match the recipe's configuration

    4. Apply core/recipes/basic_block_type

    The configuration 'field.field.block_content.basic.body' exists already and does not match the recipe's configuration

    5. Apply core/recipes/basic_html_format_editor

    The configuration 'filter.format.basic_html' exists already and does not match the recipe's configuration

    6. Apply core/recipes/comment_base

    The configuration 'field.field.comment.comment.comment_body' exists already and does not match the recipe's configuration

    7. Apply core/recipes/core_recommended_admin_theme

    The configuration 'system.theme' exists already and does not match the recipe's configuration

    8. Apply core/recipes/core_recommended_front_end_theme

    The configuration 'system.theme' exists already and does not match the recipe's configuration

    8. Apply core/recipes/feedback_contact_form

    The configuration 'contact.form.feedback' exists already and does not match the recipe's configuration

    9. Apply core/recipes/full_html_format_editor

    The configuration 'filter.format.full_html' exists already and does not match the recipe's configuration

    10. Apply core/recipes/page_content_type

    The configuration 'field.field.node.page.body' exists already and does not match the recipe's configuration

    11. Apply core/recipes/standard

    The configuration 'field.field.block_content.basic.body' exists already and does not match the recipe's configuration

    12. Apply core/recipes/standard_responsive_images

    The configuration 'image.style.max_1300x1300' exists already and does not match the recipe's configuration

    13. Apply core/recipes/tags_taxonomy

    The configuration 'taxonomy.vocabulary.tags' exists already and does not match the recipe's configuration

  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts
  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    There are couple of problems here:

    Drupal does not recognize when the config is identical. I wrote a recipe and applied it. When I immediately tried to apply it again, I got "The configuration 'CONFIG_ID' exists already and does not match the recipe's configuration". The config cannot have actually changed. I suspect this is because of key order, which often makes big diffs on config export even when nothing has changed.

    When applying a recipe, I should be able to overwrite the existing config. The point of applying a recipe is to get the config to be a particular way. If the config exists but is different from what the recipe calls for, I should have the option to have the site use the recipe's version. It should probably be the default to do this this way. Otherwise, Drupal will say that the recipe has been installed when in fact at least some of what the recipe calls for will not have been done.

  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts

    @liam

    Take a look at πŸ› Recipes' imported config is validated too strictly by default Active that was just added to 10.4 and 11. That provides more leniency for configuration files from modules and the config folder.

    This issue should be closed as the referenced issue is a much better solution than using createIfNotExists as it is a pretty dumb config action and really only checks for existence of the ID/config file itself, not the actual attributes in the file.

  • πŸ‡ΊπŸ‡ΈUnited States thejimbirch Cape Cod, Massachusetts
  • πŸ‡¨πŸ‡¦Canada Liam Morland Ontario, CA πŸ‡¨πŸ‡¦

    Thanks for your reply, @thejimbirch.

    I have opened a ticket regarding the first issue I mention in #7; see πŸ› Drupal does not recognize when the config is identical Active .

    Regarding the second issue, I write about a possible solution in #3478669-5: Consider making recipes' comparison with existing config lenient by default β†’ .

Production build 0.71.5 2024