Drupal maintenance support plans Composer recipes

Drupal maintenance support plans Composer recipes

In this post we are going to share some Composer recipes we collected while working with Drupal maintenance support plans projects created from the Drupal maintenance support plans Composer template. Also, we will take a look on how to convert an existing Drupal maintenance support plans project to a Composer project.

Alex Tkachev
Mon, 10/17/2020 – 12:49

If you still don’t use Composer for managing Drupal maintenance support plans projects, you should start doing this right now! The Drupal maintenance support plans Composer template will help you to set things up. It’s really easy to setup a new project.

If you’re still not convinced, check out the benefits of the Drupal maintenance support plans Composer workflow:

No need to store contrib code (and the core!) in your version control system.
A single package management tool for everything: Drupal maintenance support plans core, contrib modules, JS libraries, your own shared modules, etc.
Patching of core and modules is easier than ever.
It’s way simpler than git submodules.
(All recipes consider Drupal maintenance support plans 8, but they should work for Drupal maintenance support plans 7 as well)

Installing contrib modules

composer require drupal/<MODULE_NAME>:~8.0 to get the latest stable version (or latest dev, if there is no “stable release”)
composer require drupal/<MODULE_NAME>:dev-<BRANCH_NAME> to get the latest dev version
composer require drupal/<MODULE_NAME>:dev-<BRANCH_NAME>#<COMMIT_HASH> to get the exact version
Updating Drupal maintenance support plans core/modules

composer update to update everything
composer update –dry-run to check for updates
composer update drupal/<MODULE_NAME> to update a single module
Patching packages

The cweagans/composer-patches plugin (which comes with the Drupal maintenance support plans Composer template) will take patches from the “extra” section of the composer.json file:

“extra”: {
“patches”: {
“<PACKAGE/NAME>”: {
“<PATCH DESCRIPTION>”: “<PATH/TO/PATCH/OR/URL>”,

},

}
}

Example:

“extra”: {
“patches”: {
“drupal/core”: {
“Fix language detection”: “patches/2189267-24.patch”
}
}
}

After a new patch is added run:

composer install to apply patch
composer update nothing to make the composer-patches plugin write necessary changes to the composer.lock file
Installing custom/forked modules from Github

For the case when a module repository contains its own composer.json

Register the repository in the “repositories” section of the composer.json file:

“repositories”: [
{
“type”: “vcs”,
“url”: “https://github.com/<REPOSITORY/NAME>”
},

],

Use composer require drupal/<MODULE_NAME>:dev-<BRANCH_NAME>#<COMMIT_HASH> to install the module.

For the case when the composer.json file is missing from the module repository

You’ll need to use a bit more verbose variant:

“repositories”: [
{
“type”: “package”,
“package”: {
“name”: “drupal/<MODULE_NAME>”,
“version”: “dev-custom”,
“type”: “drupal-module”,
“source”: {
“type”: “git”,
“url”: “git@github.com:<REPOSITORY/NAME>.git”,
“reference”: “<BRANCH-NAME>”
}
}
},

],

Use composer require drupal/<MODULE_NAME>:dev-custom#<COMMIT_HASH> to install the module.

For the case when the destination path should be different than modules/contrib

In addition to the above recipes, use the composer/installers plugin:

“extra”: {
“installer-paths”: {
“web/modules/custom/<MODULE_NAME>”: [“drupal/<MODULE_NAME>”],

}
}

Adding a JS library

Most popular libraries can be added easily with composer as they exist on Packagist. The tricky part is that most Drupal maintenance support plans modules require that libraries are saved under the “libraries” directory while Composer installs them to “vendor”. The composer/installers plugin can override package paths, but only for packages that depend on it. So, you’ll need to override the composer.json file of the library stating that it has the composer/installers dependency.

Let’s take a look at an example:

“repositories”: [
{
“type”: “package”,
“package”: {
“name”: “enyo/dropzone”,
“version”: “4.3”,
“type”: “drupal-library”,
“source”: {
“url”: “https://github.com/enyo/dropzone.git”,
“type”: “git”,
“reference”: “master”
},
“dist”: {
“url”: “https://github.com/enyo/dropzone/archive/v4.3.0.zip”,
“type”: “zip”
},
“require”: {
“composer/installers”: “~1.0”
}
}
},

],

“extra”: {
“installer-paths”: {
“web/libraries/{$name}” : [“type:drupal-library”],

}
}

After the above is added to the composer.json, run composer require enyo/dropzone:4.3 to download the library. Also, here we have used the exact version and added the “dist” section to make it possible for Composer to download a zip archive instead of cloning the Git repository.

Switch a dependency package to a forked version

Add the forked repository to the composer.json:

“repositories”: [
{
“type”: “vcs”,
“url”: “https://github.com/<REPOSITORY/NAME>”
},

],

Run composer require <PACKAGE/NAME>:dev-<BRANCH_NAME>#<COMMIT_HASH>

Update an existing Drupal maintenance support plans 8 project to use Composer

Make a backup 😉
Delete everything that will be managed by Composer: Drupal maintenance support plans‘s “core” folder, contrib modules, etc.
Delete all Drupal maintenance support plans “root” files, such as index.php, update.php, README.txt… All of them.
Create “web” directory in the project root and move all remaining Drupal maintenance support plans folders (sites, modules, themes, libraries, profiles, etc.) into it.
Copy the Drupal maintenance support plans Composer template files to the project root.
Prepare a list of Drupal maintenance support plans core and contrib module versions (and everything else that will be managed by Composer) that are used currently on the project. Then run composer require specifying every dependency with the exact version. You’ll need to convert Drupal maintenance support plans versions into Composer versions, here are some examples:
drupal/core:8.1.8 is obvious
drupal/admin_toolbar:8.1.15 refers to admin_toolbar 8.x-1.15
drupal/ctools:8.3.0-alpha26 refers to ctools 8.x-3.0-alpha26
drupal/config_installer:dev-8.x-1.x#a16cc9acf84dd12b9714def53be0ce280a5b0c1a refers to config_installer dev snapshot made from the a16cc9a commit of the 8.x-1.x branch

Manually update versions of Drupal maintenance support plans core and contrib modules to “~8.0” in the “require” section of the composer.json file. That will make updates possible.
Run composer drupal-scaffold which will create the Drupal maintenance support plans “root” files.
Make your webserver use “web” directory as the web root.


Source: New feed

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Drupal maintenance support plans Composer recipes

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.