HomeServiceContact
Drupal
min read
November 9, 2023
November 9, 2023

Introduction to Drupal recipes

Introduction to Drupal recipes
Table of contents

Drupal is a versatile framework that is known for its capability and flexibility to build a wide range of websites. But, building a Drupal site often involves starting with a blank canvas which can be time-consuming and sometimes overwhelming.

Imagine if you could choose from a menu of 'recipes' tailored for specific needs, like creating a blog, news site, or e-commerce platform, to kickstart your Drupal project. It would make projects easier and much faster. That’s exactly what Drupal recipes do.

In this blog, we will consider three significant aspects; What are Drupal recipes? Why are they essential, and how you can use them to your advantage?

What are Drupal recipes

Drupal recipes are sets of predefined configurations and components that simplify web development in Drupal. They help streamline the process of creating Drupal projects, ensuring you follow best practices and reuse components. With recipes, developers can efficiently start and fine-tune their websites.

The foundation of recipes

Profiles: These are pre-configured site setups designed for specific purposes, forming the base of your recipe.

Features: Consider features as the building blocks that add functions to your site, anything from contact forms to e-commerce capabilities.

Distributions: Think of distributions as ready-made theme parks for your website. They combine Drupal with specific profiles and features, creating a complete package for specific project types.

Drupal recipe configuration keys

Drupal recipe configuration keys are just like keys on a treasure map, each one unlocking a unique aspect of your web development journey. These keys are guides to simplifying the development process.

Let's take a look at them:

Name:This is the label that tells us what the recipe is called.

Description: A short explanation of what the recipe is meant to achieve.

Type: This categorizes the recipe as "Site," "Content-Type," or "Feature," guiding the nature of your project.

Install: This is a set of instructions for arranging the components.

Config: Your rulebook for customizing the site, covering appearance, functionality, and hidden features.

Actions: Secret commands that instruct Drupal to perform specific tasks, adding value to your projects.

Why Drupal recipes matter

Streamlining development

Imagine you're an architect designing a new building. Instead of starting from scratch, you have a library of pre-designed floor plans, blueprints, and resources at your disposal. This not only saves you time but also ensures your project starts on a strong foundation. That's precisely the advantage Drupal recipes bring to web development.

Ensuring best practices

In web development, certain guidelines and recommended settings are crucial. Drupal recipes act like a handy checklist of these best practices. They make sure that your site building starts with the necessary components configured correctly, preventing potential issues in the future.

Encouraging reusability

Consider Drupal recipes as reusable templates. When you've created a recipe for a particular site type (blog or an e-commerce store), you can use it as a foundation for future projects. This not only saves time but also ensures consistency across all your sites.

How to use Drupal recipes

Now that we understand the significance of Drupal recipes and what they are, let's explore how to utilize them effectively.

Crafting a recipe

Creating a Drupal recipe involves picking the right modules and configurations for your project. Think of it like selecting the ideal template for your masterpiece. You mix and match the components that best suit your site's requirements.

Installation process

With your recipe prepared, the next step is to apply it to your Drupal installation. This process is similar to following a well-structured plan. Drupal handles the site configuration as per the recipe's instructions. It's a quick and efficient procedure that ensures your site starts on a firm footing.

Now, let’s create a sample Drupal recipe to kickstart your web projects.

Create a Drupal project

Before we craft our recipe, let's ensure we have the necessary setup. Here's how to install Drupal recipes:

On your command line, go to your web server's root directory, and initiate a new Drupal project using Composer.

Use the following command:


composer create-project drupal/recommended-project my-drupal-site

This will create a new Drupal site in a directory named "my-drupal-site."

Now, navigate to your new Drupal site's directory:


cd my-drupal-site

Install Drupal using Drush (Drupal Shell):


composer require drush/drush
vendor/bin/drush site-install minimal

This will set up a basic Drupal website, which serves as the foundation for our recipe.

You must apply a patch before you can begin with the recipes.

Step 1


"patches": { "drupal/core": { "Allow recipes to be applied": "https://git.drupalcode.org/project/distributions_recipes/-/raw/patch/recipe.patch" } },

Step 2


composer require oomphinc/composer-installers-extender:2.0.1

Step 3


