Completed
Push — master ( e98215...11a2d8 )
by Adam
05:41
created

ExchangeOptions::configureOptions()   A

↳ Parent: ExchangeOptions

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 12
Code Lines 8

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 1
1
<?php
2
/*
3
 * WellCommerce Open-Source E-Commerce Platform
4
 *
5
 * This file is part of the WellCommerce package.
6
 *
7
 * (c) Adam Piotrowski <[email protected]>
8
 *
9
 * For the full copyright and license information,
10
 * please view the LICENSE file that was distributed with this source code.
11
 */
12
13
namespace WellCommerce\Component\Form\Dependencies;
14
15
use Symfony\Component\OptionsResolver\OptionsResolver;
16
use WellCommerce\Component\Form\Elements\ElementInterface;
17
use WellCommerce\Component\Form\Elements\Form;
18
19
/**
20
 * Class ExchangeOptions
21
 *
22
 * @author  Adam Piotrowski <[email protected]>
23
 */
24
class ExchangeOptions extends AbstractDependency
25
{
26
    
27
    public function configureOptions(OptionsResolver $resolver)
28
    {
29
        $resolver->setRequired([
30
            'field',
31
            'form',
32
            'load_options_route',
33
        ]);
34
        
35
        $resolver->setAllowedTypes('field', ElementInterface::class);
36
        $resolver->setAllowedTypes('form', Form::class);
37
        $resolver->setAllowedTypes('load_options_route', 'string');
38
    }
39
    
40
    public function renderJs()
41
    {
42
        $javascriptType = $this->getJavascriptType();
43
        $fieldName      = $this->getField()->getName();
44
        $formName       = $this->getForm()->getName();
45
        
46
        return sprintf("new GFormDependency(GFormDependency.%s, '%s.%s', '%s')",
47
            $javascriptType,
48
            $formName,
49
            $fieldName,
50
            $this->options['load_options_route']
51
        );
52
    }
53
    
54
    public function getJavascriptType()
55
    {
56
        return 'EXCHANGE_OPTIONS';
57
    }
58
}
59