src/EventListener/SiteListener.php line 126

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use App\Controller\Page\ApplicantController;
  4. use App\Controller\Page\AppointmentController;
  5. use App\Controller\Page\BlogPostController;
  6. use App\Controller\Page\BlogPostsController;
  7. use App\Controller\Page\CompaniesController;
  8. use App\Controller\Page\CompanyController;
  9. use App\Controller\Page\ContactController;
  10. use App\Controller\Page\ElementController;
  11. use App\Controller\Page\EmployeeController;
  12. use App\Controller\Page\EventController;
  13. use App\Controller\Page\EventRegistrationController;
  14. use App\Controller\Page\EventsController;
  15. use App\Controller\Page\JobAlertController;
  16. use App\Controller\Page\NewsletterController;
  17. use App\Controller\Page\OptionController;
  18. use App\Controller\Page\OrderController;
  19. use App\Controller\Page\OrderSnippetController;
  20. use App\Controller\Page\PortfolioController;
  21. use App\Controller\Page\PortfoliosController;
  22. use App\Controller\Page\ProductController;
  23. use App\Controller\Page\ProductsController;
  24. use App\Controller\Page\ReviewController;
  25. use App\Controller\Page\ReviewsController;
  26. use App\Controller\Page\SearchController;
  27. use App\Controller\Page\TestimonialController;
  28. use App\Controller\Page\User\MobilityController;
  29. use App\Controller\Page\VacanciesController;
  30. use App\Controller\Page\VacancyController;
  31. use App\Entity\ApplicantForm;
  32. use App\Entity\Grid;
  33. use App\Entity\Head;
  34. use App\Entity\Option;
  35. use App\Entity\OptionValue;
  36. use App\Entity\Page;
  37. use App\Entity\Route;
  38. use App\Entity\Site;
  39. use App\Event\SiteCreatedEvent;
  40. use Doctrine\ORM\EntityManagerInterface;
  41. use Symfony\Component\Console\Output\OutputInterface;
  42. use Symfony\Component\Routing\RouterInterface;
  43. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  44. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  45. use Symfony\Component\Serializer\Serializer;
  46. use Symfony\Component\Serializer\SerializerInterface;
  47. use Symfony\Contracts\Translation\TranslatorInterface;
  48. use Twig\Environment as TwigEnvironment;
  49. use Twig\Error\LoaderError as Twig_Error_Loader;
  50. use Twig\Error\RuntimeError as Twig_Error_Runtime;
  51. use Twig\Error\SyntaxError as Twig_Error_Syntax;
  52. class SiteListener
  53. {
  54.     public const SYSTEM_PAGE_TEMPLATE_BOXED 'pages/system_page.html.twig';
  55.     public const SYSTEM_PAGE_TEMPLATE_EMPTY 'pages/system_page_empty.html.twig';
  56.     /**
  57.      * @var EntityManagerInterface
  58.      */
  59.     private $entityManager;
  60.     /**
  61.      * @var SerializerInterface
  62.      */
  63.     private $serializer;
  64.     /**
  65.      * @var RouterInterface
  66.      */
  67.     private $router;
  68.     /**
  69.      * @var Twig_Environment
  70.      */
  71.     private $twig;
  72.     /**
  73.      * @var TranslatorInterface
  74.      */
  75.     private $translator;
  76.     /**
  77.      * @var string
  78.      */
  79.     private $locale;
  80.     /**
  81.      * @var string
  82.      */
  83.     private $locales;
  84.     /**
  85.      * @var Site|null
  86.      */
  87.     private $site;
  88.     protected string $projectDir;
  89.     /**
  90.      * @var array
  91.      */
  92.     private $routes;
  93.     public function __construct(
  94.         RouterInterface $router,
  95.         TwigEnvironment $twig,
  96.         TranslatorInterface $translator,
  97.         string $locale
  98.     ) {
  99.         $this->serializer = new Serializer([new ObjectNormalizer()], [new JsonEncoder()]);
  100.         $this->router $router;
  101.         $this->twig $twig;
  102.         $this->translator $translator;
  103.         $this->locale $locale;
  104.         $this->locales array_diff(['nl''en''de''fr''pl''ro''es''da''sv'], [$locale]);
  105.     }
  106.     /**
  107.      * @throws Twig_Error_Loader
  108.      * @throws Twig_Error_Runtime
  109.      * @throws Twig_Error_Syntax
  110.      */
  111.     public function onPageCreate(SiteCreatedEvent $event)
  112.     {
  113.         $this->routes = require_once __DIR__.'/../../app/page_routes.php';
  114.         $output $event->getOutput();
  115.         $this->entityManager $event->getEntityManager();
  116.         $this->createWebring($output);
  117.         $headerNavigation $this->createHeaderNavigation($output);
  118.         $repository $this->createRepository($output);
  119.         $this->createFooterNavigation($output);
  120.         $this->createFooterBottomNavigation($output);
  121.         $this->createHomepage($output$headerNavigation);
  122.         $this->createGrid($output);
  123.         $this->createUserLoginPage($output$repository);
  124.         $this->createAppointmentThanksPage($output$repository);
  125.         $this->createBlog($output$headerNavigation);
  126.         $this->createEvent($output$headerNavigation$repository);
  127.         $this->createJobAlert($output$headerNavigation);
  128.         $this->createOrder($output$repository);
  129.         $this->createSample($output$repository);
  130.         $this->createPortfolio($output$headerNavigation);
  131.         $this->createProduct($output$headerNavigation);
  132.         $this->createReview($headerNavigation);
  133.         $this->createNewsletter($output$repository);
  134.         $this->add404Page($output$repository);
  135.         $this->add500Page($output$repository);
  136.         $this->createTestimonial($output$repository);
  137.         $this->createCompany($output$headerNavigation);
  138.         $this->createEmployees($repository);
  139.         $this->createVacancy($output$headerNavigation);
  140.         $this->createContact($output$headerNavigation);
  141.         $this->createSearch($output$headerNavigation);
  142.         $this->createJobProfile($output);
  143.         $this->createEmployeeOverviewPage();
  144.         $this->createTestimonialOverviewPage();
  145.         $this->createOption($output);
  146.         $this->createElementOverview();
  147.     }
  148.     /**
  149.      * @param bool $showInMenu
  150.      *
  151.      * @throws Twig_Error_Loader
  152.      * @throws Twig_Error_Runtime
  153.      * @throws Twig_Error_Syntax
  154.      *
  155.      * @return Page
  156.      */
  157.     private function createPage(
  158.         string $title,
  159.         ?string $placeholder null,
  160.         $showInMenu true,
  161.         ?Page $parent null,
  162.         bool $deleteable false,
  163.         ?string $type null,
  164.         ?string $alias null,
  165.         ?string $feature null,
  166.         ?string $systemPageTemplate self::SYSTEM_PAGE_TEMPLATE_BOXED
  167.     ) {
  168.         $body '';
  169.         if ($placeholder) {
  170.             $body $this->twig->render($systemPageTemplate, [
  171.                 'placeholder' => $placeholder,
  172.             ]);
  173.         }
  174.         $page = (new Page())
  175.             ->setTitle($this->translator->trans($title, [], 'pages'$this->locale))
  176.             ->setBody($body)
  177.             ->setShowInMenu($showInMenu)
  178.             ->setParent($parent)
  179.             ->setTranslatableLocale($this->locale)
  180.             ->setDeletable($deleteable)
  181.         ;
  182.         if ($type) {
  183.             $page->setType($type);
  184.         }
  185.         if ($alias) {
  186.             $page->setAlias($alias);
  187.         }
  188.         if ($feature) {
  189.             $page->setFeature($feature);
  190.         }
  191.         $this->entityManager->persist($page);
  192.         $this->entityManager->flush();
  193.         if (!$placeholder) {
  194.             return $page;
  195.         }
  196.         foreach ($this->locales as $locale) {
  197.             $page->setTranslatableLocale($locale);
  198.             $page->setTitle('en' === $locale $title $this->translator->trans($title, [], 'pages'$locale));
  199.             $page->setBody($body);
  200.             $this->entityManager->persist($page);
  201.             $this->entityManager->flush();
  202.         }
  203.         return $page;
  204.     }
  205.     private function createRoute(
  206.         string $name,
  207.         array $staticPrefix,
  208.         array $defaults,
  209.         Page $page,
  210.         ?string $variablePattern null,
  211.         ?array $requirements null
  212.     ) {
  213.         $route = (new Route())
  214.             ->setName($name)
  215.             ->setStaticPrefix($staticPrefix)
  216.             ->setDefaults($defaults)
  217.             ->setPage($page)
  218.         ;
  219.         if ($variablePattern) {
  220.             $route->setVariablePattern($variablePattern);
  221.         }
  222.         if ($requirements) {
  223.             $route->setRequirements($requirements);
  224.         }
  225.         $this->entityManager->persist($route);
  226.         $this->entityManager->flush();
  227.     }
  228.     /**
  229.      * @throws Twig_Error_Loader
  230.      * @throws Twig_Error_Runtime
  231.      * @throws Twig_Error_Syntax
  232.      */
  233.     public function createReview(Page $parent)
  234.     {
  235.         $reviewsPage $this->createPage(
  236.             'Reviews',
  237.             '{reviews}',
  238.             true,
  239.             $parent,
  240.             false,
  241.             null,
  242.             null,
  243.             FeatureFlagListener::FEATURE_REVIEW
  244.         );
  245.         $this->createRoute(
  246.             'review_index',
  247.             $this->routes['review_index'] ?? ['nl' => '/reviews'],
  248.             ['_controller' => ReviewsController::class.':indexAction'],
  249.             $reviewsPage
  250.         );
  251.         $this->createRoute(
  252.             'review_form',
  253.             $this->routes['review_form'] ?? ['nl' => '/reviews/formulier'],
  254.             ['_controller' => ReviewsController::class.':formAction'],
  255.             $this->createPage(
  256.                 'Review form',
  257.                 '{review_form}',
  258.                 false,
  259.                 $reviewsPage,
  260.                 false,
  261.                 null,
  262.                 null,
  263.                 FeatureFlagListener::FEATURE_REVIEW
  264.             )
  265.         );
  266.         $this->createRoute(
  267.             'review_form_confirmation',
  268.             $this->routes['review_form_confirmation'] ?? ['nl' => '/reviews/form/bedankt'],
  269.             ['_controller' => ReviewsController::class.':formConfirmAction'],
  270.             $this->createPage(
  271.                 'Review thanks',
  272.                 '{review_form_thanks}',
  273.                 false,
  274.                 $reviewsPage,
  275.                 false,
  276.                 null,
  277.                 null,
  278.                 FeatureFlagListener::FEATURE_REVIEW
  279.             )
  280.         );
  281.         $this->createRoute(
  282.             'review_detail',
  283.             $this->routes['review_detail'] ?? ['nl' => '/review'],
  284.             ['_controller' => ReviewController::class.':detailAction'],
  285.             $this->createPage(
  286.                 'Review detail',
  287.                 '{review}',
  288.                 false,
  289.                 $reviewsPage,
  290.                 false,
  291.                 null,
  292.                 null,
  293.                 FeatureFlagListener::FEATURE_REVIEW
  294.             )
  295.         );
  296.     }
  297.     /**
  298.      * @throws Twig_Error_Loader
  299.      * @throws Twig_Error_Runtime
  300.      * @throws Twig_Error_Syntax
  301.      *
  302.      * @return Page
  303.      */
  304.     public function createWebring(OutputInterface $output)
  305.     {
  306.         $webRing $this->createPage(
  307.             'Webring',
  308.             null,
  309.             false,
  310.             null,
  311.             false,
  312.             'container',
  313.             'webring'
  314.         );
  315.         $output->writeln('Created webring container');
  316.         return $webRing;
  317.     }
  318.     /**
  319.      * @throws Twig_Error_Loader
  320.      * @throws Twig_Error_Runtime
  321.      * @throws Twig_Error_Syntax
  322.      *
  323.      * @return Page
  324.      */
  325.     public function createRepository(OutputInterface $output)
  326.     {
  327.         $repository $this->createPage(
  328.             'Repository',
  329.             null,
  330.             false,
  331.             null,
  332.             false,
  333.             'container',
  334.             'repository'
  335.         );
  336.         $output->writeln('Created repository container');
  337.         return $repository;
  338.     }
  339.     /**
  340.      * @throws Twig_Error_Loader
  341.      * @throws Twig_Error_Runtime
  342.      * @throws Twig_Error_Syntax
  343.      *
  344.      * @return Page
  345.      */
  346.     public function createHeaderNavigation(OutputInterface $output)
  347.     {
  348.         $headerNavigation $this->createPage(
  349.             'Header navigation',
  350.             null,
  351.             false,
  352.             null,
  353.             false,
  354.             'container',
  355.             'header_navigation'
  356.         );
  357.         $output->writeln('Created header navigation container');
  358.         return $headerNavigation;
  359.     }
  360.     /**
  361.      * @throws Twig_Error_Loader
  362.      * @throws Twig_Error_Runtime
  363.      * @throws Twig_Error_Syntax
  364.      *
  365.      * @return Page
  366.      */
  367.     private function createFooterNavigation(OutputInterface $output)
  368.     {
  369.         $footerNavigation $this->createPage(
  370.             'Footer navigation',
  371.             null,
  372.             false,
  373.             null,
  374.             false,
  375.             'container',
  376.             'footer_navigation'
  377.         );
  378.         $output->writeln('Created footer navigation container');
  379.         return $footerNavigation;
  380.     }
  381.     /**
  382.      * @throws Twig_Error_Loader
  383.      * @throws Twig_Error_Runtime
  384.      * @throws Twig_Error_Syntax
  385.      *
  386.      * @return Page
  387.      */
  388.     private function createFooterBottomNavigation(OutputInterface $output)
  389.     {
  390.         $footerBottomNavigation $this->createPage(
  391.             'Footer bottom navigation',
  392.             null,
  393.             false,
  394.             null,
  395.             false,
  396.             'container',
  397.             'footer_bottom_navigation'
  398.         );
  399.         $output->writeln('Created footer bottom navigation container');
  400.         return $footerBottomNavigation;
  401.     }
  402.     private function createGrid(OutputInterface $output)
  403.     {
  404.         $heads = [
  405.             (new Head())->setName('Eigenschap'),
  406.             (new Head())->setName('Waarde'),
  407.         ];
  408.         $grid = (new Grid())->setName('Default');
  409.         foreach ($heads as $head) {
  410.             $grid->addHead($head);
  411.         }
  412.         $this->entityManager->persist($grid);
  413.         $this->entityManager->flush();
  414.         $output->writeln('Created default Grid');
  415.         $this->entityManager->flush();
  416.         $output->writeln('Added default Grid for Product Grid');
  417.     }
  418.     /**
  419.      * @throws Twig_Error_Loader
  420.      * @throws Twig_Error_Runtime
  421.      * @throws Twig_Error_Syntax
  422.      */
  423.     private function createUserLoginPage(OutputInterface $outputPage $repository)
  424.     {
  425.         $this->createRoute(
  426.             Route::ALIAS_PREFIX.'user_login',
  427.             $this->routes[Route::ALIAS_PREFIX.'user_login'] ?? ['nl' => '/frontend/user/login'],
  428.             [],
  429.             $this->createPage('Frontend User login''{user_login}'true$repositoryfalse)
  430.         );
  431.         $output->writeln('Created user login page');
  432.     }
  433.     /**
  434.      * @throws Twig_Error_Loader
  435.      * @throws Twig_Error_Runtime
  436.      * @throws Twig_Error_Syntax
  437.      */
  438.     private function createAppointmentThanksPage(OutputInterface $outputPage $headerNavigation)
  439.     {
  440.         $this->createRoute(
  441.             'appointment_thanks',
  442.             $this->routes['appointment_thanks'] ?? ['nl' => '/afspraak/bedankt'],
  443.             ['_controller' => AppointmentController::class.':thanksAction'],
  444.             $this->createPage('Appointment thanks''{appointment_thanks}'false$headerNavigationfalse)
  445.         );
  446.         $output->writeln('Created appointment thanks page');
  447.     }
  448.     /**
  449.      * @throws Twig_Error_Loader
  450.      * @throws Twig_Error_Runtime
  451.      * @throws Twig_Error_Syntax
  452.      */
  453.     private function createBlog(OutputInterface $outputPage $headerNavigation)
  454.     {
  455.         $page $this->createPage(
  456.             'Blogs',
  457.             '{blogs}',
  458.             true,
  459.             $headerNavigation,
  460.             false,
  461.             null,
  462.             null,
  463.             FeatureFlagListener::FEATURE_BLOG
  464.         );
  465.         $output->writeln('Created blog overview page');
  466.         $this->createRoute(
  467.             'blogs',
  468.             $this->routes['blogs'] ?? ['nl' => '/blogs'],
  469.             ['_controller' => BlogPostsController::class.':indexAction'],
  470.             $page
  471.         );
  472.         $this->createRoute(
  473.             'blogs_with_filters',
  474.             $this->routes['blogs'] ?? ['nl' => '/blogs'],
  475.             ['_controller' => BlogPostsController::class.':indexAction'],
  476.             $page,
  477.             '/{filters}',
  478.             ['filters' => '.+']
  479.         );
  480.         $page $this->createPage(
  481.             'Blog detail',
  482.             '{blog}',
  483.             false,
  484.             $page,
  485.             false,
  486.             null,
  487.             null,
  488.             FeatureFlagListener::FEATURE_BLOG
  489.         );
  490.         $output->writeln('Created blog detail page');
  491.         $this->createRoute(
  492.             'blog_detail',
  493.             $this->routes['blog_detail'] ?? ['nl' => '/blog'],
  494.             ['_controller' => BlogPostController::class.':detailAction'],
  495.             $page,
  496.             '/{id}/{slug}',
  497.             ['id' => '\d+']
  498.         );
  499.     }
  500.     /**
  501.      * @throws Twig_Error_Loader
  502.      * @throws Twig_Error_Runtime
  503.      * @throws Twig_Error_Syntax
  504.      */
  505.     private function createEvent(OutputInterface $outputPage $headerNavigationPage $repository)
  506.     {
  507.         $page $this->createPage('Events''{events}'false$headerNavigation);
  508.         $output->writeln('Created events overview page');
  509.         $this->createRoute(
  510.             'events',
  511.             $this->routes['events'] ?? ['nl' => '/evenementen'],
  512.             ['_controller' => EventsController::class.':indexAction'],
  513.             $page
  514.         );
  515.         $this->createRoute(
  516.             'events_with_filter',
  517.             $this->routes['events'] ?? ['nl' => '/evenementen'],
  518.             ['_controller' => EventsController::class.':indexAction'],
  519.             $page,
  520.             '/filter/{filters}',
  521.             ['filters' => '.+']
  522.         );
  523.         $output->writeln('Created events with filter page');
  524.         $this->createRoute(
  525.             'event_detail',
  526.             $this->routes['event_detail'] ?? ['nl' => '/evenement'],
  527.             ['_controller' => EventController::class.':detailAction'],
  528.             $this->createPage('Event detail''{event}'true$page),
  529.             '/{id}/{slug}',
  530.             ['id' => '\d+']
  531.         );
  532.         $output->writeln('Created event detail page');
  533.         $this->createRoute(
  534.             'registration',
  535.             $this->routes['registration'] ?? ['nl' => '/registratie'],
  536.             ['_controller' => EventRegistrationController::class.':registrationAction'],
  537.             $this->createPage('Registration''{registration}'false$repository),
  538.             '/{id}/{slug}',
  539.             ['id' => '\d+']
  540.         );
  541.         $output->writeln('Created registration detail page');
  542.         $this->createRoute(
  543.             'registration_thanks',
  544.             $this->routes['registration_thanks'] ?? ['nl' => '/registratie/bedankt'],
  545.             ['_controller' => EventRegistrationController::class.':thanksRegistrationAction'],
  546.             $this->createPage('Registration thanks''{registration_thanks}'false$repository)
  547.         );
  548.         $output->writeln('Created registration thanks page');
  549.     }
  550.     /**
  551.      * @throws Twig_Error_Loader
  552.      * @throws Twig_Error_Runtime
  553.      * @throws Twig_Error_Syntax
  554.      */
  555.     private function createJobAlert(OutputInterface $outputPage $headerNavigation)
  556.     {
  557.         $jobAlertPage $this->createPage('Jobalert''{jobalert_form}'true$headerNavigation);
  558.         $this->createRoute(
  559.             'jobalert',
  560.             $this->routes['jobalert'] ?? ['nl' => '/jobalert'],
  561.             ['_controller' => JobAlertController::class.':indexAction'],
  562.             $jobAlertPage
  563.         );
  564.         $output->writeln('Created jobalert page');
  565.         $this->createRoute(
  566.             'jobalert_thanks',
  567.             $this->routes['jobalert_thanks'] ?? ['nl' => '/jobalert/bedankt'],
  568.             ['_controller' => JobAlertController::class.':thanksAction'],
  569.             $this->createPage('JobAlert thanks''{jobalert_thanks}'false$jobAlertPage)
  570.         );
  571.         $output->writeln('Created jobalert thanks page');
  572.     }
  573.     /**
  574.      * @throws Twig_Error_Loader
  575.      * @throws Twig_Error_Runtime
  576.      * @throws Twig_Error_Syntax
  577.      */
  578.     private function createOrder(OutputInterface $outputPage $headerNavigation)
  579.     {
  580.         $this->createRoute(
  581.             'order_thanks',
  582.             $this->routes['order_thanks'] ?? ['nl' => '/bestelling/bedankt'],
  583.             ['_controller' => OrderController::class.':thanksInvoiceAction'],
  584.             $this->createPage('Order thanks''{order_thanks}'false$headerNavigation)
  585.         );
  586.         $output->writeln('Created order thanks page');
  587.     }
  588.     /**
  589.      * @throws Twig_Error_Loader
  590.      * @throws Twig_Error_Runtime
  591.      * @throws Twig_Error_Syntax
  592.      */
  593.     private function createSample(OutputInterface $outputPage $headerNavigation)
  594.     {
  595.         $this->createRoute(
  596.             'request_sample',
  597.             $this->routes['request_sample'] ?? ['nl' => '/bestelling/sample-aanvraag'],
  598.             ['_controller' => OrderSnippetController::class.':requestSampleAction'],
  599.             $this->createPage('Request a sample''{request_sample}'false$headerNavigation),
  600.             '/{id}'
  601.         );
  602.         $output->writeln('Created request sample page');
  603.         $this->createRoute(
  604.             'sample_thanks',
  605.             $this->routes['sample_thanks'] ?? ['nl' => '/bestelling/sample-bedankt'],
  606.             ['_controller' => OrderController::class.':thanksSampleAction'],
  607.             $this->createPage(
  608.                 'Thank you for requesting a sample',
  609.                 '{sample_thanks}',
  610.                 false,
  611.                 $headerNavigation
  612.             )
  613.         );
  614.         $output->writeln('Created sample thanks page');
  615.     }
  616.     /**
  617.      * @throws Twig_Error_Loader
  618.      * @throws Twig_Error_Runtime
  619.      * @throws Twig_Error_Syntax
  620.      */
  621.     private function createPortfolio(OutputInterface $outputPage $repository)
  622.     {
  623.         $portfoliosPage $this->createPage('Portfolio''{portfolios}'false$repository);
  624.         $this->createRoute(
  625.             'portfolios',
  626.             $this->routes['portfolios'] ?? ['nl' => '/portfolios'],
  627.             ['_controller' => PortfoliosController::class.':indexAction'],
  628.             $portfoliosPage
  629.         );
  630.         $output->writeln('Created portfolio overview page');
  631.         $this->createRoute(
  632.             'portfolio_detail',
  633.             $this->routes['portfolio_detail'] ?? ['nl' => '/portfolio'],
  634.             ['_controller' => PortfolioController::class.':detailAction'],
  635.             $this->createPage('Portfolio detail''{portfolio}'false$portfoliosPage),
  636.             '/{id}/{slug}',
  637.             ['id' => '\d+']
  638.         );
  639.         $output->writeln('Created portfolio detail page');
  640.     }
  641.     /**
  642.      * @throws Twig_Error_Loader
  643.      * @throws Twig_Error_Runtime
  644.      * @throws Twig_Error_Syntax
  645.      */
  646.     private function createProduct(OutputInterface $outputPage $repository)
  647.     {
  648.         $productsPage $this->createPage(
  649.             'Products',
  650.             '{products}',
  651.             true,
  652.             $repository,
  653.             false,
  654.             null,
  655.             null,
  656.             FeatureFlagListener::FEATURE_PRODUCT
  657.         );
  658.         $this->createRoute(
  659.             'products',
  660.             $this->routes['products'] ?? ['nl' => '/producten'],
  661.             ['_controller' => ProductsController::class.':indexAction'],
  662.             $productsPage
  663.         );
  664.         $this->createRoute(
  665.             'products_with_filter',
  666.             $this->routes['products'] ?? ['nl' => '/producten'],
  667.             ['_controller' => ProductsController::class.':indexAction'],
  668.             $productsPage,
  669.             '/{filters}',
  670.             ['filters' => '.+']
  671.         );
  672.         $output->writeln('Created vacancy page');
  673.         $productDetailPage $this->createPage(
  674.             'Product detail',
  675.             '{product}',
  676.             false,
  677.             $productsPage,
  678.             false,
  679.             null,
  680.             null,
  681.             FeatureFlagListener::FEATURE_PRODUCT
  682.         );
  683.         $this->createRoute(
  684.             'product_detail',
  685.             $this->routes['product_detail'] ?? ['nl' => '/product'],
  686.             ['_controller' => ProductController::class.':detailAction'],
  687.             $productDetailPage,
  688.             '/{id}/{slug}'
  689.         );
  690.         $this->createRoute(
  691.             'product_detail_without_slug',
  692.             $this->routes['product_detail'] ?? ['nl' => '/product'],
  693.             ['_controller' => ProductController::class.':detailAction'],
  694.             $productDetailPage,
  695.             '/{id}'
  696.         );
  697.         $output->writeln('Created vacancy detail page');
  698.     }
  699.     /**
  700.      * @throws Twig_Error_Loader
  701.      * @throws Twig_Error_Runtime
  702.      * @throws Twig_Error_Syntax
  703.      */
  704.     private function createContact(OutputInterface $outputPage $parent)
  705.     {
  706.         $contactPage $this->createPage('Contact''{contact_form}'true$parent);
  707.         $this->createRoute(
  708.             'contact',
  709.             $this->routes['contact'] ?? ['nl' => 'contact'],
  710.             ['_controller' => ContactController::class.':indexAction'],
  711.             $contactPage
  712.         );
  713.         $output->writeln('Created contact page');
  714.         $this->createRoute(
  715.             'contact_thanks',
  716.             $this->routes['contact_thanks'] ?? ['nl' => '/contact/bedankt'],
  717.             ['_controller' => ContactController::class.':thankAction'],
  718.             $this->createPage('Contact thanks''{contact_thanks}'false$contactPage)
  719.         );
  720.         $output->writeln('Created contact thanks page');
  721.     }
  722.     /**
  723.      * @throws Twig_Error_Loader
  724.      * @throws Twig_Error_Runtime
  725.      * @throws Twig_Error_Syntax
  726.      */
  727.     private function createNewsletter(OutputInterface $outputPage $headerNavigation)
  728.     {
  729.         $this->createRoute(
  730.             'newsletter_subscribe',
  731.             $this->routes['newsletter_subscribe'] ?? ['nl' => '/nieuwsbrief/aanmelden'],
  732.             ['_controller' => NewsletterController::class.':subscribeAction'],
  733.             $this->createPage(
  734.                 'Subscribed to our newsletter',
  735.                 '{newsletter_subscribe}',
  736.                 false,
  737.                 $headerNavigation
  738.             ),
  739.             '/{email}'
  740.         );
  741.         $output->writeln('Newsletter Subscribed page is created');
  742.     }
  743.     /**
  744.      * @throws Twig_Error_Loader
  745.      * @throws Twig_Error_Runtime
  746.      * @throws Twig_Error_Syntax
  747.      */
  748.     private function createHomepage(OutputInterface $outputPage $parent)
  749.     {
  750.         $this->createRoute(
  751.             'homepage',
  752.             $this->routes['homepage'] ?? ['nl' => '/'],
  753.             [],
  754.             $this->createPage(
  755.                 'Homepage',
  756.                 'Welkom',
  757.                 true,
  758.                 $parent,
  759.                 false,
  760.                 null,
  761.                 Page::ALIAS_HOMEPAGE
  762.             )
  763.         );
  764.         $output->writeln('Created homepage page');
  765.     }
  766.     /**
  767.      * @throws Twig_Error_Loader
  768.      * @throws Twig_Error_Runtime
  769.      * @throws Twig_Error_Syntax
  770.      */
  771.     private function add404Page(OutputInterface $outputPage $repository)
  772.     {
  773.         $this->createRoute(
  774.             '404_page',
  775.             $this->routes['404_page'] ?? ['nl' => '/404'],
  776.             [],
  777.             $this->createPage(
  778.                 '404 page',
  779.                 'This page cannot be displayed',
  780.                 false,
  781.                 $repository,
  782.                 false,
  783.                 null,
  784.                 '404_page'
  785.             )
  786.         );
  787.         $output->writeln('Created 404 page');
  788.     }
  789.     /**
  790.      * @throws Twig_Error_Loader
  791.      * @throws Twig_Error_Runtime
  792.      * @throws Twig_Error_Syntax
  793.      */
  794.     private function add500Page(OutputInterface $outputPage $repository)
  795.     {
  796.         $this->createRoute(
  797.             '500_page',
  798.             $this->routes['500_page'] ?? ['nl' => '/500'],
  799.             [],
  800.             $this->createPage(
  801.                 '500 page',
  802.                 'Sorry, we had some technical problems during your last operation.',
  803.                 false,
  804.                 $repository,
  805.                 false,
  806.                 null,
  807.                 '500_page'
  808.             )
  809.         );
  810.         $output->writeln('Created 500 page');
  811.     }
  812.     /**
  813.      * @throws Twig_Error_Loader
  814.      * @throws Twig_Error_Runtime
  815.      * @throws Twig_Error_Syntax
  816.      */
  817.     private function createTestimonial(OutputInterface $outputPage $headerNavigation)
  818.     {
  819.         $this->createRoute(
  820.             'testimonial_detail',
  821.             $this->routes['testimonial_detail'] ?? ['nl' => '/testimonial'],
  822.             ['_controller' => TestimonialController::class.':detailAction'],
  823.             $this->createPage('Testimonial detail''{testimonial}'false$headerNavigation),
  824.             '/{id}/{slug}'
  825.         );
  826.         $output->writeln('Created testimonial detail page');
  827.     }
  828.     /**
  829.      * @throws Twig_Error_Loader
  830.      * @throws Twig_Error_Runtime
  831.      * @throws Twig_Error_Syntax
  832.      */
  833.     private function createOption(OutputInterface $output)
  834.     {
  835.         $educationOption = new Option();
  836.         $educationOption
  837.             ->setTitle('Opleiding')
  838.             ->addValue((new OptionValue())->setValue('Elementair'))
  839.             ->addValue((new OptionValue())->setValue('MAVO'))
  840.             ->addValue((new OptionValue())->setValue('HAVO'))
  841.             ->addValue((new OptionValue())->setValue('VWO'))
  842.             ->addValue((new OptionValue())->setValue('VMBO'))
  843.             ->addValue((new OptionValue())->setValue('MBO'))
  844.             ->addValue((new OptionValue())->setValue('HBO'))
  845.             ->addValue((new OptionValue())->setValue('WO'))
  846.         ;
  847.         $this->entityManager->persist($educationOption);
  848.         $this->entityManager->flush();
  849.         $regionOption = new Option();
  850.         $regionOption
  851.             ->setTitle('Regio')
  852.             ->addValue((new OptionValue())->setValue('Drenthe'))
  853.             ->addValue((new OptionValue())->setValue('Flevoland'))
  854.             ->addValue((new OptionValue())->setValue('Friesland'))
  855.             ->addValue((new OptionValue())->setValue('Gelderland'))
  856.             ->addValue((new OptionValue())->setValue('Groningen'))
  857.             ->addValue((new OptionValue())->setValue('Limburg'))
  858.             ->addValue((new OptionValue())->setValue('Noord-Brabant'))
  859.             ->addValue((new OptionValue())->setValue('Noord-Holland'))
  860.             ->addValue((new OptionValue())->setValue('Overijssel'))
  861.             ->addValue((new OptionValue())->setValue('Utrecht'))
  862.             ->addValue((new OptionValue())->setValue('Zeeland'))
  863.             ->addValue((new OptionValue())->setValue('Zuid-Holland'))
  864.         ;
  865.         $this->entityManager->persist($regionOption);
  866.         $this->entityManager->flush();
  867.         $disciplineOption = new Option();
  868.         $disciplineOption
  869.             ->setTitle('Vakgebied')
  870.             ->addValue((new OptionValue())->setValue('Front-end development'))
  871.             ->addValue((new OptionValue())->setValue('Back-end development'))
  872.             ->addValue((new OptionValue())->setValue('Projectmanagement'))
  873.             ->addValue((new OptionValue())->setValue('Online marketing'))
  874.             ->addValue((new OptionValue())->setValue('Design'))
  875.             ->addValue((new OptionValue())->setValue('Administratief'))
  876.             ->addValue((new OptionValue())->setValue('Sales'))
  877.         ;
  878.         $this->entityManager->persist($disciplineOption);
  879.         $this->entityManager->flush();
  880.         $output->writeln('Created options');
  881.         $optionDetailPage $this->createPage(
  882.             'Option detail',
  883.             '{option}',
  884.             false,
  885.             null,
  886.             false,
  887.             null,
  888.             null,
  889.             null,
  890.             self::SYSTEM_PAGE_TEMPLATE_EMPTY
  891.         );
  892.         $this->createRoute(
  893.             'option_detail',
  894.             $this->routes['option_detail'] ?? ['nl' => '/option'],
  895.             ['_controller' => OptionController::class.':detailAction'],
  896.             $optionDetailPage,
  897.             '/{optionSlug}/{optionValueSlug}'
  898.         );
  899.         $output->writeln('Created option option detail page');
  900.         $optionsOptionDetailPage $this->createPage(
  901.             'Options option detail',
  902.             '{option}',
  903.             false,
  904.             null,
  905.             false,
  906.             null,
  907.             null,
  908.             null,
  909.             self::SYSTEM_PAGE_TEMPLATE_EMPTY
  910.         );
  911.         $this->createRoute(
  912.             'options_option_detail',
  913.             $this->routes['options_option_detail'] ?? ['nl' => '/options'],
  914.             ['_controller' => OptionController::class.':optionDetail'],
  915.             $optionsOptionDetailPage,
  916.             '/{subOptions}'
  917.         );
  918.         $output->writeln('Created options option detail page');
  919.     }
  920.     /**
  921.      * @throws Twig_Error_Loader
  922.      * @throws Twig_Error_Runtime
  923.      * @throws Twig_Error_Syntax
  924.      */
  925.     private function createVacancy(OutputInterface $outputPage $headerNavigation)
  926.     {
  927.         $applicantFormFields = [
  928.             [
  929.                 'type' => 'text',
  930.                 'required' => true,
  931.                 'label' => 'Voornaam',
  932.                 'className' => 'form-control',
  933.                 'name' => 'firstname',
  934.             ],
  935.             [
  936.                 'type' => 'text',
  937.                 'required' => true,
  938.                 'label' => 'Achternaam',
  939.                 'className' => 'form-control',
  940.                 'name' => 'lastname',
  941.             ],
  942.             [
  943.                 'type' => 'text',
  944.                 'required' => true,
  945.                 'label' => 'Stad',
  946.                 'className' => 'form-control',
  947.                 'name' => 'city',
  948.                 'maxlength' => 15,
  949.             ],
  950.             [
  951.                 'type' => 'text',
  952.                 'required' => true,
  953.                 'label' => 'Telefoonnummer',
  954.                 'className' => 'form-control',
  955.                 'name' => 'phone',
  956.                 'maxlength' => 15,
  957.             ],
  958.             [
  959.                 'type' => 'text',
  960.                 'required' => true,
  961.                 'label' => 'E-mailadres',
  962.                 'className' => 'form-control',
  963.                 'name' => 'email',
  964.                 'maxlength' => 100,
  965.             ],
  966.             [
  967.                 'type' => 'textarea',
  968.                 'required' => true,
  969.                 'label' => 'Motivatie',
  970.                 'className' => 'form-control',
  971.                 'name' => 'motivation',
  972.                 'rows' => 20,
  973.             ],
  974.             [
  975.                 'type' => 'file',
  976.                 'required' => true,
  977.                 'label' => 'CV Uploaden',
  978.                 'className' => 'form-control',
  979.                 'name' => 'CVFile',
  980.             ],
  981.         ];
  982.         $forms $this->entityManager->getRepository(ApplicantForm::class)->findAll();
  983.         if (empty($forms)) {
  984.             $applicantForm = (new ApplicantForm())
  985.                 ->setTitle('Default')
  986.                 ->setDefault(true)
  987.                 ->setFields(json_encode($applicantFormFields))
  988.             ;
  989.             $this->entityManager->persist($applicantForm);
  990.             $this->entityManager->flush();
  991.         }
  992.         $vacanciesPage $this->createPage('Vacancies''{vacancies}'true$headerNavigationfalsefalsenullFeatureFlagListener::FEATURE_VACANCY);
  993.         $vacancyApplyPage $this->createPage('Applicant form''{vacancy_apply}'false$vacanciesPage);
  994.         $this->createRoute(
  995.             'vacancy_apply',
  996.             $this->routes['vacancy_apply'] ?? ['nl' => '/vacature-solliciteren'],
  997.             ['_controller' => ApplicantController::class.':formAction'],
  998.             $vacancyApplyPage,
  999.             '/{id}'
  1000.         );
  1001.         $output->writeln('Created vacancy apply page');
  1002.         $this->createRoute(
  1003.             'vacancy_apply_thanks',
  1004.             $this->routes['vacancy_apply_thanks'] ?? ['nl' => '/vacature-solliciteren-bedankt'],
  1005.             ['_controller' => 'App\Controller\Page\ApplicantController'.':thanksAction''id' => null],
  1006.             $this->createPage('Thank you for applying''{vacancy_apply_thanks}'false$vacancyApplyPage),
  1007.             '/{id}'
  1008.         );
  1009.         $output->writeln('Created vacancy apply thanks page');
  1010.         $this->createRoute(
  1011.             'vacancies',
  1012.             $this->routes['vacancies'] ?? ['nl' => '/vacatures'],
  1013.             ['_controller' => VacanciesController::class.':indexAction'],
  1014.             $vacanciesPage
  1015.         );
  1016.         $this->createRoute(
  1017.             'vacancies_with_filter',
  1018.             $this->routes['vacancies'] ?? ['nl' => '/vacatures'],
  1019.             ['_controller' => VacanciesController::class.':indexAction'],
  1020.             $vacanciesPage,
  1021.             '/{filters}',
  1022.             ['filters' => '.+']
  1023.         );
  1024.         $output->writeln('Created vacancy page');
  1025.         $vacancyDetailPage $this->createPage('Vacancy detail''{vacancy}'false$vacanciesPage);
  1026.         $this->createRoute(
  1027.             'vacancy_detail',
  1028.             $this->routes['vacancy_detail'] ?? ['nl' => '/vacature'],
  1029.             ['_controller' => VacancyController::class.':detailAction'],
  1030.             $vacancyDetailPage,
  1031.             '/{id}/{slug}',
  1032.             ['id' => '\d+']
  1033.         );
  1034.         $this->createRoute(
  1035.             'vacancy_detail_without_slug',
  1036.             $this->routes['vacancy_detail'] ?? ['nl' => '/vacature'],
  1037.             ['_controller' => VacancyController::class.':detailAction'],
  1038.             $vacancyDetailPage,
  1039.             '/{id}',
  1040.             ['id' => '\d+']
  1041.         );
  1042.         $output->writeln('Created vacancy detail page');
  1043.         $this->createRoute(
  1044.             'favorites',
  1045.             $this->routes['favorites'],
  1046.             ['_controller' => VacanciesController::class.':favoritesOverviewAction'],
  1047.             $this->createPage('Favorites''{favorites}'false$headerNavigation)
  1048.         );
  1049.         $output->writeln('Created favorites overview page');
  1050.         $vacancyCreatePage $this->createPage('Vacancy create''{vacancy_create}'false$headerNavigation);
  1051.         $this->createRoute(
  1052.             'vacancy_create_without_account',
  1053.             $this->routes['vacancy_create_without_account'] ?? ['nl' => '/vacature-aanmaken'],
  1054.             ['_controller' => VacancyController::class.':create'],
  1055.             $vacancyCreatePage
  1056.         );
  1057.         $output->writeln('Created vacancy create page');
  1058.         $this->createRoute(
  1059.             'vacancy_create_without_account_thanks',
  1060.             $this->routes['vacancy_create_without_account_thanks'] ?? ['nl' => '/vacature-aanmaken-bedankt'],
  1061.             [],
  1062.             $this->createPage('Thank you for creating a vacancy'nullfalse$vacancyCreatePage)
  1063.         );
  1064.         $output->writeln('Created vacancy create thanks page');
  1065.     }
  1066.     /**
  1067.      * @throws Twig_Error_Loader
  1068.      * @throws Twig_Error_Runtime
  1069.      * @throws Twig_Error_Syntax
  1070.      */
  1071.     private function createCompany(OutputInterface $outputPage $parent)
  1072.     {
  1073.         $companiesPage $this->createPage('Companies''{companies}'false$parent);
  1074.         $this->createRoute(
  1075.             'companies',
  1076.             $this->routes['companies'] ?? ['nl' => '/bedrijven'],
  1077.             ['_controller' => CompaniesController::class.':indexAction'],
  1078.             $companiesPage
  1079.         );
  1080.         $output->writeln('Created company page');
  1081.         $this->createRoute(
  1082.             'company_with_filter',
  1083.             $this->routes['companies'] ?? ['nl' => '/bedrijven'],
  1084.             ['_controller' => CompanyController::class.':indexAction'],
  1085.             $companiesPage,
  1086.             '/{filters}',
  1087.             ['filters' => '.+']
  1088.         );
  1089.         $output->writeln('Created company page wih filter');
  1090.         $companyDetailPage $this->createPage(
  1091.             'Company detail',
  1092.             '{company}',
  1093.             false,
  1094.             $companiesPage
  1095.         );
  1096.         $this->createRoute(
  1097.             'company_detail',
  1098.             $this->routes['company_detail'] ?? ['nl' => '/bedrijf'],
  1099.             ['_controller' => CompanyController::class.':detailAction'],
  1100.             $companyDetailPage,
  1101.             '/{id}/{slug}'
  1102.         );
  1103.         $this->createRoute(
  1104.             'company_detail_without_slug',
  1105.             $this->routes['company_detail'] ?? ['nl' => '/bedrijf'],
  1106.             ['_controller' => CompanyController::class.':detailAction'],
  1107.             $companyDetailPage,
  1108.             '/{id}'
  1109.         );
  1110.         $output->writeln('Created company detail page');
  1111.     }
  1112.     /**
  1113.      * @throws Twig_Error_Loader
  1114.      * @throws Twig_Error_Runtime
  1115.      * @throws Twig_Error_Syntax
  1116.      */
  1117.     private function createEmployees(Page $parent)
  1118.     {
  1119.         $employeeDetailPage $this->createPage('Employee detail''{employee}'false$parent);
  1120.         $this->createRoute(
  1121.             'employee_detail',
  1122.             $this->routes['employee_detail'] ?? ['nl' => 'medewerker'],
  1123.             ['_controller' => EmployeeController::class.':detailAction'],
  1124.             $employeeDetailPage,
  1125.             '/{id}/{slug}'
  1126.         );
  1127.     }
  1128.     /**
  1129.      * @throws Twig_Error_Loader
  1130.      * @throws Twig_Error_Runtime
  1131.      * @throws Twig_Error_Syntax
  1132.      */
  1133.     private function createSearch(OutputInterface $outputPage $headerNavigation)
  1134.     {
  1135.         $searchPage $this->createPage('Zoekresultaten''{search_results}'false$headerNavigation);
  1136.         $this->createRoute(
  1137.             'search',
  1138.             $this->routes['search'] ?? ['nl' => '/zoeken'],
  1139.             ['_controller' => SearchController::class.':searchAction'],
  1140.             $searchPage
  1141.         );
  1142.         $output->writeln('Created search page');
  1143.     }
  1144.     private function createJobProfile(OutputInterface $output)
  1145.     {
  1146.         $profilesPage $this->createPage('Profielen''{job_profiles}'falsenullfalsenullnullFeatureFlagListener::FEATURE_MOBILITY_PLATFORM);
  1147.         $staticPrefixes $this->routes['job_profiles'] ?? ['nl' => '/'];
  1148.         $this->createRoute(
  1149.             'job_profiles',
  1150.             $staticPrefixes,
  1151.             ['_controller' => MobilityController::class.':jobProfiles'],
  1152.             $profilesPage
  1153.         );
  1154.         $this->createRoute(
  1155.             'job_profiles_with_filter',
  1156.             $staticPrefixes,
  1157.             ['_controller' => MobilityController::class.':jobProfiles'],
  1158.             $profilesPage,
  1159.             '/{filters}',
  1160.             ['filters' => '.+']
  1161.         );
  1162.         $profilePage $this->createPage('Profiel''{job_profile}'falsenullfalsenullnullFeatureFlagListener::FEATURE_MOBILITY_PLATFORM);
  1163.         $this->createRoute(
  1164.             'job_profile',
  1165.             $this->routes['job_profile'] ?? ['nl' => '/user/mobility/profiel'],
  1166.             ['_controller' => MobilityController::class.':jobProfile'],
  1167.             $profilePage,
  1168.             '/{id}'
  1169.         );
  1170.     }
  1171.     public function createEmployeeOverviewPage()
  1172.     {
  1173.         $employeeOverviewPage $this->createPage('Employees''{employees}'false);
  1174.         $this->createRoute(
  1175.             'employees',
  1176.             $this->routes['employees'] ?? ['nl' => '/medewerkers'],
  1177.             ['_controller' => EmployeeController::class.':index'],
  1178.             $employeeOverviewPage,
  1179.         );
  1180.     }
  1181.     public function createTestimonialOverviewPage()
  1182.     {
  1183.         $testimonialOverviewPage $this->createPage('Testimonials''{testimonials}'false);
  1184.         $this->createRoute(
  1185.             'testimonials',
  1186.             $this->routes['testimonials'] ?? ['nl' => '/getuigenissen'],
  1187.             ['_controller' => TestimonialController::class.':index'],
  1188.             $testimonialOverviewPage,
  1189.         );
  1190.     }
  1191.     private function createElementOverview(): void
  1192.     {
  1193.         $elementOverviewPage $this->createPage('Elements''{elements}'false);
  1194.         $this->createRoute(
  1195.             'elements',
  1196.             $this->routes['elements'] ?? ['nl' => '/elements'],
  1197.             ['_controller' => ElementController::class.':index'],
  1198.             $elementOverviewPage,
  1199.         );
  1200.     }
  1201. }