From 60b896623e12ab7af51ed130d4bb3274f769fa8c Mon Sep 17 00:00:00 2001 From: Liam Morland Date: Tue, 5 Mar 2019 10:36:25 -0500 Subject: [PATCH 1/5] Remove static from $packageTypes --- src/DrupalInfo.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DrupalInfo.php b/src/DrupalInfo.php index e5758f9..0b05d56 100644 --- a/src/DrupalInfo.php +++ b/src/DrupalInfo.php @@ -37,7 +37,7 @@ class DrupalInfo implements PluginInterface, EventSubscriberInterface /** * Package types to process. */ - protected static $packageTypes = [ + protected $packageTypes = [ 'drupal-core', 'drupal-module', 'drupal-profile', @@ -203,7 +203,7 @@ protected function findTimestamp(PackageInterface $package) */ protected function processPackage(PackageInterface $package) { - return in_array($package->getType(), static::$packageTypes); + return in_array($package->getType(), $this->packageTypes); } /** From de769053860a5cd78e72e6935018d8e2a16b861a Mon Sep 17 00:00:00 2001 From: Liam Morland Date: Tue, 5 Mar 2019 10:37:36 -0500 Subject: [PATCH 2/5] Create configuration variable drupal-info-rewrite--additional-packageTypes Allow configuring additional $packageTypes. --- src/DrupalInfo.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/DrupalInfo.php b/src/DrupalInfo.php index 0b05d56..e300403 100644 --- a/src/DrupalInfo.php +++ b/src/DrupalInfo.php @@ -51,6 +51,11 @@ public function activate(Composer $composer, IOInterface $io) { $this->composer = $composer; $this->io = $io; + + $additionalPackageTypes = $this->composer->getConfig()->get('drupal-info-rewrite--additional-packageTypes'); + if (is_array($additionalPackageTypes)) { + $this->packageTypes = array_merge($this->packageTypes, $additionalPackageTypes); + } } /** From 8c270ca2a54b050172dd8a4ac24db50feffe792f Mon Sep 17 00:00:00 2001 From: Liam Morland Date: Tue, 5 Mar 2019 11:17:17 -0500 Subject: [PATCH 3/5] Allow getConfig() to return NULL --- src/DrupalInfo.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/DrupalInfo.php b/src/DrupalInfo.php index e300403..18b67d8 100644 --- a/src/DrupalInfo.php +++ b/src/DrupalInfo.php @@ -52,9 +52,12 @@ public function activate(Composer $composer, IOInterface $io) $this->composer = $composer; $this->io = $io; - $additionalPackageTypes = $this->composer->getConfig()->get('drupal-info-rewrite--additional-packageTypes'); - if (is_array($additionalPackageTypes)) { - $this->packageTypes = array_merge($this->packageTypes, $additionalPackageTypes); + $config = $this->composer->getConfig(); + if ($config) { + $additionalPackageTypes = $config->get('drupal-info-rewrite--additional-packageTypes'); + if (is_array($additionalPackageTypes)) { + $this->packageTypes = array_merge($this->packageTypes, $additionalPackageTypes); + } } } From 3aace278f3fe116c2236817f9d969eecb1bd6d6d Mon Sep 17 00:00:00 2001 From: Liam Morland Date: Tue, 5 Mar 2019 11:56:48 -0500 Subject: [PATCH 4/5] Add getConfig() to tests --- tests/DrupalInfoTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/DrupalInfoTest.php b/tests/DrupalInfoTest.php index de6f1f8..b5840d7 100644 --- a/tests/DrupalInfoTest.php +++ b/tests/DrupalInfoTest.php @@ -91,6 +91,7 @@ public function testInstallOperationWriteInfoFiles() $manager->getInstaller('drupal-module')->willReturn($installer->reveal()); $this->composer = $this->prophesize(Composer::class); $this->composer->getInstallationManager()->willReturn($manager->reveal()); + $this->composer->getConfig()->willReturn(null); $this->fixture->activate( $this->composer->reveal(), @@ -169,6 +170,7 @@ public function testNoInfoFile() $manager->getInstaller('drupal-module')->willReturn($installer->reveal()); $this->composer = $this->prophesize(Composer::class); $this->composer->getInstallationManager()->willReturn($manager->reveal()); + $this->composer->getConfig()->willReturn(null); $this->io->write('No info files found for foo')->shouldBeCalled(); $this->io->isVerbose()->willReturn(true); $this->fixture->activate( @@ -242,6 +244,7 @@ public function testRollbackRewrite() $this->composer = $this->prophesize(Composer::class); $this->composer->getRepositoryManager()->willReturn($manager->reveal()); $this->composer->getInstallationManager()->willReturn($location_manager->reveal()); + $this->composer->getConfig()->willReturn(null); $this->fixture->activate( $this->composer->reveal(), From f9e13ee16aad89358a4db48651a40d7ccaff6687 Mon Sep 17 00:00:00 2001 From: Liam Morland Date: Tue, 5 Mar 2019 13:33:35 -0500 Subject: [PATCH 5/5] Document drupal-info-rewrite--additional-packageTypes --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 9dc8607..214c444 100644 --- a/README.md +++ b/README.md @@ -12,3 +12,7 @@ This is only required when downloading projects that aren't full releases (for i ## Installation `composer require drupal-composer/info-rewrite:~1.0` + +## Configuration + +By default, this plugin only acts on packages of type `drupal-core`, `drupal-module`, `drupal-profile`, and `drupal-theme` (see DrupalInfo::$packageTypes). You can add additional package types in your `composer.json` file. Add to the `config` array an entry with key `drupal-info-rewrite--additional-packageTypes` and make its value be an array of strings which are the additional types you would like to add.