|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the Sylius package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Paweł Jędrzejewski |
|
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 Sylius\Bundle\CoreBundle\Form\EventSubscriber; |
|
13
|
|
|
|
|
14
|
|
|
use Sylius\Component\Core\Model\ChannelInterface; |
|
15
|
|
|
use Sylius\Component\Resource\Exception\UnexpectedTypeException; |
|
16
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
17
|
|
|
use Symfony\Component\Form\FormEvent; |
|
18
|
|
|
use Symfony\Component\Form\FormEvents; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Anna Walasek <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
class AddBaseCurrencySubscriber implements EventSubscriberInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* {@inheritdoc} |
|
27
|
|
|
*/ |
|
28
|
|
|
public static function getSubscribedEvents() |
|
29
|
|
|
{ |
|
30
|
|
|
return [ |
|
31
|
|
|
FormEvents::PRE_SET_DATA => 'preSetData', |
|
32
|
|
|
]; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @param FormEvent $event |
|
37
|
|
|
*/ |
|
38
|
|
|
public function preSetData(FormEvent $event) |
|
39
|
|
|
{ |
|
40
|
|
|
$resource = $event->getData(); |
|
41
|
|
|
$disabled = $this->getDisabledOption($resource); |
|
42
|
|
|
|
|
43
|
|
|
$form = $event->getForm(); |
|
44
|
|
|
$form->add( |
|
45
|
|
|
'baseCurrency', |
|
46
|
|
|
'sylius_currency_choice', |
|
47
|
|
|
[ |
|
48
|
|
|
'label' => 'sylius.form.channel.currency_base', |
|
49
|
|
|
'required' => true, |
|
50
|
|
|
'disabled' => $disabled |
|
51
|
|
|
] |
|
52
|
|
|
); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* @param mixed $resource |
|
57
|
|
|
* |
|
58
|
|
|
* @return bool |
|
59
|
|
|
*/ |
|
60
|
|
|
private function getDisabledOption($resource) |
|
|
|
|
|
|
61
|
|
|
{ |
|
62
|
|
|
if ($resource instanceof ChannelInterface) { |
|
63
|
|
|
return null !== $resource->getId(); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
if (null === $resource) { |
|
67
|
|
|
return false; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
throw new UnexpectedTypeException($resource, ChannelInterface::class); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.