├── README.md ├── composer.json └── src └── Drupal └── Composer ├── DrupalLibraryInstaller.php └── DrupalLibraryInstallerPlugin.php /README.md: -------------------------------------------------------------------------------- 1 | Drupal Libraries Installer Plugin (For Composer) 2 | 3 | The problem this installer tries to achieve is the ability to install libraries that Drupal modules use in the right place. 4 | 5 | Common examples of modules that do this are: 6 | 7 | * [WYSIWYG](https://www.drupal.org/project/wysiwyg) 8 | 9 | In order to use this plugin add this package to your "requires" section as well as any package you wish to install as a library: 10 | 11 | "require": { 12 | "drupal/drupal-library-installer-plugin": "~0.1", 13 | "ckeditor/ckeditor": "~4.4.4", 14 | } 15 | 16 | Then you need to tell the installer plugin where you need your libraries installed. An example may be as follows 17 | 18 | "extra": { 19 | "drupal-libraries": { 20 | "library-directory": "www/sites/all/libraries", 21 | "libraries": [ 22 | { 23 | "name": "ckeditor", 24 | "package": "ckeditor/ckeditor" 25 | } 26 | ] 27 | } 28 | } 29 | 30 | This will install the ckeditor library in the folder `www/sites/all/libraries/ckeditor`. Easy nuff. -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "drupal/drupal-library-installer-plugin", 3 | "type": "composer-plugin", 4 | "authors": [ 5 | { 6 | "name": "Allan Chappell", 7 | "email": "generalredneck@gmail.com" 8 | } 9 | ], 10 | "autoload": { 11 | "psr-0": {"Drupal\\Composer": "src/"} 12 | }, 13 | "extra": { 14 | "class": "Drupal\\Composer\\DrupalLibraryInstallerPlugin" 15 | }, 16 | "require": { 17 | "composer-plugin-api": "^1.0" 18 | }, 19 | "abandoned": "oomphinc/composer-installers-extender" 20 | 21 | 22 | } 23 | -------------------------------------------------------------------------------- /src/Drupal/Composer/DrupalLibraryInstaller.php: -------------------------------------------------------------------------------- 1 | composer->getPackage()->getExtra(); 16 | $this->drupalConfig = isset($extra['drupal-libraries']) ? $extra['drupal-libraries'] : array(); 17 | $this->drupalLibrariesPath = isset($this->drupalConfig['library-directory']) ? $this->drupalConfig['library-directory'] : 'www/sites/all/libraries/'; 18 | if (substr($this->drupalLibrariesPath, -1) != '/') { 19 | $this->drupalLibrariesPath .= '/'; 20 | } 21 | $this->drupalLibraries = isset($this->drupalConfig['libraries']) ? $this->drupalConfig['libraries'] : array(); 22 | $this->drupalLibraryMap = array(); 23 | foreach ($this->drupalLibraries as $library) { 24 | $this->drupalLibraryMap[$library['package']] = $library['name']; 25 | } 26 | } 27 | /** 28 | * {@inheritDoc} 29 | */ 30 | public function getInstallPath(PackageInterface $package) 31 | { 32 | if (empty($this->drupalLibraryMap[$package->getPrettyName()])) { 33 | $path = parent::getInstallPath($package); 34 | } 35 | else { 36 | $path = $this->drupalLibrariesPath . $this->drupalLibraryMap[$package->getPrettyName()]; 37 | } 38 | return $path; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Drupal/Composer/DrupalLibraryInstallerPlugin.php: -------------------------------------------------------------------------------- 1 | getInstallationManager()->addInstaller($installer); 15 | } 16 | } --------------------------------------------------------------------------------