www.drupaleurope.org axelerant.com 1
Lesser known perks of using composer Drupal Europe 2018 axelerant.com 2
Drupal + Technology TRACK SUPPORTED BY axelerant.com 3
Special Thanks to.. axelerant.com 4
Mohit Aghera Drupal developer @Axelerant Drupal.org: mohit_aghera Twitter: @mohit_rocks axelerant.com 5
Quick Introduction Why do we need it? ● How do we use it? ● axelerant.com 6
Drupal Composer initiative Follow updates here: https://www.drupal.org/project/ideas/issues/2958021 axelerant.com 7
Composer scripts Define script in composer.json and run ● Helps to automate tasks ● Supports various events. ● axelerant.com 8
Composer Scripts axelerant.com 9
Composer Plugins Helps to overcome limitation of composer scripts ● Run independently - irrespective of root package ● Helps in creating distributable package ● axelerant.com 10
{ Composer "name": "my/plugin-package", "type": "composer-plugin", Plugins "require": { "composer-plugin-api": "^1.1" ● “type” : “composer-plugin” }, ● “extra” : Contains class name "extra": { ● Add special package called "class": "My\\Plugin" “composer-plugin-api” } } axelerant.com 11
Composer Plugins drupal- composer/drupal -scaffold axelerant.com 12
Composer Plugins axelerant.com 13
Patching Requirement to update core of system ● Bugs that are not merged ● axelerant.com 14
Patching axelerant.com 15
Keeping data up to date Pull and process remote data automatically ● Implement Composer Plugins ● axelerant.com 16
Keeping data up to date Benefits: No need to have separate sync code ● Helps to solve problems in continuous integration as data will already be there ● Limitations: It is meant for retrieving and storing data - no live sync. ● axelerant.com 17
Commit Hooks axelerant.com 18
Commit Hooks GIT hooks helps to enforce code quality ● Ensure commit messages are proper ● Coding standards validation ● Sharing GIT hooks with composer has more advantages ● axelerant.com 19
Commit Hooks There are several libraries that supports this type of implementations: https://github.com/sebastianfeldmann/captainhook ● https://github.com/bruli/php-git-hooks ● https://github.com/php-composter/php-composter ● https://github.com/BrainMaestro/composer-git-hooks ● axelerant.com 20
axelerant.com 21
Automatting project structure Composer helps to generate essential files and other code ● Use case : drupal-composer/drupal-project ● axelerant.com 22
Automatting project structure axelerant.com 23
Example from “ScriptHandler.php” axelerant.com 24
Thank you.. axelerant.com 25
Become a Drupal contributor, Friday from 9 AM ● First timers workshop ● Mentored contribution ● General contribution 26 axelerant.com 26
Recommend
More recommend