Completed
Push — master ( 7346cf...68e36d )
by Ryan
18:45 queued 13:05
created

FieldFormButtons   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 37
rs 10
c 1
b 0
f 0
wmc 4
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 25 4
1
<?php namespace Anomaly\Streams\Platform\Field\Form;
2
3
use Anomaly\Streams\Platform\Addon\Module\ModuleCollection;
4
use Anomaly\Streams\Platform\Routing\UrlGenerator;
5
use Illuminate\Routing\Route;
6
7
/**
8
 * Class FieldFormButtons
9
 *
10
 * @link   http://pyrocms.com/
11
 * @author PyroCMS, Inc. <[email protected]>
12
 * @author Ryan Thompson <[email protected]>
13
 */
14
class FieldFormButtons
15
{
16
17
    /**
18
     * Handle the buttons.
19
     *
20
     * @param FieldFormBuilder $builder
21
     * @param ModuleCollection $modules
22
     * @param Route            $route
23
     * @param UrlGenerator     $url
24
     */
25
    public function handle(FieldFormBuilder $builder, ModuleCollection $modules, Route $route, UrlGenerator $url)
26
    {
27
        $module = $modules->active();
28
        $field  = $builder->getFormEntry();
29
        $type   = $field->getType();
30
31
        $builder->setButtons(
32
            [
33
                'cancel',
34
                'change' => [
35
                    'data-toggle' => 'modal',
36
                    'data-target' => '#modal',
37
                    'disabled'    => $builder->getFormMode() == 'edit'
38
                        && !$type->getColumnType(),
39
                    'enabled'     => $builder->getFormMode() == 'edit'
40
                        && $module
41
                        && $url->hasRoute($module->getNamespace('fields.change')),
42
                    'href'        => $url->route(
43
                        $module->getNamespace('fields.change'),
44
                        ['id' => $route->parameter('id')]
45
                    ),
46
                ],
47
            ]
48
        );
49
    }
50
}
51