setCacheBackend($cache_backend, 'image_toolkit_plugins'); $this->configFactory = $config_factory; } /** * Gets the default image toolkit ID. * * @return string|bool * ID of the default toolkit, or FALSE on error. */ public function getDefaultToolkitId() { $toolkit_id = $this->configFactory->get('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. $toolkit_id = array_key_first($toolkits); } return $toolkit_id; } /** * Gets the default image toolkit. * * @return \Drupal\Core\ImageToolkit\ImageToolkitInterface * Object of the default toolkit, or FALSE on error. */ public function getDefaultToolkit() { if ($toolkit_id = $this->getDefaultToolkitId()) { return $this->createInstance($toolkit_id); } return FALSE; } /** * 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 = []; 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; } }