1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\Wishlist\Form; |
4
|
|
|
|
5
|
|
|
use Dynamic\Wishlist\Model\ProductWishList; |
6
|
|
|
use SilverStripe\Control\Controller; |
7
|
|
|
use SilverStripe\Forms\DropdownField; |
8
|
|
|
use SilverStripe\Forms\FieldList; |
9
|
|
|
use SilverStripe\Forms\Form; |
10
|
|
|
use SilverStripe\Forms\FormAction; |
11
|
|
|
use SilverStripe\Forms\HiddenField; |
12
|
|
|
use SilverStripe\Security\Security; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class RemoveFromWishListForm |
16
|
|
|
* @package Dynamic\Wishlist\Form |
17
|
|
|
*/ |
18
|
|
|
class RemoveFromWishListForm extends Form |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* RemoveFromWishListForm constructor. |
22
|
|
|
* @param \SilverStripe\Control\Controller $controller |
23
|
|
|
* @param string $name Defaults to AddToWishListForm |
24
|
|
|
* @param int $productID An easy way to override the id of the product to be added. If one is not provided the current page id will be used instead. |
25
|
|
|
*/ |
26
|
|
|
public function __construct(Controller $controller, $name = 'RemoveFromWishListForm', $productID = 0) |
27
|
|
|
{ |
28
|
|
|
if ($productID < 1) { |
29
|
|
|
$productID = $controller->ID; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$lists = ProductWishList::get()->filter([ |
33
|
|
|
'MemberID' => Security::getCurrentUser()->ID, |
34
|
|
|
]); |
35
|
|
|
$this->extend('updateWishLists', $lists); |
36
|
|
|
|
37
|
|
|
$fields = FieldList::create( |
38
|
|
|
HiddenField::create('ProductID', 'ProductID', $productID), |
39
|
|
|
DropdownField::create('List', 'Wish List', $lists->map('ID', 'Title')) |
40
|
|
|
); |
41
|
|
|
$this->extend('updateFields', $fields, $productID); |
42
|
|
|
|
43
|
|
|
$actions = FieldList::create( |
44
|
|
|
FormAction::create('removeFromWishList')->setTitle('Remove From List') |
45
|
|
|
); |
46
|
|
|
$this->extend('updateActions', $actions, $productID); |
47
|
|
|
|
48
|
|
|
parent::__construct($controller, $name, $fields, $actions); |
49
|
|
|
|
50
|
|
|
// makes a unique id for each wishlist form |
51
|
|
|
$reflection = new \ReflectionClass($this); |
52
|
|
|
$shortName = str_replace(array('.', '/'), '', $this->getName()); |
53
|
|
|
$this->setHTMLID($reflection->getShortName() . '_' . $shortName . '_' . $productID); |
54
|
|
|
$this->addExtraClass('remove-from-wishlist-form'); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|