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 (\Throwable $t) { $this->logger->warning("The image toolkit '@toolkit' failed processing '@operation' for image '@image'. Reported error: @class - @message", [ '@toolkit' => $this->getPluginId(), '@operation' => $operation, '@image' => $this->getSource(), '@class' => get_class($t), '@message' => $t->getMessage(), ]); return FALSE; } } }