function ImageToolkitOperationBase::prepareArguments
Same name in other branches
- 9 core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php \Drupal\Core\ImageToolkit\ImageToolkitOperationBase::prepareArguments()
- 8.9.x core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php \Drupal\Core\ImageToolkit\ImageToolkitOperationBase::prepareArguments()
- 10 core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php \Drupal\Core\ImageToolkit\ImageToolkitOperationBase::prepareArguments()
Checks for required arguments and adds optional argument defaults.
Image toolkit operation implementers should not normally need to override this method as they should place their own validation in validateArguments.
Parameters
array $arguments: An associative array of arguments to be used by the toolkit operation.
Return value
array The prepared arguments array.
Throws
\InvalidArgumentException
\Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException
1 call to ImageToolkitOperationBase::prepareArguments()
- ImageToolkitOperationBase::apply in core/
lib/ Drupal/ Core/ ImageToolkit/ ImageToolkitOperationBase.php - Applies a toolkit specific operation to an image.
File
-
core/
lib/ Drupal/ Core/ ImageToolkit/ ImageToolkitOperationBase.php, line 103
Class
- ImageToolkitOperationBase
- Provides a base class for image toolkit operation plugins.
Namespace
Drupal\Core\ImageToolkitCode
protected function prepareArguments(array $arguments) {
foreach ($this->arguments() as $id => $argument) {
$argument += [
'required' => TRUE,
];
// Check if the argument is required and, if so, has been provided.
if ($argument['required']) {
if (!array_key_exists($id, $arguments)) {
// If the argument is required throw an exception.
throw new \InvalidArgumentException("Argument '{$id}' expected by plugin '{$this->getPluginId()}' but not passed");
}
}
else {
// Optional arguments require a 'default' value.
// We check this even if the argument is provided by the caller, as we
// want to fail fast here, i.e. at development time.
if (!array_key_exists('default', $argument)) {
// The plugin did not define a default, so throw a plugin exception,
// not an invalid argument exception.
throw new InvalidPluginDefinitionException("Default for argument '{$id}' expected by plugin '{$this->getPluginId()}' but not defined");
}
// Use the default value if the argument is not passed in.
if (!array_key_exists($id, $arguments)) {
$arguments[$id] = $argument['default'];
}
}
}
return $arguments;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.