Skip to main content
Image
Drupal Recipe Module Drupal Latest Initiative - Recipes OpenSense Labs

Drupal Recipe Module: What Is It & How It Works?

Drupal

Drupal 11 is now available, bringing new standards. The latest version combines code and design to enhance user experience. It features updates like CKEditor Autoformat and better block management, all designed for a smoother development process. Additionally, there are upgrades to the Drupal Recipe module as well. 

As Drupal grows and changes, the Recipe feature has become a key part of the platform. A Recipe looks at the idea of 'compossibility,' enabling users to build a Drupal website that meets their unique needs or, at the very least, offers a strong starting point.

In this blog, we’ll discuss Drupal 11’s Drupal Recipe module and how to best use it.   

If you are thinking about moving from your current content management system to Drupal, please check out our migration services before you continue.

Migrate To Drupal

Let us begin! 

Drupal Recipes Initiative: What Is It?  

The introduction of the Drupal icon into a sauté pan represents a new initiative by Drupal known as Drupal Recipes. This tool is intended for site builders and developers, allowing them to improve the functionality of a Drupal site.  

Drupal Recipes is similar to a cooking recipe. Drupal Recipes provides a set of ready-made configurations and components that help add new features easily. By using these recipes, developers can quickly create and improve Drupal sites while following best practices and encouraging code reuse.

Drupal Recipes can be added, removed, or mixed with different features at any point in the Drupal application's life. For instance, if you have a recipe for a specific type of site, like a blog or an online store, you can use it as a base for new projects. This approach saves time and ensures consistency across all your sites.

Drupal recipes offer more flexibility compared to distributions. While distributions are a collection of Drupal and other software components that are set up to work well together without much change, Drupal recipes allow you to easily replace or upgrade parts of your system. This means you are not stuck with a fixed setup.

Components Of A Recipe: 

  1. Profiles: These are ready-made setups meant for certain tasks, serving as the base of a recipe.  

  1. Features: Essential elements that enhance your site, like contact forms or online shopping options.  

  1. Configuration Keys: Every recipe has configuration keys that help with the setup, including:  

  • Name: The title of the recipe.  

  • Description: A summary of what the recipe does.  

  • Type: Classifies the recipe (e.g., Site, Content-Type, Feature). 

  • Install Instructions: Guidelines for organizing components.  

  • Config Actions: Guidelines for adjusting the look and functions of the site.

    Drupal Recipe Module Drupal Recipes Initiative OpenSense Labs

Also Check Out: 

  1. Plug & Play with New Drupal Recipes 
  2. Drupal 11: Eleven Changes & Updates In Drupal 11 
  3. Drupal 7 End Of Life: Top Reasons You Should Migrate To Drupal 10 
  4. What to do with your Drupal 7 website? 

Drupal Recipe Module: How To Install? 

Drupal Recipes focus on configuration, and are ‘declarative, not functional.’ Drupal Recipes can also be used with other Drupal recipes. For instance, a Drupal recipe that performs a specific task can be used with another Drupal recipe that does something different.   

Drupal Recipes can add modules with code, but they don’t include any code themselves. They utilize the configuration, not the code. When you install a Drupal recipe, it becomes part of your configuration. Also, there’s nothing to upgrade; hence, an upgrade path is unnecessary.  

A recipe will have a folder similar to a Drupal module. Let's look at its folder layout. It includes a recipe.yml file and a configuration folder for your config files. Now, let's explore the details of the recipe.yml file structure: 

  • It starts by defining the recipe’s name, which is ‘Event’ in this case, and its type, labeled as “Content-type.”   

  • This also shows if the recipe is looking for other Drupal recipes. For instance, it looks for the "Event manager" recipe, which creates a user role with that name on the Drupal site and is located in the same folder as the "Event" recipe.   

  • The recipe then adds any necessary modules that are not yet installed on the website. In this case, it installs the Datetime range and Node modules. 

  • Lastly, there are Config Actions, this feature is powerful for changing an existing configuration. In this example, the config actions modify the ‘user.role.event_manager’ configuration by adding permissions to edit and delete any event content.  

You can create a full "Event" system by combining several smaller Drupal recipes into one larger recipe.

 

