Completed
Pull Request — master (#2)
by Matthew
13:57
created

AddToWishListForm   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 12
dl 0
loc 26
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
1
<?php
2
3
namespace Dynamic\Wishlist\Form;
4
5
6
use Dynamic\Wishlist\Model\ProductWishList;
7
use SilverStripe\Control\Controller;
8
use SilverStripe\Forms\DropdownField;
9
use SilverStripe\Forms\FieldList;
10
use SilverStripe\Forms\Form;
11
use SilverStripe\Forms\FormAction;
12
use SilverStripe\Forms\HiddenField;
13
use SilverStripe\Security\Security;
14
15
/**
16
 * Class AddToWishListForm
17
 * @package Dynamic\Wishlist\Form
18
 */
19
class AddToWishListForm extends Form
20
{
21
    /**
22
     * AddToWishListForm constructor.
23
     * @param \SilverStripe\Control\Controller|\Dynamic\FoxyStripe\Page\ProductPage $controller
0 ignored issues
show
Bug introduced by
The type Dynamic\FoxyStripe\Page\ProductPage was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
     * @param string $name
25
     */
26
    public function __construct(Controller $controller, $name = 'AddToWishListForm')
27
    {
28
        $lists = ProductWishList::get()->filter([
29
            'MemberID' => Security::getCurrentUser()->ID,
30
        ]);
31
        $this->extend('updateWishLists', $lists);
32
33
        $fields = FieldList::create(
34
            HiddenField::create('ProductID', 'ProductID', $controller->ID),
35
            DropdownField::create('List', 'Wish List', $lists->map('ID', 'Title'))
36
        );
37
        $this->extend('updateFields', $fields);
38
39
        $actions = FieldList::create(
40
            FormAction::create('addToWishList')->setTitle('Add To List')
41
        );
42
        $this->extend('updateActions', $actions);
43
44
        parent::__construct($controller, $name, $fields, $actions);
45
    }
46
}
47