abstract class ImageToolkitBase in Drupal 9
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/ImageToolkit/ImageToolkitBase.php \Drupal\Core\ImageToolkit\ImageToolkitBase
Provides a base class for image toolkit plugins.
Hierarchy
- class \Drupal\Component\Plugin\PluginBase implements DerivativeInspectionInterface, PluginInspectionInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
- class \Drupal\Core\ImageToolkit\ImageToolkitBase implements ImageToolkitInterface
- class \Drupal\Core\Plugin\PluginBase uses DependencySerializationTrait, MessengerTrait, StringTranslationTrait
Expanded class hierarchy of ImageToolkitBase
See also
\Drupal\Core\ImageToolkit\Annotation\ImageToolkit
\Drupal\Core\ImageToolkit\ImageToolkitInterface
\Drupal\Core\ImageToolkit\ImageToolkitManager
2 files declare their use of ImageToolkitBase
- GDToolkit.php in core/
modules/ system/ src/ Plugin/ ImageToolkit/ GDToolkit.php - TestToolkit.php in core/
modules/ system/ tests/ modules/ image_test/ src/ Plugin/ ImageToolkit/ TestToolkit.php
File
- core/
lib/ Drupal/ Core/ ImageToolkit/ ImageToolkitBase.php, line 19
Namespace
Drupal\Core\ImageToolkitView source
abstract class ImageToolkitBase extends PluginBase implements ImageToolkitInterface {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* Path of the image file.
*
* @var string
*/
protected $source = '';
/**
* The image toolkit operation manager.
*
* @var \Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface
*/
protected $operationManager;
/**
* A logger instance.
*
* @var \Psr\Log\LoggerInterface
*/
protected $logger;
/**
* Constructs an ImageToolkitBase object.
*
* @param array $configuration
* A configuration array containing information about the plugin instance.
* @param string $plugin_id
* The plugin_id for the plugin instance.
* @param array $plugin_definition
* The plugin implementation definition.
* @param \Drupal\Core\ImageToolkit\ImageToolkitOperationManagerInterface $operation_manager
* The toolkit operation manager.
* @param \Psr\Log\LoggerInterface $logger
* A logger instance.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(array $configuration, $plugin_id, array $plugin_definition, ImageToolkitOperationManagerInterface $operation_manager, LoggerInterface $logger, ConfigFactoryInterface $config_factory) {
parent::__construct($configuration, $plugin_id, $plugin_definition);
$this->operationManager = $operation_manager;
$this->logger = $logger;
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public function validateConfigurationForm(array &$form, FormStateInterface $form_state) {
}
/**
* {@inheritdoc}
*/
public function setSource($source) {
// If a previous image has been loaded, there is no way to know if the
// toolkit implementation needs to perform any additional actions like
// freeing memory. Therefore, the source image cannot be changed once set.
if ($this->source) {
throw new \BadMethodCallException(__METHOD__ . '() may only be called once');
}
$this->source = $source;
return $this;
}
/**
* {@inheritdoc}
*/
public function getSource() {
return $this->source;
}
/**
* {@inheritdoc}
*/
public function getRequirements() {
return [];
}
/**
* Gets a toolkit operation plugin instance.
*
* @param string $operation
* The toolkit operation requested.
*
* @return \Drupal\Core\ImageToolkit\ImageToolkitOperationInterface
* An instance of the requested toolkit operation plugin.
*/
protected function getToolkitOperation($operation) {
return $this->operationManager
->getToolkitOperation($this, $operation);
}
/**
* {@inheritdoc}
*/
public function apply($operation, array $arguments = []) {
try {
// Get the plugin to use for the operation and apply the operation.
return $this
->getToolkitOperation($operation)
->apply($arguments);
} catch (PluginNotFoundException $e) {
$this->logger
->error("The selected image handling toolkit '@toolkit' can not process operation '@operation'.", [
'@toolkit' => $this
->getPluginId(),
'@operation' => $operation,
]);
return FALSE;
} catch (\InvalidArgumentException $e) {
$this->logger
->warning($e
->getMessage(), []);
return FALSE;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ContainerFactoryPluginInterface:: |
public static | function | Creates an instance of the plugin. | 120 |
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
protected | property | ||
DependencySerializationTrait:: |
public | function | 2 | |
DependencySerializationTrait:: |
public | function | 2 | |
ImageToolkitBase:: |
protected | property | The config factory. | |
ImageToolkitBase:: |
protected | property | A logger instance. | |
ImageToolkitBase:: |
protected | property | The image toolkit operation manager. | |
ImageToolkitBase:: |
protected | property | Path of the image file. | |
ImageToolkitBase:: |
public | function |
Applies a toolkit operation to an image. Overrides ImageToolkitInterface:: |
1 |
ImageToolkitBase:: |
public | function |
Gets toolkit requirements in a format suitable for hook_requirements(). Overrides ImageToolkitInterface:: |
1 |
ImageToolkitBase:: |
public | function |
Gets the source path of the image file. Overrides ImageToolkitInterface:: |
|
ImageToolkitBase:: |
protected | function | Gets a toolkit operation plugin instance. | |
ImageToolkitBase:: |
public | function |
Sets the source path of the image file. Overrides ImageToolkitInterface:: |
|
ImageToolkitBase:: |
public | function |
Form validation handler. Overrides PluginFormInterface:: |
1 |
ImageToolkitBase:: |
public | function |
Constructs an ImageToolkitBase object. Overrides PluginBase:: |
2 |
ImageToolkitInterface:: |
public | function | Returns the height of the image. | 2 |
ImageToolkitInterface:: |
public | function | Returns the MIME type of the image file. | 2 |
ImageToolkitInterface:: |
public static | function | Returns a list of image file extensions supported by the toolkit. | 2 |
ImageToolkitInterface:: |
public | function | Returns the width of the image. | 2 |
ImageToolkitInterface:: |
public static | function | Verifies that the Image Toolkit is set up correctly. | 2 |
ImageToolkitInterface:: |
public | function | Checks if the image is valid. | 2 |
ImageToolkitInterface:: |
public | function | Determines if a file contains a valid image. | 2 |
ImageToolkitInterface:: |
public | function | Writes an image resource to a destination file. | 2 |
MessengerTrait:: |
protected | property | The messenger. | 27 |
MessengerTrait:: |
public | function | Gets the messenger. | 27 |
MessengerTrait:: |
public | function | Sets the messenger. | |
PluginBase:: |
protected | property | Configuration information passed into the plugin. | 1 |
PluginBase:: |
protected | property | The plugin implementation definition. | 1 |
PluginBase:: |
protected | property | The plugin_id. | |
PluginBase:: |
constant | A string which is used to separate base plugin IDs from the derivative ID. | ||
PluginBase:: |
public | function |
Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface:: |
|
PluginBase:: |
public | function |
Gets the definition of the plugin implementation. Overrides PluginInspectionInterface:: |
2 |
PluginBase:: |
public | function |
Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface:: |
|
PluginBase:: |
public | function | Determines if the plugin is configurable. | |
PluginFormInterface:: |
public | function | Form constructor. | 37 |
PluginFormInterface:: |
public | function | Form submission handler. | 32 |
StringTranslationTrait:: |
protected | property | The string translation service. | 4 |
StringTranslationTrait:: |
protected | function | Formats a string containing a count of items. | |
StringTranslationTrait:: |
protected | function | Returns the number of plurals supported by a given language. | |
StringTranslationTrait:: |
protected | function | Gets the string translation service. | |
StringTranslationTrait:: |
public | function | Sets the string translation service to use. | 2 |
StringTranslationTrait:: |
protected | function | Translates a string to the current language or to a given language. |