WidgetExtensionFormSections::handle()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 30
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
c 0
b 0
f 0
rs 8.8571
cc 1
eloc 14
nc 1
nop 1
1
<?php namespace Anomaly\DashboardModule\Widget\Extension\Form;
2
3
/**
4
 * Class WidgetExtensionFormSections
5
 *
6
 * @link          http://pyrocms.com/
7
 * @author        PyroCMS, Inc. <[email protected]>
8
 * @author        Ryan Thompson <[email protected]>
9
 */
10
class WidgetExtensionFormSections
11
{
12
13
    /**
14
     * Handle the form sections.
15
     *
16
     * @param WidgetExtensionFormBuilder $builder
17
     */
18
    public function handle(WidgetExtensionFormBuilder $builder)
19
    {
20
        $widget        = $builder->getChildForm('widget');
21
        $configuration = $builder->getChildForm('configuration');
22
23
        $builder->setSections(
24
            [
25
                [
26
                    'fields' => function () use ($widget) {
27
                        return array_map(
28
                            function ($field) {
29
                                return 'widget_' . $field;
30
                            },
31
                            $widget->getFormFieldSlugs()
32
                        );
33
                    },
34
                ],
35
                [
36
                    'fields' => function () use ($configuration) {
37
                        return array_map(
38
                            function ($field) {
39
                                return 'configuration_' . $field;
40
                            },
41
                            $configuration->getFormFieldSlugs()
42
                        );
43
                    },
44
                ],
45
            ]
46
        );
47
    }
48
}
49