src/Eccube/Controller/Admin/Content/CssController.php line 31

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of EC-CUBE
  4.  *
  5.  * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
  6.  *
  7.  * http://www.ec-cube.co.jp/
  8.  *
  9.  * For the full copyright and license information, please view the LICENSE
  10.  * file that was distributed with this source code.
  11.  */
  12. namespace Eccube\Controller\Admin\Content;
  13. use Eccube\Controller\AbstractController;
  14. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  15. use Symfony\Component\Filesystem\Exception\IOException;
  16. use Symfony\Component\Filesystem\Filesystem;
  17. use Symfony\Component\Form\Extension\Core\Type\FormType;
  18. use Symfony\Component\Form\Extension\Core\Type\TextareaType;
  19. use Symfony\Component\HttpFoundation\Request;
  20. use Symfony\Component\Routing\Annotation\Route;
  21. class CssController extends AbstractController
  22. {
  23.     /**
  24.      * @Route("/%eccube_admin_route%/content/css", name="admin_content_css", methods={"GET", "POST"})
  25.      * @Template("@admin/Content/css.twig")
  26.      */
  27.     public function index(Request $request)
  28.     {
  29.         $this->addInfoOnce('admin.common.restrict_file_upload_info''admin');
  30.         $builder $this->formFactory
  31.             ->createBuilder(FormType::class)
  32.             ->add('css'TextareaType::class, [
  33.                 'required' => false,
  34.             ]);
  35.         $form $builder->getForm();
  36.         $cssPath $this->getParameter('eccube_html_dir').'/user_data/assets/css/customize.css';
  37.         if (file_exists($cssPath) && is_writable($cssPath)) {
  38.             $form->get('css')->setData(file_get_contents($cssPath));
  39.         }
  40.         $form->handleRequest($request);
  41.         if ($form->isSubmitted() && $form->isValid()) {
  42.             $fs = new Filesystem();
  43.             try {
  44.                 $fs->dumpFile($cssPath$form->get('css')->getData());
  45.                 $this->addSuccess('admin.common.save_complete''admin');
  46.                 return $this->redirectToRoute('admin_content_css');
  47.             } catch (IOException $e) {
  48.                 $message trans('admin.common.save_error');
  49.                 $this->addError($message'admin');
  50.                 log_error($message, [$cssPath$e]);
  51.             }
  52.         }
  53.         return [
  54.             'form' => $form->createView(),
  55.         ];
  56.     }
  57. }