Drupal 8  8.0.2
ImageToolkitOperationBase Class Reference
Inheritance diagram for ImageToolkitOperationBase:

Public Member Functions

 __construct (array $configuration, $plugin_id, array $plugin_definition, ImageToolkitInterface $toolkit, LoggerInterface $logger)
 
 apply (array $arguments)
 
- Public Member Functions inherited from PluginInspectionInterface
 getPluginId ()
 
 getPluginDefinition ()
 

Protected Member Functions

 getToolkit ()
 
 arguments ()
 
 prepareArguments (array $arguments)
 
 validateArguments (array $arguments)
 
 execute (array $arguments)
 

Protected Attributes

 $toolkit
 
 $logger
 

Detailed Description

Provides a base class for image toolkit operation plugins.

See Also
Plugin API

Constructor & Destructor Documentation

__construct ( array  $configuration,
  $plugin_id,
array  $plugin_definition,
ImageToolkitInterface  $toolkit,
LoggerInterface  $logger 
)

Constructs an image toolkit operation plugin.

Parameters
array$configurationA configuration array containing information about the plugin instance.
string$plugin_idThe plugin_id for the plugin instance.
array$plugin_definitionThe plugin implementation definition.
\Drupal\Core\ImageToolkit\ImageToolkitInterface$toolkitThe image toolkit.
\Psr\Log\LoggerInterface$loggerA logger instance.

References Drupal\logger().

Here is the call graph for this function:

Member Function Documentation

apply ( array  $arguments)
final

{Applies a toolkit specific operation to an image.

Parameters
array$argumentsAn associative array of data to be used by the toolkit operation.
Returns
bool TRUE if the operation was performed successfully, FALSE otherwise.
Exceptions
\InvalidArgumentExceptionIf one or more of the arguments are not valid.
}

Implements ImageToolkitOperationInterface.

References ImageToolkitOperationBase\execute(), ImageToolkitOperationBase\prepareArguments(), and ImageToolkitOperationBase\validateArguments().

Referenced by Convert\execute(), Resize\execute(), and Crop\execute().

Here is the call graph for this function:

Here is the caller graph for this function:

arguments ( )
abstractprotected

Returns the definition of the operation arguments.

Image toolkit operation implementers must implement this method to "document" their operation, thus also if no arguments are expected.

Returns
array An array whose keys are the names of the arguments (e.g. "width", "degrees") and each value is an associative array having the following keys:
  • description: A string with the argument description. This is used only internally for documentation purposes, so it does not need to be translatable.
  • required: (optional) A boolean indicating if this argument should be provided or not. Defaults to TRUE.
  • default: (optional) When the argument is set to "required" = FALSE, this must be set to a default value. Ignored for "required" = TRUE arguments.

Referenced by ImageToolkitOperationBase\prepareArguments().

Here is the caller graph for this function:

execute ( array  $arguments)
abstractprotected

Performs the actual manipulation on the image.

Image toolkit operation implementers must implement this method. This method is responsible for actually performing the operation on the image. When this method gets called, the implementer may assume all arguments, also the optional ones, to be available, validated and corrected.

Parameters
array$argumentsAn associative array of arguments to be used by the toolkit operation.
Returns
bool TRUE if the operation was performed successfully, FALSE otherwise.

Referenced by ImageToolkitOperationBase\apply().

Here is the caller graph for this function:

getToolkit ( )
protected

Returns the image toolkit instance for this operation.

Image toolkit implementers should provide a toolkit operation base class that overrides this method to correctly document the return type of this getter. This provides better DX (code checking and code completion) for image toolkit operation developers.

Returns
prepareArguments ( array  $arguments)
protected

Checks if required arguments are passed in and adds defaults for non passed in optional arguments.

Image toolkit operation implementers should not normally need to override this method as they should place their own validation in validateArguments.

Parameters
array$argumentsAn associative array of arguments to be used by the toolkit operation.
Returns
array The prepared arguments array.
Exceptions
\InvalidArgumentException.
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException.

References ImageToolkitOperationBase\arguments().

Referenced by ImageToolkitOperationBase\apply().

Here is the call graph for this function:

Here is the caller graph for this function:

validateArguments ( array  $arguments)
protected

Validates the arguments.

Image toolkit operation implementers should place any argument validation in this method, throwing an InvalidArgumentException when an error is encountered.

Validation typically includes things like:

  • Checking that width and height are not negative.
  • Checking that a color value is indeed a color.

But validation may also include correcting the arguments, e.g:

  • Casting arguments to the correct type.
  • Rounding pixel values to an integer.

This base implementation just returns the array of arguments and thus does not need to be called by overriding methods.

Parameters
array$argumentsAn associative array of arguments to be used by the toolkit operation.
Returns
array The validated and corrected arguments array.
Exceptions
\InvalidArgumentExceptionIf one or more of the arguments are not valid.
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionExceptionIf the plugin does not define a default for an optional argument.

Referenced by ImageToolkitOperationBase\apply().

Here is the caller graph for this function:


The documentation for this class was generated from the following file: