Completed
Pull Request — master (#105)
by Nic
26:42
created

LocatorBootstrapForm::__construct()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 32
Code Lines 19

Duplication

Lines 32
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 32
loc 32
rs 8.8571
cc 2
eloc 19
nc 2
nop 2
1
<?php
2
3
if (class_exists('BootstrapForm')) {
4
5
    /**
6
     * Class LocatorForm
7
     */
8 View Code Duplication
    class LocatorBootstrapForm extends BootstrapForm
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
    {
10
11
        /**
12
         * LocatorForm constructor.
13
         * @param Controller $controller
14
         * @param string $name
15
         */
16
        public function __construct(Controller $controller, $name)
17
        {
18
19
            $fields = FieldList::create(
20
                TextField::create('Address')
21
                    ->setTitle('')
22
                    ->setAttribute('placeholder', 'address or zip code')
23
            );
24
25
            if (LocationCategory::get()->count() > 0) {
26
                $categories = DropdownField::create('CategoryID')
27
                    ->setTitle('')
28
                    ->setEmptyString('All Categories')
29
                    ->setSource(LocationCategory::get()->map());
30
                $fields->push($categories);
31
            }
32
33
            $this->extend('updateLocatorFormFields', $fields);
34
35
            $actions = FieldList::create(
36
                FormAction::create('doFilterLocations')
37
                    ->setTitle('Search')
38
            );
39
40
            $this->extend('updateLocatorFormActions', $actions);
41
42
            $validator = RequiredFields::create();
43
44
            $this->extend('updateLocatorFormRequiredFields', $validator);
45
46
            parent::__construct($controller, $name, $fields, $actions, $validator);
47
        }
48
49
    }
50
51
}