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

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.     /**
  24.      * @return array
  25.      */
  26.     public static function getSubscribedEvents()
  27.     {
  28.         return [
  29.             ExtractMappingEvent::class => 'onExtractMapping',
  30.             UpdateIndexDataEvent::class => 'onUpdateIndexData'
  31.         ];
  32.     }
  33.     public function onExtractMapping(ExtractMappingEvent $event)
  34.     {
  35.         $mappings $event->getCustomFieldsMapping();
  36.         $mappings array_merge($mappings$this->sizeEstimationStrategy->getCustomDataObjectMappingForIndex($event->getClassDefinition()));
  37.         $event->setCustomFieldsMapping($mappings);
  38.     }
  39.     public function onUpdateIndexData(UpdateIndexDataEvent $event)
  40.     {
  41.         $data $event->getCustomFields();
  42.         $event->setCustomFields(array_replace($data$this->sizeEstimationStrategy->getCustomDataObjectDataForIndex($event->getDataObject())));
  43.     }
  44. }