src/Kunstmaan/SeoBundle/Controller/Admin/SettingsController.php
public function robotsSettingsAction(Request $request)
    {
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');

        $em = $this->getDoctrine()->getManager();
        $repo = $this->getDoctrine()->getRepository('KunstmaanSeoBundle:Robots');
        $robot = $repo->findOneBy(array());
        $default = $this->container->getParameter('robots_default');
        $isSaved = true;

        if (!$robot) {
            $robot = new Robots();
        }

        if ($robot->getRobotsTxt() == null) {
            $robot->setRobotsTxt($default);
            $isSaved = false;
        }

        $form = $this->createForm(RobotsType::class, $robot, array(
            'action' => $this->generateUrl('KunstmaanSeoBundle_settings_robots'),
        ));
        if ($request->isMethod('POST')) {
            $form->handleRequest($request);
            if ($form->isSubmitted() && $form->isValid()) {
                $em->persist($robot);
                $em->flush();

                return new RedirectResponse($this->generateUrl('KunstmaanSeoBundle_settings_robots'));
            }
        }

        if (!$isSaved) {
            $this->addFlash(
                FlashTypes::WARNING,
                $this->container->get('translator')->trans('seo.robots.warning')
            );
        }

        return array(
            'form' => $form->createView(),
        );
    }
public function robotsSettingsAction(Request $request)
    {
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');

        $em = $this->getDoctrine()->getManager();
        $repo = $this->getDoctrine()->getRepository('KunstmaanSeoBundle:Robots');
        $robot = $repo->findOneBy(array());
        $default = $this->container->getParameter('robots_default');
        $isSaved = true;

        if (!$robot) {
            $robot = new Robots();
        }

        if ($robot->getRobotsTxt() == null) {
            $robot->setRobotsTxt($default);
            $isSaved = false;
        }

        $form = $this->createForm(RobotsType::class, $robot, array(
            'action' => $this->generateUrl('KunstmaanSeoBundle_settings_robots'),
        ));
        if ($request->isMethod('POST')) {
            $form->handleRequest($request);
            if ($form->isSubmitted() && $form->isValid()) {
                $em->persist($robot);
                $em->flush();

                return new RedirectResponse($this->generateUrl('KunstmaanSeoBundle_settings_robots'));
            }
        }

        if (!$isSaved) {
            $this->addFlash(
                FlashTypes::WARNING,
                $this->container->get('translator')->trans('seo.robots.warning')
            );
        }

        return array(
            'form' => $form->createView(),
        );
    }
public function robotsSettingsAction ( Request $ request ) { $ this -> denyAccessUnlessGranted ( 'ROLE_SUPER_ADMIN' ) ; $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ repo = $ this -> getDoctrine ( ) -> getRepository ( 'KunstmaanSeoBundle:Robots' ) ; $ robot = $ repo -> findOneBy ( array ( ) ) ; $ default = $ this -> container -> getParameter ( 'robots_default' ) ; $ isSaved = true ; if ( ! $ robot ) { $ robot = new Robots ( ) ; } if ( $ robot -> getRobotsTxt ( ) == null ) { $ robot -> setRobotsTxt ( $ default ) ; $ isSaved = false ; } $ form = $ this -> createForm ( RobotsType :: class , $ robot , array ( 'action' => $ this -> generateUrl ( 'KunstmaanSeoBundle_settings_robots' ) , ) ) ; if ( $ request -> isMethod ( 'POST' ) ) { $ form -> handleRequest ( $ request ) ; if ( $ form -> isSubmitted ( ) && $ form -> isValid ( ) ) { $ em -> persist ( $ robot ) ; $ em -> flush ( ) ; return new RedirectResponse ( $ this -> generateUrl ( 'KunstmaanSeoBundle_settings_robots' ) ) ; } } if ( ! $ isSaved ) { $ this -> addFlash ( FlashTypes :: WARNING , $ this -> container -> get ( 'translator' ) -> trans ( 'seo.robots.warning' ) ) ; } return array ( 'form' => $ form -> createView ( ) , ) ; }
Generates the robots administration form and fills it with a default value if needed.

@Route(path="/", name="KunstmaanSeoBundle_settings_robots")
@Template(template="@KunstmaanSeo/Admin/Settings/robotsSettings.html.twig")

@param Request $request

@return array|RedirectResponse
Generates the robots administration form and fills it with a default value if needed .