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

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