Issue #2105621 by claudiu.cristea: Inject config factory service into image toolkit manager.
parent
6615069304
commit
6207fe9417
|
@ -526,7 +526,7 @@ services:
|
|||
- { name: event_subscriber }
|
||||
image.toolkit.manager:
|
||||
class: Drupal\system\Plugin\ImageToolkitManager
|
||||
arguments: ['@container.namespaces', '@cache.cache', '@language_manager']
|
||||
arguments: ['@container.namespaces', '@cache.cache', '@language_manager', '@config.factory']
|
||||
image.toolkit:
|
||||
class: Drupal\system\Plugin\ImageToolkitInterface
|
||||
factory_method: getDefaultToolkit
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
namespace Drupal\system\Plugin;
|
||||
|
||||
use Drupal\Core\Cache\CacheBackendInterface;
|
||||
use Drupal\Core\Config\ConfigFactory;
|
||||
use Drupal\Core\Language\LanguageManager;
|
||||
use Drupal\Core\Plugin\DefaultPluginManager;
|
||||
|
||||
|
@ -16,6 +17,13 @@ use Drupal\Core\Plugin\DefaultPluginManager;
|
|||
*/
|
||||
class ImageToolkitManager extends DefaultPluginManager {
|
||||
|
||||
/**
|
||||
* The config factory.
|
||||
*
|
||||
* @var \Drupal\Core\Config\ConfigFactory
|
||||
*/
|
||||
protected $configFactory;
|
||||
|
||||
/**
|
||||
* Constructs the ImageToolkitManager object.
|
||||
*
|
||||
|
@ -26,10 +34,14 @@ class ImageToolkitManager extends DefaultPluginManager {
|
|||
* Cache backend instance to use.
|
||||
* @param \Drupal\Core\Language\LanguageManager $language_manager
|
||||
* The language manager.
|
||||
* @param \Drupal\Core\Config\ConfigFactory $config_factory
|
||||
* The config factory.
|
||||
*/
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager) {
|
||||
public function __construct(\Traversable $namespaces, CacheBackendInterface $cache_backend, LanguageManager $language_manager, ConfigFactory $config_factory) {
|
||||
parent::__construct('Plugin/ImageToolkit', $namespaces, 'Drupal\system\Annotation\ImageToolkit');
|
||||
|
||||
$this->setCacheBackend($cache_backend, $language_manager, 'image_toolkit');
|
||||
$this->configFactory = $config_factory;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -43,7 +55,7 @@ class ImageToolkitManager extends DefaultPluginManager {
|
|||
* Object of the default toolkit, or FALSE on error.
|
||||
*/
|
||||
public function getDefaultToolkit() {
|
||||
$toolkit_id = \Drupal::config('system.image')->get('toolkit');
|
||||
$toolkit_id = $this->configFactory->get('system.image')->get('toolkit');
|
||||
$toolkits = $this->getAvailableToolkits();
|
||||
|
||||
if (!isset($toolkits[$toolkit_id]) || !class_exists($toolkits[$toolkit_id]['class'])) {
|
||||
|
|
|
@ -7,8 +7,6 @@
|
|||
|
||||
namespace Drupal\system\Tests\Image;
|
||||
|
||||
use Drupal\system\Plugin\ImageToolkitManager;
|
||||
|
||||
/**
|
||||
* Tests that the methods in Image correctly pass data to the toolkit.
|
||||
*/
|
||||
|
@ -26,7 +24,7 @@ class ToolkitTest extends ToolkitTestBase {
|
|||
* available toolkits.
|
||||
*/
|
||||
function testGetAvailableToolkits() {
|
||||
$manager = new ImageToolkitManager($this->container->get('container.namespaces'), $this->container->get('cache.cache'), $this->container->get('language_manager'));
|
||||
$manager = $this->container->get('image.toolkit.manager');
|
||||
$toolkits = $manager->getAvailableToolkits();
|
||||
$this->assertTrue(isset($toolkits['test']), 'The working toolkit was returned.');
|
||||
$this->assertFalse(isset($toolkits['broken']), 'The toolkit marked unavailable was not returned');
|
||||
|
|
|
@ -8,7 +8,6 @@
|
|||
namespace Drupal\system\Tests\Image;
|
||||
|
||||
use Drupal\simpletest\WebTestBase;
|
||||
use Drupal\system\Plugin\ImageToolkitManager;
|
||||
|
||||
/**
|
||||
* Base class for image manipulation testing.
|
||||
|
@ -47,7 +46,7 @@ abstract class ToolkitTestBase extends WebTestBase {
|
|||
parent::setUp();
|
||||
|
||||
// Use the image_test.module's test toolkit.
|
||||
$manager = new ImageToolkitManager($this->container->get('container.namespaces'), $this->container->get('cache.cache'), $this->container->get('language_manager'));
|
||||
$manager = $this->container->get('image.toolkit.manager');
|
||||
$this->toolkit = $manager->createInstance('test');
|
||||
|
||||
// Pick a file for testing.
|
||||
|
|
Loading…
Reference in New Issue