Completed
Push — master ( 8fc13e...c19aa3 )
by Axel
06:21
created

ConfigController::configAction()   A

Complexity

Conditions 6
Paths 8

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 16
nc 8
nop 2
dl 0
loc 26
rs 9.1111
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Zikula package.
7
 *
8
 * Copyright Zikula Foundation - https://ziku.la/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Zikula\GroupsModule\Controller;
15
16
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
17
use Symfony\Component\HttpFoundation\RedirectResponse;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\Routing\Annotation\Route;
20
use Zikula\Bundle\CoreBundle\Controller\AbstractController;
21
use Zikula\GroupsModule\Entity\RepositoryInterface\GroupRepositoryInterface;
22
use Zikula\GroupsModule\Form\Type\ConfigType;
23
use Zikula\PermissionsModule\Annotation\PermissionCheck;
24
use Zikula\ThemeModule\Engine\Annotation\Theme;
25
26
/**
27
 * Class ConfigController
28
 *
29
 * @Route("/config")
30
 * @PermissionCheck("admin")
31
 */
32
class ConfigController extends AbstractController
33
{
34
    /**
35
     * @Route("/config")
36
     * @Theme("admin")
37
     * @Template("@ZikulaGroupsModule/Config/config.html.twig")
38
     *
39
     * @return array|RedirectResponse
40
     */
41
    public function configAction(Request $request, GroupRepositoryInterface $groupRepository)
42
    {
43
        // build a groups array suitable for the form choices
44
        $groupsList = [];
45
        $groups = $groupRepository->findAll();
46
        foreach ($groups as $group) {
47
            $groupsList[$group->getName()] = $group->getGid();
48
        }
49
50
        $form = $this->createForm(ConfigType::class, $this->getVars(), [
51
            'groups' => $groupsList
52
        ]);
53
        $form->handleRequest($request);
54
        if ($form->isSubmitted() && $form->isValid()) {
55
            if ($form->get('save')->isClicked()) {
0 ignored issues
show
Bug introduced by
The method isClicked() does not exist on Symfony\Component\Form\FormInterface. It seems like you code against a sub-type of Symfony\Component\Form\FormInterface such as Symfony\Component\Form\SubmitButton. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

55
            if ($form->get('save')->/** @scrutinizer ignore-call */ isClicked()) {
Loading history...
56
                $this->setVars($form->getData());
57
                $this->addFlash('status', 'Done! Configuration updated.');
58
            } elseif ($form->get('cancel')->isClicked()) {
59
                $this->addFlash('status', 'Operation cancelled.');
60
            }
61
62
            return $this->redirectToRoute('zikulagroupsmodule_group_adminlist');
63
        }
64
65
        return [
66
            'form' => $form->createView()
67
        ];
68
    }
69
}
70