Completed
Push — master ( 91fdab...75a7b9 )
by
unknown
13:37
created

SeoBundle/Controller/Admin/SettingsController.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\SeoBundle\Controller\Admin;
4
5
use Kunstmaan\AdminBundle\Controller\BaseSettingsController;
6
use Kunstmaan\AdminBundle\FlashMessages\FlashTypes;
7
use Kunstmaan\SeoBundle\Entity\Robots;
8
use Kunstmaan\SeoBundle\Form\RobotsType;
9
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
11
12
use Symfony\Component\HttpFoundation\RedirectResponse;
13
use Symfony\Component\HttpFoundation\Request;
14
15
16
class SettingsController extends BaseSettingsController
17
{
18
    /**
19
     * Generates the robots administration form and fills it with a default value if needed.
20
     *
21
     * @Route(path="/", name="KunstmaanSeoBundle_settings_robots")
22
     * @Template(template="@KunstmaanSeo/Admin/Settings/robotsSettings.html.twig")
23
     * @param Request $request
24
     * @return array|RedirectResponse
0 ignored issues
show
Consider making the return type a bit more specific; maybe use RedirectResponse|array<s...omponent\Form\FormView>.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
25
     */
26
    public function robotsSettingsAction(Request $request)
27
    {
28
        $this->denyAccessUnlessGranted('ROLE_SUPER_ADMIN');
29
30
        $em = $this->getDoctrine()->getManager();
31
        $repo = $this->getDoctrine()->getRepository("KunstmaanSeoBundle:Robots");
32
        $robot = $repo->findOneBy(array());
33
        $default = $this->container->getParameter('robots_default');
34
        $isSaved = true;
35
36
        if (!$robot) {
37
            $robot = new Robots();
38
        }
39
40
        if ($robot->getRobotsTxt() == NULL) {
41
            $robot->setRobotsTxt($default);
42
            $isSaved = false;
43
        }
44
45
        $form = $this->createForm(RobotsType::class, $robot, array(
46
            'action' => $this->generateUrl('KunstmaanSeoBundle_settings_robots')
47
        ));
48
        if ($request->isMethod('POST')) {
49
            $form->handleRequest($request);
50
            if ($form->isSubmitted() && $form->isValid()) {
51
52
                $em->persist($robot);
53
                $em->flush();
54
55
                return new RedirectResponse($this->generateUrl('KunstmaanSeoBundle_settings_robots'));
56
            }
57
        }
58
59
        if (!$isSaved) {
60
            $this->addFlash(
61
                FlashTypes::WARNING,
62
                $this->container->get('translator')->trans('seo.robots.warning')
63
            );
64
        }
65
66
        return array(
67
            'form' => $form->createView(),
68
        );
69
    }
70
}
71