Commit c4c7e6ee authored by Neslee Canil Pinto's avatar Neslee Canil Pinto Committed by Neslee Canil Pinto

Issue #3136968 by lolandese, Neslee Canil Pinto: Drupal calls should be...

Issue #3136968 by lolandese, Neslee Canil Pinto: Drupal calls should be avoided in classes, use dependency injection instead
parent a6844e5e
services:
colorbox.commands:
class: \Drupal\colorbox\Commands\ColorboxCommands
arguments:
- '@library.discovery'
tags:
- { name: drush.command }
......@@ -2,10 +2,11 @@
namespace Drupal\colorbox\Commands;
use Drupal\Core\Asset\libraryDiscovery;
use Drush\Commands\DrushCommands;
use Symfony\Component\Filesystem\Filesystem;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\RequestException;
use Symfony\Component\Filesystem\Filesystem;
/**
* A Drush commandfile.
......@@ -20,6 +21,20 @@ use GuzzleHttp\Exception\RequestException;
*/
class ColorboxCommands extends DrushCommands {
/**
* Library discovery service.
*
* @var Drupal\Core\Asset\libraryDiscovery
*/
protected $libraryDiscovery;
/**
* {@inheritdoc}
*/
public function __construct(libraryDiscovery $library_discovery) {
$this->libraryDiscovery = $library_discovery;
}
/**
* Download and install the Colorbox plugin.
*
......@@ -49,7 +64,7 @@ class ColorboxCommands extends DrushCommands {
}
// Load the colorbox defined library.
if ($colorbox_library = \Drupal::service('library.discovery')->getLibraryByName('colorbox', 'colorbox')) {
if ($colorbox_library = $this->libraryDiscovery->getLibraryByName('colorbox', 'colorbox')) {
// Download the file.
$client = new Client();
$destination = tempnam(sys_get_temp_dir(), 'colorbox-tmp');
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment