<?php
declare(strict_types=1);
namespace Abcpremium\InspectablePdfsBundle\Event;
use Abcpremium\InspectablePdfsBundle\Model\Setting;
use Pimcore\Event\DocumentEvents;
use Pimcore\Event\Model\PrintConfigEvent;
use Pimcore\Web2Print\Processor\PdfReactor;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class AddInspectableSettingToProcessingConfig implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
return [
DocumentEvents::PRINT_MODIFY_PROCESSING_CONFIG => 'addInspectableSetting',
];
}
public function addInspectableSetting(PrintConfigEvent $event): void
{
$processor = $event->getProcessor();
if (!$processor instanceof PdfReactor) {
return;
}
$options = $event->getArgument('config');
$optionArray = get_object_vars($options);
$createInspectablePdf = $optionArray[Setting::INSPECTABLE_PDF] ?? false;
if (false === $createInspectablePdf) {
return;
}
$config = $event->getArgument('reactorConfig');
$config['inspectableSettings'] = [
'enabled' => true,
];
$event->setArgument('reactorConfig', $config);
}
}