protected function ImageToolkitOperationBase::prepareArguments in Drupal 10
Same name and namespace in other branches
- 8 core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php \Drupal\Core\ImageToolkit\ImageToolkitOperationBase::prepareArguments()
- 9 core/lib/Drupal/Core/ImageToolkit/ImageToolkitOperationBase.php \Drupal\Core\ImageToolkit\ImageToolkitOperationBase::prepareArguments()
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 $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.
File
- core/
lib/ Drupal/ Core/ ImageToolkit/ ImageToolkitOperationBase.php, line 104
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;
}