1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\RecipeBook\Page; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\FieldList; |
6
|
|
|
use SilverStripe\Forms\GridField\GridField; |
7
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; |
8
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddNewButton; |
9
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
10
|
|
|
use SilverStripe\Forms\NumericField; |
11
|
|
|
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; |
12
|
|
|
use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
13
|
|
|
|
14
|
|
|
class RecipeLanding extends \Page |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private static $db = [ |
|
|
|
|
20
|
|
|
'PerPage' => 'Int', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var array |
25
|
|
|
*/ |
26
|
|
|
private static $many_many = [ |
|
|
|
|
27
|
|
|
'FeaturedCategories' => RecipeCategoryPage::class, |
28
|
|
|
]; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var array |
32
|
|
|
*/ |
33
|
|
|
private static $many_many_extraFields = [ |
|
|
|
|
34
|
|
|
'FeaturedCategories' => [ |
35
|
|
|
'SortOrder' => 'Int', |
36
|
|
|
], |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var array |
41
|
|
|
*/ |
42
|
|
|
private static $defaults = [ |
|
|
|
|
43
|
|
|
'PerPage' => 9, |
44
|
|
|
]; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var string |
48
|
|
|
*/ |
49
|
|
|
private static $singular_name = 'Recipe Landing Page'; |
|
|
|
|
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var string |
53
|
|
|
*/ |
54
|
|
|
private static $plural_name = 'Recipe Landing Pages'; |
|
|
|
|
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var array |
58
|
|
|
*/ |
59
|
|
|
private static $allowed_children = [ |
|
|
|
|
60
|
|
|
RecipeCategoryPage::class, |
61
|
|
|
]; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @var string |
65
|
|
|
*/ |
66
|
|
|
private static $table_name = 'RecipeLanding'; |
|
|
|
|
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* @return \SilverStripe\Forms\FieldList |
70
|
|
|
*/ |
71
|
|
|
public function getCMSFields() |
72
|
|
|
{ |
73
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
74
|
|
|
if ($this->ID) { |
75
|
|
|
$config = GridFieldConfig_RelationEditor::create() |
76
|
|
|
->addComponent(new GridFieldOrderableRows('SortOrder')) |
77
|
|
|
->removeComponentsByType(GridFieldAddExistingAutocompleter::class) |
78
|
|
|
->removeComponentsByType(GridFieldAddNewButton::class) |
79
|
|
|
->addComponent(new GridFieldAddExistingSearchButton()); |
80
|
|
|
$cats = $this->FeaturedCategories()->sort('SortOrder'); |
|
|
|
|
81
|
|
|
$catsField = GridField::create( |
82
|
|
|
'FeaturedCategories', |
83
|
|
|
'Featured Categories', |
84
|
|
|
$cats, |
85
|
|
|
$config |
86
|
|
|
); |
87
|
|
|
|
88
|
|
|
$fields->addFieldsToTab('Root.Featured', array( |
89
|
|
|
$catsField, |
90
|
|
|
)); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
$fields->addFieldsToTab('Root.Browse', [ |
94
|
|
|
NumericField::create('PerPage', 'Categories per page'), |
95
|
|
|
]); |
96
|
|
|
}); |
97
|
|
|
|
98
|
|
|
return parent::getCMSFields(); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @return mixed |
103
|
|
|
*/ |
104
|
|
|
public function getFeaturedList() |
105
|
|
|
{ |
106
|
|
|
return $this->FeaturedCategories()->sort('SortOrder'); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|