|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Zikula package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright Zikula Foundation - http://zikula.org/ |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace Zikula\GroupsModule\Controller; |
|
13
|
|
|
|
|
14
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; |
|
15
|
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; |
|
16
|
|
|
use Symfony\Component\HttpFoundation\RedirectResponse; |
|
17
|
|
|
use Symfony\Component\HttpFoundation\Request; |
|
18
|
|
|
use Symfony\Component\Security\Core\Exception\AccessDeniedException; |
|
19
|
|
|
use Zikula\Core\Controller\AbstractController; |
|
20
|
|
|
use Zikula\GroupsModule\Form\Type\ConfigType; |
|
21
|
|
|
use Zikula\ThemeModule\Engine\Annotation\Theme; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* Class ConfigController |
|
25
|
|
|
* @Route("/config") |
|
26
|
|
|
*/ |
|
27
|
|
|
class ConfigController extends AbstractController |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* @Route("/config") |
|
31
|
|
|
* @Theme("admin") |
|
32
|
|
|
* @Template |
|
33
|
|
|
* |
|
34
|
|
|
* This is a standard function to modify the configuration parameters of the module. |
|
35
|
|
|
* |
|
36
|
|
|
* @param Request $request |
|
37
|
|
|
* @throws AccessDeniedException Thrown if the user doesn't have admin access to the module |
|
38
|
|
|
* @return array|RedirectResponse |
|
39
|
|
|
*/ |
|
40
|
|
|
public function configAction(Request $request) |
|
41
|
|
|
{ |
|
42
|
|
|
if (!$this->hasPermission('ZikulaGroupsModule::', '::', ACCESS_ADMIN)) { |
|
43
|
|
|
throw new AccessDeniedException(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
// build a groups array suitable for the form choices |
|
47
|
|
|
$groupsList = []; |
|
48
|
|
|
$groups = $this->get('zikula_groups_module.group_repository')->findAll(); |
|
49
|
|
|
foreach ($groups as $group) { |
|
50
|
|
|
$groupsList[$group->getName()] = $group->getGid(); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$form = $this->createForm(ConfigType::class, $this->getVars(), [ |
|
54
|
|
|
'translator' => $this->get('translator.default'), |
|
55
|
|
|
'groups' => $groupsList |
|
56
|
|
|
] |
|
57
|
|
|
); |
|
58
|
|
|
|
|
59
|
|
|
if ($form->handleRequest($request)->isValid()) { |
|
60
|
|
|
if ($form->get('save')->isClicked()) { |
|
|
|
|
|
|
61
|
|
|
$this->setVars($form->getData()); |
|
62
|
|
|
$this->addFlash('status', $this->__('Done! Module configuration updated.')); |
|
63
|
|
|
} |
|
64
|
|
|
if ($form->get('cancel')->isClicked()) { |
|
|
|
|
|
|
65
|
|
|
$this->addFlash('status', $this->__('Operation cancelled.')); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
return $this->redirectToRoute('zikulagroupsmodule_group_adminlist'); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
return [ |
|
72
|
|
|
'form' => $form->createView() |
|
73
|
|
|
]; |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: