app/Plugin/AttachWysiwygEditor42/EventListener/AweEditorListener.php line 49

Open in your IDE?
  1. <?php
  2. namespace Plugin\AttachWysiwygEditor42\EventListener;
  3. use Eccube\Common\EccubeConfig;
  4. use Eccube\Request\Context;
  5. use Eccube\Event\TemplateEvent;
  6. use Plugin\AttachWysiwygEditor42\Entity\AweConfig;
  7. use Plugin\AttachWysiwygEditor42\Repository\AweConfigRepository;
  8. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. // use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
  11. class AweEditorListener implements EventSubscriberInterface
  12. {
  13.     /**
  14.      * @var RequestStack
  15.      */
  16.     protected $requestStack;
  17.     /**
  18.      * @var EccubeConfig
  19.      */
  20.     protected $eccubeConfig;
  21.     /**
  22.      * @var Context
  23.      */
  24.     protected $requestContext;
  25.     protected $aweConfigRepository;
  26.     public function __construct(
  27.       RequestStack $requestStack,
  28.       EccubeConfig $eccubeConfig,
  29.       Context $requestContext,
  30.       AweConfigRepository $aweConfigRepository
  31.     )
  32.     {
  33.         $this->requestStack $requestStack;
  34.         $this->eccubeConfig $eccubeConfig;
  35.         $this->requestContext $requestContext;
  36.         $this->aweConfigRepository $aweConfigRepository;
  37.     }
  38.     public function adminInsertWysiwygEditorTag(TemplateEvent $event)
  39.     {
  40.       // 拡張されるファイルに充てたSnipetsの退避
  41.       if( $event->hasParameter('plugin_snippets') )
  42.       {
  43.         $snipets $event->getParameter('plugin_snippets');
  44.         if( $snipets )
  45.         {
  46.           foreach( $snipets as $snippet => $include )
  47.           {
  48.             $event->addSnippet$snippet $include);
  49.           }
  50.         }
  51.       }
  52.       $output;
  53.       $selector_list = [];
  54.       $wysiwyg_frag false;
  55.       $wysiwyg_config $this->aweConfigRepository->findAll();
  56.       $currentRequest $this->requestStack->getCurrentRequest();
  57.       $request_path $currentRequest->getPathInfo();
  58.       $setting_path;
  59.       foreach( $wysiwyg_config as $config)
  60.       {
  61.         $setting_path '/'.$this->eccubeConfig['eccube_admin_route'].'/'.$config['url_path'];
  62.         if(  false !== strpos($request_path$setting_path) )
  63.         {
  64.           $wysiwyg_frag true;
  65.           $selector_list[] = $config['selector'];
  66.         }
  67.       }
  68.       if( $wysiwyg_frag )
  69.       {
  70.         $fileDir $this->eccubeConfig['eccube_html_dir'] . '/AttachWysiwygEditor/summernote/dist';
  71.         $output "<script>$(document).ready(function() {\r\n";
  72.         foreach( $selector_list as $selector )
  73.         {
  74.           $output .= "$('{$selector}').summernote(window.summernote_option);\r\n";
  75.         }
  76.         $output .= "});</script>";
  77.         $event->addSnippet'@AttachWysiwygEditor42/admin/awe.twig' );
  78.         $event->addSnippet$output false);
  79.       }
  80.     }
  81.     public static function getSubscribedEvents()
  82.     {
  83.         return [
  84.           '@admin/default_frame.twig' => ['adminInsertWysiwygEditorTag'],
  85.         ];
  86.     }
  87. }