Passed
Pull Request — master (#121)
by Arnaud
07:12
created

ActionField::configureOptions()   A

Complexity

Conditions 5
Paths 1

Size

Total Lines 26
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 14
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 26
rs 9.4888
1
<?php
2
3
namespace LAG\AdminBundle\Field;
4
5
use LAG\AdminBundle\Configuration\ActionConfiguration;
6
use Symfony\Component\OptionsResolver\Options;
7
use Symfony\Component\OptionsResolver\OptionsResolver;
8
9
/**
10
 * Display a link with button render and options.
11
 */
12
class ActionField extends LinkField
13
{
14
    public function isSortable(): bool
15
    {
16
        return true;
17
    }
18
19
    public function configureOptions(OptionsResolver $resolver, ActionConfiguration $actionConfiguration)
20
    {
21
        parent::configureOptions($resolver, $actionConfiguration);
22
23
24
        $resolver
25
            ->setDefault('class', '')
26
            ->setNormalizer('class', function (Options $options, $value) {
27
                if ($value) {
28
                    return $value;
29
                }
30
                $action = null;
31
32
                if ($options->offsetGet('action')) {
33
                    $action = $options->offsetGet('action');
34
                }
35
36
                if ('edit' === $action) {
37
                    return 'btn btn-primary';
38
                }
39
40
                if ('delete' === $action) {
41
                    return 'btn btn-danger';
42
                }
43
44
                return 'btn btn-secondary';
45
            })
46
        ;
47
    }
48
}
49