Problem/ Motivation

As part of the Drupal 8 port, we want to make sure that Composer Manager handles our dependency of the Mobile_detect library.

Solution

Write a patch to integrate the dependency from Mobile_detect.

Here are great documentation on how to integrate Composer Manager with Drupal 8 .
Here is the Mobile_detect library in the packagist - https://packagist.org/packages/mobiledetect/mobiledetectlib

Here is some usefull information about composer.json https://getcomposer.org/doc/04-schema.md

Comments

darol100 created an issue. See original summary.

darol100’s picture

Assigned: Unassigned » darol100

I will give this a shot, assign it to myself.

darol100’s picture

Assigned: darol100 » Unassigned
Status: Active » Needs review
StatusFileSize
new759 bytes

Here is the first patch. To test it out you need to run composer drupal/mobile_detect inside of the project. This will download the mobile_detect library with composer.

In the future, I think we should add the hook_requirements to make sure that this project can not be install unless we have the library. What you guys think about this ?

Here is an example of hook_requirements from the address project.

/**
 * Implements hook_requirements().
 */
function address_requirements($phase) {
  $requirements = [];
  if ($phase == 'install') {
    if (!class_exists('\CommerceGuys\Addressing\Repository\AddressFormatRepository')) {
      $requirements['addressing_library'] = [
        'description' => t('Address requires the commerceguys/addressing library.'),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }

  return $requirements;
}

Maybe we should wait until we have a class from #2627514: Create a service to load the Mobile_Detect library and they implement the hook_requirements

jmolivas’s picture

Status: Needs review » Reviewed & tested by the community

I test the composer.json file:

Using:
composer validate

And got a valid output:
./composer.json is valid

darol100’s picture

The current patch from #3 will save the Mobile_Detect library into a vendor directory inside of the module. My question should we make this available in to the vendor directory or some place else where the code can be reuse just in case ? Similar of what libraries api where we use to add things on sites/all/libraries.

mpdonadio’s picture

Composer Manager will search out composer.json files in modules and add them to the root composer.json via the merge plugin. A `composer drupal-update` will then install everything. What the address module does is a good model. See also https://bojanz.wordpress.com/2015/09/18/d8-composer-definitive-intro/

darol100’s picture

Composer Manager will search out composer.json files in modules and add them to the root composer.json via the merge plugin.

I had the same conversation with @Crell and other people in IRC. I did not that composer manager did that.

@mpdonadio, Do you think we need to add this extra composer information ?

 "replace": {
    "drupal/core": "~8.0"
  },
  "minimum-stability": "dev",
  "prefer-stable": true,
  "extra": {
    "merge-plugin": {
      "include": [
        "core/composer.json"
      ],
      "recurse": false,
      "replace": false,
      "merge-extra": false
    }
  }

I took this code from https://bojanz.wordpress.com/2015/09/18/d8-composer-definitive-intro/

darol100’s picture

Issue summary: View changes
Status: Reviewed & tested by the community » Needs review
StatusFileSize
new1.42 KB
new1.25 KB

I use the devel composer.json and the address composer.json as an example and re-roll the entire patch with more useful information. Also, I fix the license because I thought that the license was base of the library and it should be base of the project. I can confirm that the patch have been validate if I run
composer validate.

Also, if I install and configure composer_manager and run composer drupal-update it download the library into the root vendor directory.

I do not think none this is need it.

"replace": {
    "drupal/core": "~8.0"
  },
"prefer-stable": true,
  "extra": {
    "merge-plugin": {
      "include": [
        "core/composer.json"
      ],
      "recurse": false,
      "replace": false,
      "merge-extra": false
    }
  }
darol100’s picture

StatusFileSize
new1.37 KB
new338 bytes

Removing this ...

"replace": {
    "drupal/core": "~8.0"
  }
,

From #8 patch because is not need it.

  • darol100 committed c42a25e on 8.x-2.x
    Issue #2627482 by darol100: Integration with Composer Manager
    
darol100’s picture

Assigned: Unassigned » mpdonadio

I push #9 patch into the 8.x branch. So we can start moving on with other patches that are dependent on this patch.

There does not seem to be like a real example on how to use a composer.json with Drupal 8 on Drupal.org documentation pages. There are little of information all over the place.

I ended up doing couple things with this patch:

I'm going to leave as "Needs Review" and assigned it to @mpdonadio for one last review just in case you will like to change something.

darol100’s picture

Title: Integration with Composer Manager » Integration with Composer
Assigned: mpdonadio » Unassigned
Status: Needs review » Fixed

I have to change the title because ... I do not think this is necessary directly with "Composer Manager" instead to Composer. I have pushed this into the 8.x.2 branch.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.