1 | <?php |
||
2 | |||
3 | namespace Dynamic\Elements\Promos\Model; |
||
4 | |||
5 | use Dynamic\BaseObject\Model\BaseElementObject; |
||
6 | use Dynamic\Elements\Promos\Elements\ElementPromos; |
||
7 | use SilverStripe\Forms\FieldList; |
||
8 | use SilverStripe\Forms\GridField\GridField; |
||
9 | use SilverStripe\Forms\GridField\GridFieldConfig_RecordViewer; |
||
10 | |||
11 | /** |
||
12 | * Class PromoObject |
||
13 | * @package Dynamic\Elements\Promos\Model |
||
14 | * |
||
15 | * @method \SilverStripe\ORM\ManyManyList ElementPromos() |
||
16 | */ |
||
17 | class PromoObject extends BaseElementObject |
||
18 | { |
||
19 | /** |
||
20 | * @return string |
||
21 | */ |
||
22 | private static $singular_name = 'Promo'; |
||
0 ignored issues
–
show
introduced
by
![]() |
|||
23 | |||
24 | /** |
||
25 | * @return string |
||
26 | */ |
||
27 | private static $plural_name = 'Promos'; |
||
0 ignored issues
–
show
|
|||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private static $belongs_many_many = array( |
||
0 ignored issues
–
show
|
|||
33 | 'ElementPromos' => ElementPromos::class, |
||
34 | ); |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private static $table_name = 'PromoObject'; |
||
0 ignored issues
–
show
|
|||
40 | |||
41 | /** |
||
42 | * @var array |
||
43 | */ |
||
44 | private static $summary_fields = [ |
||
0 ignored issues
–
show
|
|||
45 | 'Summary', |
||
46 | ]; |
||
47 | |||
48 | 1 | /** |
|
49 | 1 | * @return FieldList |
|
50 | * |
||
51 | 1 | * @throws \Exception |
|
52 | 1 | */ |
|
53 | 1 | public function getCMSFields() |
|
54 | 1 | { |
|
55 | 1 | $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
56 | 1 | $fields->removeByName('ElementPromos'); |
|
57 | 1 | ||
58 | 1 | $config = GridFieldConfig_RecordViewer::create(); |
|
59 | $fields->addFieldToTab( |
||
60 | 'Root.Elements', |
||
61 | GridField::create( |
||
62 | 1 | 'ElementPromos', |
|
63 | 1 | 'Elements', |
|
64 | 1 | $this->ElementPromos(), |
|
65 | $config |
||
66 | ) |
||
67 | ); |
||
68 | |||
69 | $fields->dataFieldByName('Image') |
||
70 | ->setFolderName('Uploads/Elements/Promos'); |
||
71 | }); |
||
72 | |||
73 | return parent::getCMSFields(); |
||
74 | } |
||
75 | |||
76 | /** |
||
77 | * @return mixed |
||
78 | */ |
||
79 | public function getSummary() |
||
80 | { |
||
81 | return $this->dbObject('Content')->Summary(20); |
||
82 | } |
||
83 | } |
||
84 |