class ImageToolkitManager

Manages toolkit plugins.

Hierarchy

Expanded class hierarchy of ImageToolkitManager

4 files declare their use of ImageToolkitManager
ImageToolkitForm.php in drupal/core/modules/system/lib/Drupal/system/Form/ImageToolkitForm.php
Contains \Drupal\system\Form\ImageToolkitForm.
ToolkitGdTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitGdTest.php
Definition of Drupal\system\Tests\Image\ToolkitGdTest.
ToolkitTest.php in drupal/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTest.php
Definition of Drupal\system\Tests\Image\ToolkitTest.
ToolkitTestBase.php in drupal/core/modules/system/lib/Drupal/system/Tests/Image/ToolkitTestBase.php
Definition of Drupal\system\Tests\Image\ToolkitTestBase.
1 string reference to 'ImageToolkitManager'
core.services.yml in drupal/core/core.services.yml
drupal/core/core.services.yml
1 service uses ImageToolkitManager

File

drupal/core/modules/system/lib/Drupal/system/Plugin/ImageToolkitManager.php, line 17
Contains \Drupal\system\Plugin\ImageToolkitManager.

Namespace

Drupal\system\Plugin
View source
class ImageToolkitManager extends PluginManagerBase {

  /**
   * Constructs the ImageToolkitManager object.
   *
   * @param \Traversable $namespaces
   *   An object that implements \Traversable which contains the root paths
   *   keyed by the corresponding namespace to look for plugin implementations,
   */
  public function __construct(\Traversable $namespaces) {
    $this->discovery = new AnnotatedClassDiscovery('ImageToolkit', $namespaces);
    $this->factory = new DefaultFactory($this->discovery);
  }

  /**
   * Gets the default image toolkit.
   *
   * @param string $toolkit_id
   *   (optional) String specifying toolkit to load. NULL will load the default
   *   toolkit.
   *
   * @return \Drupal\system\Plugin\ImageToolkitInterface
   *   Object of the default toolkit, or FALSE on error.
   */
  public function getDefaultToolkit() {
    $toolkit_id = config('system.image')
      ->get('toolkit');
    $toolkits = $this
      ->getAvailableToolkits();
    if (!isset($toolkits[$toolkit_id]) || !class_exists($toolkits[$toolkit_id]['class'])) {

      // The selected toolkit isn't available so return the first one found. If
      // none are available this will return FALSE.
      reset($toolkits);
      $toolkit_id = key($toolkits);
    }
    if ($toolkit_id) {
      $toolkit = $this
        ->createInstance($toolkit_id);
    }
    else {
      $toolkit = FALSE;
    }
    return $toolkit;
  }

  /**
   * Gets a list of available toolkits.
   *
   * @return array
   *   An array with the toolkit names as keys and the descriptions as values.
   */
  public function getAvailableToolkits() {

    // Use plugin system to get list of available toolkits.
    $toolkits = $this
      ->getDefinitions();
    $output = array();
    foreach ($toolkits as $id => $definition) {

      // Only allow modules that aren't marked as unavailable.
      if (call_user_func($definition['class'] . '::isAvailable')) {
        $output[$id] = $definition;
      }
    }
    return $output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ImageToolkitManager::getAvailableToolkits public function Gets a list of available toolkits.
ImageToolkitManager::getDefaultToolkit public function Gets the default image toolkit.
ImageToolkitManager::__construct public function Constructs the ImageToolkitManager object.
PluginManagerBase::$defaults protected property A set of defaults to be referenced by $this->processDefinition() if additional processing of plugins is necessary or helpful for development purposes. 3
PluginManagerBase::$discovery protected property The object that discovers plugins managed by this manager.
PluginManagerBase::$factory protected property The object that instantiates plugins managed by this manager.
PluginManagerBase::$mapper protected property The object that returns the preconfigured plugin instance appropriate for a particular runtime condition.
PluginManagerBase::clearCachedDefinitions public function Clears static and persistent plugin definition caches. Overrides CachedDiscoveryInterface::clearCachedDefinitions
PluginManagerBase::createInstance public function Returns a preconfigured instance of a plugin. Overrides FactoryInterface::createInstance 6
PluginManagerBase::getDefinition public function Gets a specific plugin definition. Overrides DiscoveryInterface::getDefinition
PluginManagerBase::getDefinitions public function Gets the definition of all plugins for this type. Overrides DiscoveryInterface::getDefinitions
PluginManagerBase::getInstance public function Returns a preconfigured instance of a plugin. Overrides MapperInterface::getInstance 6
PluginManagerBase::processDefinition public function Performs extra processing on plugin definitions. 2