Drupal Recipe Module Recipe.yml File Structure OpenSense Labs

Configuring Drupal to Apply Recipes

This blog outlines the necessary steps to set up a Composer-based Drupal installation in preparation for the application of Drupal recipes.

## Composer.json Configuration

### Composer Installers Extender

If your project lacks the composer-installers-extender plugin, please refer to the instructions available at https://github.com/oomphinc/composer-installers-extender to install it initially.

This package defines new install types for Composer, allowing packages of various types to be installed in distinct locations within your project directory. Without this configuration, packages will default to being installed in the project vendor folder.

To proceed, include `drupal-recipe` in the `installer-types` section of the repository's composer.json extra section.

"extra": {
    "installer-types": [
        "drupal-library",
        "npm-asset",
        "bower-asset",
        "quicksilver-script",
        "drupal-recipe"
    ],
}

This instructs the composer to anticipate a new "type" specified in the recipe's composer.json file, referred to as `drupal-recipe`.

Additionally, include in the extra section of the repository's composer.json.

"web/recipes/contrib/{$name}": ["type:drupal-recipe"]
 "installer-paths": {
        "web/core": ["type:drupal-core"],
        "web/libraries/{$name}": [
            "type:drupal-library",
            "type:bower-asset",
            "type:npm-asset"
        ],
        "web/modules/contrib/{$name}": ["type:drupal-module"],
        "web/profiles/contrib/{$name}": ["type:drupal-profile"],
        "web/themes/contrib/{$name}": ["type:drupal-theme"],
        "drush/contrib/{$name}": ["type:drupal-drush"],
        "web/private/scripts/quicksilver/{$name}/": ["type:quicksilver-script"],
        "web/recipes/contrib/{$name}": ["type:drupal-recipe"]
    },

This instructs the composer to install a Drupal-recipe type package in the web/recipes/contrib/ folder when it is found.

Understanding the recipe.yml File 

At a minimum, a recipe.yml file contains name and description keys. In addition to these, it can include three main sections:

  • Installing Packages (install Key) - The install Key specifies the modules and themes that should be installed when the Recipe is applied. If they are not already installed, Drupal will automatically install them. Example:

  install:
  # Install primary module.
  - password_policy
  # Install submodules.
  - password_policy_characters
  - password_policy_history
  - password_policy_length

Drupal Recipes Module Installing Packages OpneSense Labs

  • Managing Configuration (config Key) - The config Key allows you to import and modify configurations in two ways:
  1. Importing Configurations:
  • Use "*" to import all base and optional configurations from a module.

  • Specify individual configurations to be imported selectively.

  • Example:

config:
  import:
    password_policy:
      # Add Password Policy Settings
      - password_policy.settings
      # Add Password Policy fields.
      - field.field.user.user.field_last_password_reset
      - field.field.user.user.field_password_expiration
      - field.field.user.user.field_pending_expire_sent
      - field.storage.user.field_last_password_reset
      - field.storage.user.field_password_expiration
      - field.storage.user.field_pending_expire_sent
      # The 90-day policy is imported by default from this recipe's config folder.

Drupal Recipes Module Importing Configurations OpneSense Labs

Drupal Recipes Module Importing Configurations OpneSense Labs 2

2. Updating Existing Configurations (actions Key): When updating imported configurations or modifying existing ones, the actions key is used. Example:

config:
  actions:
    # Adds Two new fields to the user form. The third field is hidden by default.
    core.entity_form_display.user.user.default:
      setComponents:
        -
          name: field_last_password_reset
          options:
            type: datetime_default
            weight: 4
            region: content
            settings: {  }
            third_party_settings: {  }
        -
          name: field_password_expiration
          options:
            type: boolean_checkbox
            weight: 3
            region: content
            settings:
              display_label: true
            third_party_settings: {  }

3. Managing Dependencies on Other Recipes (recipes Key) - If the current Recipe depends on other Recipes, they can be specified under the recipes key. This ensures they are applied before the current Recipe is executed. Example:

recipes:
  - core/recipes/example

This structured approach helps maintain modular, reusable, and manageable configurations within Drupal Recipes.

