From b06034886ea2de75707aa699410f7c1bd205446b Mon Sep 17 00:00:00 2001 From: Claudiu Cristea Date: Sun, 6 Oct 2013 01:17:44 +0300 Subject: [PATCH] Issue #2105621 by claudiu.cristea: Inject config factory service into image toolkit manager. --- core/core.services.yml | 2 +- .../lib/Drupal/system/Plugin/ImageToolkitManager.php | 16 ++++++++++++++-- .../system/lib/Drupal/system/Tests/Image/ToolkitTest.php | 2 +- .../lib/Drupal/system/Tests/Image/ToolkitTestBase.php | 3 +-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/core/core.services.yml b/core/core.services.yml index 24ef51e..54dd634 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -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 diff --git a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php index 77e90c1..b29ab58 100644 --- a/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php +++ b/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php @@ -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; @@ -17,6 +18,13 @@ class ImageToolkitManager extends DefaultPluginManager { /** + * The config factory. + * + * @var \Drupal\Core\Config\ConfigFactory + */ + protected $configFactory; + + /** * Constructs the ImageToolkitManager object. * * @param \Traversable $namespaces @@ -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 @@ public function __construct(\Traversable $namespaces, CacheBackendInterface $cac * 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'])) { diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php index 5f6c4dc..e2a546e 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php @@ -26,7 +26,7 @@ public static function getInfo() { * 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'); diff --git a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php index a7d097b..38d7a91 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php @@ -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 @@ function setUp() { 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. -- 1.8.3.1