src/App/Controller/Dashboard/Websites/DefaultController.php line 62

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Dashboard\Websites;
  3. use App\Component\Dom\Nodes\Elements\StylesheetLinkElement;
  4. use App\Component\ViewLayer\Views\AbstractHtmlView;
  5. use App\Component\ViewLayer\Views\AjaxHtmlView;
  6. use App\Component\ViewLayer\Views\DocHtmlView;
  7. use App\Controller\PaginationTrait;
  8. use App\Entity\Content\AbstractObject;
  9. use Cms\ContainerBundle\Entity\Container;
  10. use Cms\ContainerBundle\Entity\Containers\GenericContainer;
  11. use Cms\ContainerBundle\Entity\Containers\IntranetContainer;
  12. use Cms\ContainerBundle\Entity\Containers\PersonalContainer;
  13. use Cms\CoreBundle\Service\ContextManager;
  14. use Cms\Modules\PageBundle\Service\PageModuleConfig;
  15. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  16. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  17. use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
  18. use Symfony\Component\Form\Extension\Core\Type\FormType;
  19. use Symfony\Component\Form\Extension\Core\Type\HiddenType;
  20. use Symfony\Component\Form\Extension\Core\Type\TextType;
  21. use Symfony\Component\Form\FormFactoryInterface;
  22. use Symfony\Component\HttpFoundation\RedirectResponse;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  25. use Symfony\Component\Routing\Annotation\Route;
  26. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  27. /**
  28.  *
  29.  */
  30. final class DefaultController extends AbstractContentController
  31. {
  32.     const ROUTES__MAIN 'app.app.dashboard.websites.default.main';
  33.     const ROUTES__LIST 'app.app.dashboard.websites.content.all.list';
  34.     const ROUTES__ADD 'app.app.dashboard.websites.content.add';
  35.     const ROUTES__ADD_PAGE 'app.app.dashboard.websites.content.add_page';
  36.     const ROUTES__HONEYCOMB 'app.app.dashboard.websites.default.honeycomb';
  37.     use PaginationTrait;
  38.     /**
  39.      * @Route(
  40.      *     "honeycomb",
  41.      *     name = self::ROUTES__HONEYCOMB,
  42.      * )
  43.      */
  44.     public function honeycombAction(): DocHtmlView
  45.     {
  46.         return $this->html();
  47.     }
  48.     /**
  49.      * @return RedirectResponse
  50.      *
  51.      * @Route(
  52.      *     "",
  53.      *     name = self::ROUTES__MAIN,
  54.      * )
  55.      */
  56.     public function mainAction(): RedirectResponse
  57.     {
  58.         return $this->redirectToRoute(LegacyPageController::ROUTES__LIST);
  59.     }
  60.     /**
  61.      * @param int $pagination
  62.      * @return AbstractHtmlView|RedirectResponse
  63.      *
  64.      * @Route(
  65.      *     "/content/all/list/{pagination}",
  66.      *     name = self::ROUTES__LIST,
  67.      *     requirements = {
  68.      *         "pagination" = "[1-9]\d*",
  69.      *     },
  70.      *     defaults = {
  71.      *         "pagination" = 0,
  72.      *     },
  73.      * )
  74.      */
  75.     public function listAction(int $pagination 0)
  76.     {
  77.         return $this->listLogic(
  78.             AbstractObject::class,
  79.             $pagination
  80.         );
  81.     }
  82.     /**
  83.      * @param Request $request
  84.      * @return AjaxHtmlView
  85.      *
  86.      * @Route(
  87.      *     "/content/add",
  88.      *     name = self::ROUTES__ADD,
  89.      * )
  90.      */
  91.     public function addAction(Request $request): AjaxHtmlView
  92.     {
  93.         // make sure it is ajax
  94.         if ( ! $request->isXmlHttpRequest()) {
  95.             throw new NotFoundHttpException();
  96.         }
  97.         return $this->ajax([
  98.             'department' => null,
  99.             'departments' => array_merge(
  100.                 $this->getEntityManager()->getRepository(PersonalContainer::class)->findAllHierarchy(
  101.                     null,
  102.                     [
  103.                         PersonalContainer::class,
  104.                     ],
  105.                     $this->getGlobalContext()->getEffectiveAccount()
  106.                 ),
  107.                 $this->getEntityManager()->getRepository(Container::class)->findAllHierarchy(
  108.                     null,
  109.                     [
  110.                         GenericContainer::class,
  111.                         IntranetContainer::class,
  112.                     ]
  113.                 )
  114.             ),
  115.         ]);
  116.     }
  117.     /**
  118.      * @param Request $request
  119.      * @param Container $department
  120.      * @return AjaxHtmlView
  121.      *
  122.      * @Route(
  123.      *     "/content/add/{department}/page",
  124.      *     name = self::ROUTES__ADD_PAGE,
  125.      *     requirements = {
  126.      *         "department" = "[1-9]\d*",
  127.      *     },
  128.      * )
  129.      * @ParamConverter(
  130.      *     "department",
  131.      *     class = Container::class,
  132.      * )
  133.      */
  134.     public function addPageAction(Request $requestContainer $department): AjaxHtmlView
  135.     {
  136.         // make sure it is ajax
  137.         if ( ! $request->isXmlHttpRequest()) {
  138.             throw new NotFoundHttpException();
  139.         }
  140.         $form $this->getFormFactory()
  141.             ->createNamedBuilder(
  142.                 '',
  143.                 FormType::class,
  144.                 [
  145.                     'redirectTo' => $this->generateUrl(LegacyPageController::ROUTES__LIST),
  146.                 ],
  147.                 [
  148.                     'csrf_protection' => false,
  149.                 ]
  150.             )
  151.             ->setAction($this->generateUrl(
  152.                 'campussuite.cms.module.dashboard.content.proxy_create',
  153.                 [
  154.                     'container' => $department->getId(),
  155.                     'module' => $this->getPageModuleConfig()->key(),
  156.                 ],
  157.                 UrlGeneratorInterface::ABSOLUTE_URL
  158.             ))
  159.             ->setMethod('GET')
  160.             ->add('redirectTo'HiddenType::class)
  161.             ->add('prefill_name'TextType::class, [
  162.                 'label' => 'Page name (internal)',
  163.                 'attr' => [
  164.                     'placeholder' => 'e.g. About Us',
  165.                     'autocomplete' => 'off',
  166.                 ],
  167.             ])
  168.             ->add('prefill_nav'CheckboxType::class, [
  169.                 'label' => 'Include in department\'s navigation',
  170.                 'required' => false,
  171.             ])
  172.             ->add('prefill_layout'ChoiceType::class, [
  173.                 'label' => 'Page layout',
  174.                 'multiple' => false,
  175.                 'expanded' => true,
  176.                 'choices' => [
  177.                     'One column' => '1',
  178.                     'Two column' => '2',
  179.                     'Custom' => '0',
  180.                 ],
  181.             ])
  182.             ->getForm();
  183.         return $this->ajax([
  184.             'department' => $department,
  185.             'form' => $form->createView(),
  186.         ]);
  187.     }
  188.     /**
  189.      * @return PageModuleConfig|object
  190.      */
  191.     private function getPageModuleConfig(): PageModuleConfig
  192.     {
  193.         return $this->get(__METHOD__);
  194.     }
  195. }