Drupal Recipe Module: How To Unpack Recipes?

This composer plugin facilitates the extraction of a package's dependencies into the composer and lock files located in the project root, specifically for implementation within Drupal recipes.

To ensure the proper functioning of this plugin, it is essential that the recipe functionality is enabled and configured within the Drupal core. This functionality can be integrated by applying the provided patch. For further details on how to apply the patch and to stay updated, please consult the Drupal recipe project page.

Installation 

The installation process can be accomplished using Composer by including this package as a development dependency:

1. Include the Git repositories in the list of project repositories as outlined below:

{
    "type": "vcs",
    "url": "https://gitlab.ewdev.ca/yonas.legesse/drupal-recipe-unpack.git"
}

2. Execute the installation of the package along with the recipe:

composer require ewcomposer/unpack:dev-master

Upon utilizing Composer version 2.2 or above, the system will request your authorization to permit this plugin to run code. For the plugin to operate effectively, it is essential to grant this permission.

Once permission is granted, Composer will automatically insert the following snippet into your composer.json file:

{
    "config": {
        "allow-plugins": {
            "ewcomposer/unpack": true,
        }
    }
}

Before upgrading to Composer 2.2, if you are using a version earlier than 2.2, you can include the permission flag by executing the following command:

composer config allow-plugins.ewcomposer/unpack true

Execute The Command

After applying a Drupal recipe to your project, execute the command below to unpack and update the dependencies specified in the recipe's composer.json file to the project's root composer and lock files.

# For a drupal recipe with name drupal_recipe/startup_recipe
composer unpack drupal_recipe/startup_recipe

Compatibility

This plugin is compatible with:

  • PHP 7.x and 8.x
  • Composer ˆ1.8 and 2.x

Roadmap

The existing functionality permits the automatic extraction of a package's dependencies into the root composer file of the project. Below is a comprehensive list of the intended features:

1. An unpack command that transfers all package requirements into the project's composer.json file.

2. A configuration option within composer.json that designates which types of packages should be automatically unpacked, i.e., unpacked upon being required or updated. For example:

{
    "config": {
        "drupal-recipe": {
            "auto-unpack": true,
        }
    }
}

3. A configuration setting defined in composer.json that indicates which packages are to be unpacked recursively. Example:

composer unpack --recursive drupal-recipe/RECIPE

4. A configuration setting that determines whether the recipe requirement is removed after unpacking. Example:

{
    "config": {
        "drupal-recipe": {
            "unpack-remove-recipe": true,
        }
    }
}

Drupal Recipe Module: How To Create A Drupal Recipe? 

To create a recipe, follow these steps:  

  1. Start Your Repository: Make a repository to organize and manage your recipes easily. 

  1. Outline Your Recipe Format: At the very least, have a recipe.yml file.  

  • List the modules you want to install under the install key.  

  • You can also add other recipes under the recipes key for better organization.  

  1. Here’s an example of a recipe.yml layout: 

 Drupal Recipe Module Example Recipe yml Structure 1 OpenSense Labs

Example of a Drupal Recipe to install a module with custom configs 
Code Structure 

Drupal Recipe Module Example Recipe.yml Structure 2 OpenSense Labs

Here, there are a total of three files  
Recipe.yml 
Composer.json 
Advagg.settings.yml 
 

Drupal Recipe Module Example Recipe.yml Structure 3 OpenSense Labs

Drupal Recipe Module Example Recipe.yml Structure 4 OpenSense Labs

Drupal Recipe Module Example Recipe.yml Structure 5 OpenSense Labs

This is an easy example of using a recipe.  
Here, we install a module through composer.json and activate it using the install in recipe.yml. 

For custom settings, we keep our personalized configurations in the config folder, which are imported when we set up our recipe. 

Drupal Recipe Module: How It Works? 

To explain, let's say you want to create an Event feature. Here, you will use an ‘Events Content-Type' Recipe to establish an Event content type with the needed attributes and fields. This will also set up views, metatags, and paths for the Event content. This approach gives you a strong starting point, as 70-80% of the basic setup and configurations are handled by the Recipe.  

