Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
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 Symfony\Component\Routing\Annotation\Route;
10
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
11
use Symfony\Component\HttpFoundation\RedirectResponse;
12
use Symfony\Component\HttpFoundation\Request;
13
14
class SettingsController extends BaseSettingsController
15
{
16
    /**
17
     * Generates the robots administration form and fills it with a default value if needed.
18
     *
19
     * @Route(path="/", name="KunstmaanSeoBundle_settings_robots")
20
     * @Template(template="@KunstmaanSeo/Admin/Settings/robotsSettings.html.twig")
21
     *
22
     * @param Request $request
23
     *
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
                $em->persist($robot);
52
                $em->flush();
53
54
                return new RedirectResponse($this->generateUrl('KunstmaanSeoBundle_settings_robots'));
55
            }
56
        }
57
58
        if (!$isSaved) {
59
            $this->addFlash(
60
                FlashTypes::WARNING,
61
                $this->container->get('translator')->trans('seo.robots.warning')
62
            );
63
        }
64
65
        return array(
66
            'form' => $form->createView(),
67
        );
68
    }
69
}
70