1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Dynamic\ProductCatalog\Page; |
4
|
|
|
|
5
|
|
|
use Dynamic\ProductCatalog\ORM\CatalogProduct; |
6
|
|
|
use SilverStripe\Forms\GridField\GridField; |
7
|
|
|
use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; |
8
|
|
|
use SilverStripe\Forms\GridField\GridFieldConfig_RelationEditor; |
9
|
|
|
use SilverStripe\Forms\GridField\GridFieldPageCount; |
10
|
|
|
use SilverStripe\Forms\GridField\GridFieldPaginator; |
11
|
|
|
use Symbiote\GridFieldExtensions\GridFieldAddExistingSearchButton; |
12
|
|
|
use Symbiote\GridFieldExtensions\GridFieldOrderableRows; |
13
|
|
|
|
14
|
|
|
class CatalogCategory extends \Page |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private static $belongs_many_many = array( |
|
|
|
|
20
|
|
|
'Products' => CatalogProduct::class, |
21
|
|
|
); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var string |
25
|
|
|
*/ |
26
|
|
|
private static $table_name = 'CatalogCategory'; |
|
|
|
|
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @return \SilverStripe\Forms\FieldList |
30
|
|
|
*/ |
31
|
1 |
|
public function getCMSFields() |
32
|
|
|
{ |
33
|
1 |
|
$fields = parent::getCMSFields(); |
34
|
|
|
|
35
|
1 |
|
if ($this->ID) { |
36
|
|
|
// Products |
37
|
1 |
|
$config = GridFieldConfig_RelationEditor::create(); |
38
|
1 |
|
$config->addComponent(new GridFieldOrderableRows('SortOrder')); |
39
|
1 |
|
$config->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
40
|
1 |
|
$config->addComponent(new GridFieldAddExistingSearchButton()); |
41
|
1 |
|
$config->removeComponentsByType(GridFieldPaginator::class); |
42
|
1 |
|
$config->removeComponentsByType(GridFieldPageCount::class); |
43
|
|
|
|
44
|
1 |
|
$products = $this->Products()->sort('SortOrder'); |
|
|
|
|
45
|
1 |
|
$productsField = GridField::create('Products', 'Products', $products, $config); |
46
|
|
|
|
47
|
1 |
|
$fields->addFieldsToTab('Root.Products', array( |
48
|
1 |
|
$productsField, |
49
|
|
|
)); |
50
|
|
|
} |
51
|
|
|
|
52
|
1 |
|
return $fields; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return DataList |
|
|
|
|
57
|
|
|
*/ |
58
|
1 |
|
public function getProductList() |
59
|
|
|
{ |
60
|
1 |
|
return $this->Products()->sort('SortOrder'); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|