"installer-types": ["drupal-recipe"], "installer-paths": { // existing entries omitted... "docroot/recipes/contrib/{$name}": [ "type:drupal-recipe" ] }

When you request Composer for a recipe, it will automatically place it in your project's recipes/contrib directory, similar to how it handles modules or themes.

A sample recipe

The following recipe depends on my-custom recipe, which is unique. "Underinstall" offers several modules that can be activated during recipe import. It determines which configurations from the recipe's config directory should be loaded after enabling the modules.


name: 'Drupal Base'
description: 'A recipe tailored to best practices for kickstarting a new Drupal 10 project.'
type: 'Site'

install:
  - config
  - node
  - user
  - text
  - link
  - filter
  - block
  - block_content
  - ckeditor5
  - contextual
  - menu_link_content
  - datetime
  - block_content
  - editor
  - image
  - menu_ui
  - options
  - path
  - dynamic_page_cache
  - big_pipe
  - taxonomy
  - dblog
  - toolbar
  - field_ui
  - media
  - media_library
  - views
  - views_ui
  - automated_cron
  - claro
  - gin
  - gin_login
  - gin_toolbar
  - config_ignore
  - pathauto
  - memcache
  - redirect
  - robotstxt
  - menu_block
  - csp
  - metatag
  - metatag_open_graph
  - metatag_verification

config:
  import:
    dblog: '*'
    image: '*'
    media: '*'
    media_library: '*'
    pathauto: '*'
    redirect:
      - redirect.settings
      - system.action.redirect_delete_action
      - views.view.redirect
    node:
      - views.view.content
    user:
      - views.view.user_admin_people
    gin:
      - gin.settings
      - block.block.gin_breadcrumbs
      - block.block.gin_content
      - block.block.gin_local_actions
      - block.block.gin_messages
      - block.block.gin_page_title
      - block.block.gin_primary_local_tasks
      - block.block.gin_secondary_local_tasks
  actions:
    block.block.gin_admin:
      simple_config_update:
        status: false
    block.block.gin_branding:
      simple_config_update:
        status: false
    block.block.gin_local_actions:
      simple_config_update:
        region: content
        weight: -10
    block.block.gin_local_tasks:
      simple_config_update:
        status: false
    block.block.gin_page_title:
      simple_config_update:
        region: header
        weight: -10
    block.block.gin_primary_local_tasks:
      simple_config_update:
        region: header
        weight: -5
    block.block.gin_tools:
      simple_config_update:
        status: false
    node.settings:
      simple_config_update:
        use_admin_theme: true
    user.settings:
      simple_config_update:
        register: admin_only
    automated_cron.settings:
      simple_config_update:
        interval: 0
    system.theme:
      simple_config_update:
        admin: 'gin'
        default: 'stark'

This my-custom-recipe.yml file will be included when you import a drupal-base recipe.

The composer.json from the recipe will also be considered, and the necessary modules will be downloaded during the import process.


name: 'Example recipe'
description: "An example Drupal recipe description"
type: 'Content type'
install:
  - gin
  - gin_login
  - gin_toolbar
config:
  import:
    gin:
      - gin.settings
      - block.block.gin_breadcrumbs
      - block.block.gin_content
      - block.block.gin_local_actions
      - block.block.gin_messages
      - block.block.gin_page_title
      - block.block.gin_primary_local_tasks
      - block.block.gin_secondary_local_tasks
  actions:
    block.block.gin_admin:
      simple_config_update:
        status: false
    block.block.gin_branding:
      simple_config_update:
        status: false
    block.block.gin_local_actions:
      simple_config_update:
        region: content
        weight: -10
    block.block.gin_local_tasks:
      simple_config_update:
        status: false
    block.block.gin_page_title:
      simple_config_update:
        region: header
        weight: -10
    block.block.gin_primary_local_tasks:
      simple_config_update:
        region: header
        weight: -5
    block.block.gin_tools:
      simple_config_update:
        status: false

Next, command to run the recipe script.


php core/scripts/drupal recipe recipes/contrib/drupal-base

Customization and expansion

After using the recipe, you can further customize your Drupal site, just like how an artist adds their unique touch to a canvas. You have the freedom to enhance features, adjust settings, and even create your own custom modules to shape it into exactly what you envision.

Useful resources

Exploring the New “Recipes” Feature in Drupal 10

The Recipes Initiative

Github next-drupal-starterkit

Conclusion

To sum it up, Drupal recipes are the key to making Drupal web development more efficient and reliable. They accelerate the development process, ensure best practices, and promote reusability. By understanding why, what, and how to use recipes, you can easily create impressive websites.

Whether you're an experienced Drupal developer or just starting your journey in web development, harness the potential of Drupal recipes and watch your projects succeed like never before!

Written by
Editor
No art workers.
We'd love to talk about your business objectives