amansrivastava/d9-dev

#17 ­- Composer in your module to load PHP libraries

Closed this issue · 1 comments

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

  1. Create a custom module.
  2. Update the module’s composer.json file to include this library https://packagist.org/packages/guhelski/forecast­php
  3. 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.
  4. Build a custom block with a configuration form that takes latitude and longitude in the configuration form.
  5. 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.
  6. API Key you could use = 7411b0e6d5e0c99fbd7405fd6de00cd5 (Alternatively, you could register on forecast.io for the key).

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/*"
        }