vendor/pimcore/portal-engine/src/EventSubscriber/SizeEstimationStrategyListener.php line 46

Open in your IDE?
  1. <?php
  2. /**
  3.  * Pimcore
  4.  *
  5.  * This source file is available under following license:
  6.  * - Pimcore Commercial License (PCL)
  7.  *
  8.  *  @copyright  Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  9.  *  @license    http://www.pimcore.org/license     PCL
  10.  */
  11. namespace Pimcore\Bundle\PortalEngineBundle\EventSubscriber;
  12. use Pimcore\Bundle\PortalEngineBundle\Event\DataObject\ExtractMappingEvent;
  13. use Pimcore\Bundle\PortalEngineBundle\Event\DataObject\UpdateIndexDataEvent;
  14. use Pimcore\Bundle\PortalEngineBundle\Service\Download\SizeEstimation\SizeEstimationStrategyInterface;
  15. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  16. class SizeEstimationStrategyListener implements EventSubscriberInterface
  17. {
  18.     protected $sizeEstimationStrategy;
  19.     public function __construct(SizeEstimationStrategyInterface $sizeEstimationStrategy)
  20.     {
  21.         $this->sizeEstimationStrategy $sizeEstimationStrategy;
  22.     }
  23.     public static function getSubscribedEvents()
  24.     {
  25.         return [
  26.             ExtractMappingEvent::class => 'onExtractMapping',
  27.             UpdateIndexDataEvent::class => 'onUpdateIndexData'
  28.         ];
  29.     }
  30.     public function onExtractMapping(ExtractMappingEvent $event)
  31.     {
  32.         $mappings $event->getCustomFieldsMapping();
  33.         $mappings array_merge($mappings$this->sizeEstimationStrategy->getCustomDataObjectMappingForIndex($event->getClassDefinition()));
  34.         $event->setCustomFieldsMapping($mappings);
  35.     }
  36.     public function onUpdateIndexData(UpdateIndexDataEvent $event)
  37.     {
  38.         $data $event->getCustomFields();
  39.         $event->setCustomFields(array_replace($data$this->sizeEstimationStrategy->getCustomDataObjectDataForIndex($event->getDataObject())));
  40.     }
  41. }