custom/plugins/MoorlFoundation/src/Core/Subscriber/MoorlFoundationSubscriber.php line 28

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace MoorlFoundation\Core\Subscriber;
  4. use Shopware\Core\Content\Media\Event\MediaFileExtensionWhitelistEvent;
  5. use Shopware\Core\System\SystemConfig\SystemConfigService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. class MoorlFoundationSubscriber implements EventSubscriberInterface
  8. {
  9.     private SystemConfigService $systemConfigService;
  10.     public function __construct(
  11.         SystemConfigService $systemConfigService
  12.     ) {
  13.         $this->systemConfigService $systemConfigService;
  14.     }
  15.     public static function getSubscribedEvents(): array
  16.     {
  17.         return [
  18.             MediaFileExtensionWhitelistEvent::class => 'onMediaFileExtensionWhitelist'
  19.         ];
  20.     }
  21.     public function onMediaFileExtensionWhitelist(MediaFileExtensionWhitelistEvent $event)
  22.     {
  23.         $whitelist $event->getWhitelist();
  24.         $whitelistConfig $this->systemConfigService->get('MoorlFoundation.config.fileExtensions');
  25.         if ($whitelistConfig) {
  26.             $whitelistConfig explode(","$whitelistConfig);
  27.             $whitelistConfig array_map('trim'$whitelistConfig);
  28.             if (is_array($whitelistConfig)) {
  29.                 $whitelist array_merge($whitelist$whitelistConfig);
  30.             }
  31.         }
  32.         $event->setWhitelist($whitelist);
  33.     }
  34. }