Completed
Push — master ( 98a062...441031 )
by Ryan
10:10
created

FieldFormButtons::handle()   A

Complexity

Conditions 3
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 13
nc 1
nop 4
dl 0
loc 21
rs 9.3142
c 0
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
29
        $builder->setButtons(
30
            [
31
                'cancel',
32
                'change' => [
33
                    'data-toggle' => 'modal',
34
                    'data-target' => '#modal',
35
                    'enabled'     => $builder->getFormMode() == 'edit'
36
                        && $module
37
                        && $url->hasRoute($module->getNamespace('fields.change')),
38
                    'href'        => $url->route(
39
                        $module->getNamespace('fields.change'),
40
                        ['id' => $route->parameter('id')]
41
                    ),
42
                ],
43
            ]
44
        );
45
    }
46
}
47