Extend
Extending and Configuring Drupal for web applications can be challenging at first and requires many adjustments. However, recipes simplify the process by offering a set of ready-to-install configurations to be applied to your installation.
Making Drupal ready to use as a headless CMS is not the exception, and for this reason, recipes are the best way to help you start your next Drupal decoupled implementation.
Drupal recipes had been added to the core as experimental in 10.3 and above. The following instructions will be based on this assumption.
Preparing Drupal
This guide shows how to install a Drupal decoupled recipe according to the recipes Initiative
We will follow as guide a setup using drupal/recommended-project as a template for illustration purposes.
Configure composer.json
Some modules of our recipes are still in active development; for this reason, changing the minimum-stability of composer is necessary to download all dependencies.
ddev composer config minimum-stability --merge --json "dev"lando composer config minimum-stability --merge --json "dev"Ignoring downloaded recipes
If you start a git repository of your project, you will find that the recipe is downloaded, and since this is managed by composer, you’ll want to exclude the /recipes path.
echo "/recipes" >> .gitignoreRequire the recipe
ddev composer require octahedroid/drupal-decoupled-graphql-basic-recipelando composer require octahedroid/drupal-decoupled-graphql-basic-recipeApplying the recipe
Recipes are applied using core’s PHP Drupal script. In your CLI, cd into your webroot, and run the following command:
ddev exec -d /var/www/html/web php core/scripts/drupal recipe ../recipes/drupal-decoupled-graphql-basic-recipecd web && \lando php core/scripts/drupal recipe ../recipes/drupal-decoupled-graphql-basic-recipe && \cd ..Unpacking the recipe and making it part of your installation
This is an optional step. However, these recipes are intended to be a starting point for your Drupal project, and we strongly recommend unpacking the recipe and, with that, integrating the dependencies into your main project’s composer.json file.
ddev composer config allow-plugins.ewcomposer/unpack trueddev composer config repo.recipe-unpack vcs https://github.com/woredeyonas/Drupal-Recipe-Unpack.gitddev composer require ewcomposer/unpack:dev-masterlando composer config allow-plugins.ewcomposer/unpack truelando composer config repo.recipe-unpack vcs https://github.com/woredeyonas/Drupal-Recipe-Unpack.gitlando composer require ewcomposer/unpack:dev-masterThe https://github.com/woredeyonas/Drupal-Recipe-Unpack composer plugin can be run after you apply a recipe.
The plugin is not on Packagist, so you must first install the repository in your site, adding the following lines to your site’s composer.json file at the repositories section.
{ "type": "vcs", "url": "https://github.com/woredeyonas/Drupal-Recipe-Unpack.git"}Require the package.
ddev composer require ewcomposer/unpack:dev-masterWhen using Composer 2.2 or higher, Composer will ask for your permission to allow this plugin to execute code.
Add the following lines to your site’s composer.json file at the config > allow-plugins section.
{ "config": { "allow-plugins": { "ewcomposer/unpack": true } }}Unpack the recipe
Unpack the recipe with the following command.
ddev composer unpack octahedroid/drupal-decoupled-graphql-basic-recipelando composer unpack octahedroid/drupal-decoupled-graphql-basic-recipeAfter this, the dependencies have been added to your main composer.json, then we just need a cleanup of the recipe and remove the downloaded files
ddev composer installlando composer installThe recipe is now part of your project, and you can continue setting up your front end application.
Drupal Decoupled recipes
Here is a set of recipes according to the recipes initiative, designed to configure Drupal as a headless CMS ready to be integrated with a Frontend application.
- drupal-decoupled-graphql-advanced-recipe: Advanced recipe, this is a turnkey and ready to use solution.
- drupal-decoupled-graphql-basic-recipe: Basic recipe, this is a starting point based on the standard installation profile.