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

ConfigController::configAction()   A

Complexity

Conditions 6
Paths 7

Size

Total Lines 26
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 7
nop 3
dl 0
loc 26
rs 9.2222
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\ExtensionsModule\Controller;
15
16
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\Routing\Annotation\Route;
20
use Zikula\Bundle\CoreBundle\CacheClearer;
21
use Zikula\Bundle\CoreBundle\Controller\AbstractController;
22
use Zikula\ExtensionsModule\Form\Type\ConfigType;
23
use Zikula\ExtensionsModule\Helper\BundleSyncHelper;
24
use Zikula\PermissionsModule\Annotation\PermissionCheck;
25
use Zikula\ThemeModule\Engine\Annotation\Theme;
26
27
/**
28
 * Class ConfigController
29
 *
30
 * @Route("/config")
31
 * @PermissionCheck("admin")
32
 */
33
class ConfigController extends AbstractController
34
{
35
    /**
36
     * @Route("")
37
     * @Theme("admin")
38
     * @Template("@ZikulaExtensionsModule/Config/config.html.twig")
39
     *
40
     * @return array|Response
41
     */
42
    public function configAction(
43
        Request $request,
44
        BundleSyncHelper $bundleSyncHelper,
45
        CacheClearer $cacheClearer
46
    ) {
47
        $form = $this->createForm(ConfigType::class, $this->getVars());
48
        $form->handleRequest($request);
49
        if ($form->isSubmitted() && $form->isValid()) {
50
            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

50
            if ($form->get('save')->/** @scrutinizer ignore-call */ isClicked()) {
Loading history...
51
                $this->setVars($form->getData());
52
                if (true === $form->get('hardreset')->getData()) {
53
                    $extensionsInFileSystem = $bundleSyncHelper->scanForBundles();
54
                    $bundleSyncHelper->syncExtensions($extensionsInFileSystem, true);
55
                    $cacheClearer->clear('symfony.routing');
56
                }
57
                $this->addFlash('status', 'Done! Configuration updated.');
58
            }
59
            if ($form->get('cancel')->isClicked()) {
60
                $this->addFlash('status', 'Operation cancelled.');
61
            }
62
63
            return $this->redirectToRoute('zikulaextensionsmodule_extension_list');
64
        }
65
66
        return [
67
            'form' => $form->createView()
68
        ];
69
    }
70
}
71