#17 - Composer in your module to load PHP libraries
Closed this issue · 1 comments
amansrivastava commented
Objective
In this session, we will see how we could leverage composer,and composer-merge-plugin to load PHP libraries / SDKs in our custom modules
Exercise
- Create a custom module.
- Update the module’s composer.json file to include this library https://packagist.org/packages/guhelski/forecastphp
- Install wikimedia/composer-merge-plugin. Run composer update in root such that the mentioned library is fetched to the vendor folder and autoloaded and hence is available for use in your module.
- Build a custom block with a configuration form that takes latitude and longitude in the configuration form.
- The block, when enabled should show the forecast for the configured location by a simple text as "Forecast is XXXXX with temperature of XXX deg C". This forecast information is retrieved using Forecast wrapper library that we included.
- API Key you could use = 7411b0e6d5e0c99fbd7405fd6de00cd5 (Alternatively, you could register on forecast.io for the key).
amansrivastava commented
wikimedia/composer-merge-plugin
is not required any more.
This is deprecated in Drupal 9.
Custom modules can be added by adding custom path in repositories
in root composer.json
file.
"custom-modules": {
"type": "path",
"url": "docroot/modules/custom/*"
}