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

FieldFormButtons::handle()   B

Complexity

Conditions 4
Paths 1

Size

Total Lines 25
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 17
nc 1
nop 4
dl 0
loc 25
rs 8.5806
c 1
b 0
f 0
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