After that, you can customize additional settings to meet your needs. Once you apply the Recipe, you won't need it anymore, and you can remove it from your project while keeping all the configurations in place.

Before we move further in this blog, ensure a smooth transition to Drupal 10 with our expert services. Migrate to Drupal 10 before it’s too late! 

Migrate to Drupal 

Drupal Recipe Module: How Can It Benefit You? 

Drupal Recipes provides a lot of benefits, like addressing issues with distributions by providing greater modularity. Rather than combining everything, Drupal Recipes allows you to select only the features you need, preventing the excess of unneeded Drupal modules. 

Let’s have a look at some more benefits of using Drupal Recipes:    

  1. Modular Setup: Drupal Recipes enable the addition of specific features or settings at any stage of a project. 

  1. Merge Different Drupal Recipes: You can easily mix or change Drupal recipes to suit your needs. This creates a more flexible site-building experience, helping you adjust to new demands. 

  1. No Lock-In: Drupal Recipes offer more flexibility compared to distributions, allowing you to change or upgrade parts of your setup without being stuck in a fixed system. 

  1. Composable: You can mix different Drupal recipes, making it simple to create new ones. If you need both Event registration and Commerce features, you can easily make a new recipe that includes both the Event and Commerce recipes.

Drupal Recipe MOdule Benefits of using Drupal Recipes OpenSense Labs

Drupal 11 Recipes: How Is It Different From Drupal 10? 

With Drupal 10, the Drupal Recipe module brought a new method to replace old distributions and install profiles. This Drupal Recipe module was designed for Drupal 10 and allowed for flexible and site-specific installations. Users could efficiently create custom setups by separating them from their original base. However, the Distributions and Recipes Initiative in Drupal 10 was in its beginning phase. 

The Drupal Recipe module in Drupal 10 allowed users to quickly add functions to their website using a set of ready-made settings. A recipe can include anything configurable in Drupal, from a basic content type to a complete set of features. You can make your Drupal recipes to share or use, or you can use Drupal recipes made by other Drupal users. While Drupal recipes are still experimental in this version, they are functional and stable in version 11.1. 

Recipes in Drupal 11 is an updated version for site builders and developers. They provide more flexibility, modularity, and easier maintenance than traditional installation profiles and distributions. When starting a new Drupal site or adding features, Recipes makes managing the configuration simple and efficient. 

Drupal Recipes are changing to make Drupal site development faster and better for meeting new needs. This will help make Drupal easier and more powerful for everyone.  

You can either create them from the ground up or use Drupal Recipes. It's up to you! 

Also Check Out:  

  1. SDC: Integrating Storybook & Single Directory Component 
  2. DrupalCon Barcelona: 2024 Wrap-Up From Europe 
  3. RFP: How To Create An RFP For Open Source Solutions? 
  4. Drupal's Omnichannel Capabilities: Enhancing Customer Engagement and Experience 

Key Takeaways

  1. Drupal Recipes provides a set of ready-made configurations and components that can be used to effectively add new features. 

  2. Drupal Recipes can be added, removed, or mixed with different features at any point in the Drupal application's lifecycle. 

  1. After applying the Recipe, it is no longer needed and can be removed from the project while retaining all the configurations. 

  1. Drupal Recipes provide greater flexibility than distributions, enabling you to modify or upgrade components of your setup without being confined to a set system. 

  1. Drupal 11 recipes offer greater flexibility, modularity, and simpler maintenance compared to traditional installation profiles and distributions. 

 

Subscribe

Ready to start your digital transformation journey with us?

Related Blogs

Drupal Debug: Effective Techniques And Tools 

Drupal Debugging Techniques Drupal Debug OpenSense Labs

Today, we will discuss how to do Drupal Debug. This means getting the tools and methods to turn complex issues into workable…

Drupal SDC v/s Storybook: What’s The Difference?

Drupal SDC Storybook Difference Between SDC And Storybook OpenSense Labs

One helps you set up your UI components, and the other allows you to work with them. we are exploring Single Directory…

Starshot: Drupal’s New CMS Initiative

Drupal Starshot Initiative OpenSense Labs

The Drupal community is excited about the Drupal Starshot project, which aims to update and improve the Drupal experience…