Skip to content

Commit 7eee959

Browse files
authored
Upgrade to Silverstripe 6 (#51)
* Update composer to be compatible with SS6 * fix getCMSField to be compatible with parent class * update array syntax * use self::class instead of __CLASS__ constant
1 parent cf8625c commit 7eee959

3 files changed

Lines changed: 30 additions & 23 deletions

File tree

composer.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626
}
2727
],
2828
"require": {
29-
"dnadesign/silverstripe-elemental": "^5",
30-
"dynamic/silverstripe-elemental-baseobject": "^5",
31-
"jonom/focuspoint": "^5.0"
29+
"dnadesign/silverstripe-elemental": "^6",
30+
"dynamic/silverstripe-elemental-baseobject": "^6",
31+
"jonom/focuspoint": "^6"
3232
},
3333
"require-dev": {
34-
"silverstripe/recipe-testing": "^3"
34+
"silverstripe/recipe-testing": "^4"
3535
},
3636
"minimum-stability": "dev",
3737
"prefer-stable": true,
@@ -49,4 +49,4 @@
4949
},
5050
"process-timeout": 600
5151
}
52-
}
52+
}

src/Elements/ElementPromos.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ElementPromos extends BaseElement
4343
/**
4444
* @var array
4545
*/
46-
private static $styles = array();
46+
private static $styles = [];
4747

4848
/**
4949
* @var array
@@ -55,18 +55,18 @@ class ElementPromos extends BaseElement
5555
/**
5656
* @var array
5757
*/
58-
private static $many_many = array(
58+
private static $many_many = [
5959
'Promos' => PromoObject::class,
60-
);
60+
];
6161

6262
/**
6363
* @var array
6464
*/
65-
private static $many_many_extraFields = array(
66-
'Promos' => array(
65+
private static $many_many_extraFields = [
66+
'Promos' => [
6767
'SortOrder' => 'Int',
68-
),
69-
);
68+
],
69+
];
7070

7171
/**
7272
* @var array
@@ -88,19 +88,21 @@ class ElementPromos extends BaseElement
8888
* @param bool $includerelations
8989
* @return array
9090
*/
91+
#[\Override]
9192
public function fieldLabels($includerelations = true)
9293
{
9394
$labels = parent::fieldLabels($includerelations);
9495

95-
$labels['Content'] = _t(__CLASS__.'.ContentLabel', 'Intro');
96-
$labels['Promos'] = _t(__CLASS__ . '.PromosLabel', 'Promos');
96+
$labels['Content'] = _t(self::class.'.ContentLabel', 'Intro');
97+
$labels['Promos'] = _t(self::class . '.PromosLabel', 'Promos');
9798

9899
return $labels;
99100
}
100101

101102
/**
102103
* @return FieldList
103104
*/
105+
#[\Override]
104106
public function getCMSFields()
105107
{
106108
$this->beforeUpdateCMSFields(function (FieldList $fields) {
@@ -117,13 +119,14 @@ public function getCMSFields()
117119
GridFieldDeleteAction::class,
118120
GridFieldArchiveAction::class,
119121
])->addComponents(
120-
new GridFieldOrderableRows('SortOrder'),
121-
new GridFieldAddExistingSearchButton()
122+
GridFieldOrderableRows::create('SortOrder'),
123+
GridFieldAddExistingSearchButton::create()
122124
);
123125

124-
$fields->addFieldsToTab('Root.Main', array(
126+
127+
$fields->addFieldsToTab('Root.Main', [
125128
$promoField,
126-
));
129+
]);
127130
}
128131
});
129132

@@ -141,6 +144,7 @@ public function getPromoList()
141144
/**
142145
* @return DBHTMLText
143146
*/
147+
#[\Override]
144148
public function getSummary()
145149
{
146150
$count = $this->Promos()->count();
@@ -149,13 +153,14 @@ public function getSummary()
149153
'A promo|{count} promos',
150154
[ 'count' => $count ]
151155
);
152-
156+
153157
return DBField::create_field('HTMLText', $label)->Summary(20);
154158
}
155159

156160
/**
157161
* @return array
158162
*/
163+
#[\Override]
159164
protected function provideBlockSchema()
160165
{
161166
$blockSchema = parent::provideBlockSchema();
@@ -166,8 +171,9 @@ protected function provideBlockSchema()
166171
/**
167172
* @return string
168173
*/
174+
#[\Override]
169175
public function getType()
170176
{
171-
return _t(__CLASS__.'.BlockType', 'Promos');
177+
return _t(self::class.'.BlockType', 'Promos');
172178
}
173179
}

src/Model/PromoObject.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class PromoObject extends BaseElementObject
2828
/**
2929
* @var array
3030
*/
31-
private static $belongs_many_many = array(
31+
private static $belongs_many_many = [
3232
'ElementPromos' => ElementPromos::class,
33-
);
33+
];
3434

3535
/**
3636
* @var string
@@ -49,7 +49,8 @@ class PromoObject extends BaseElementObject
4949
*
5050
* @throws \Exception
5151
*/
52-
public function getCMSFields()
52+
#[\Override]
53+
public function getCMSFields(): FieldList
5354
{
5455
$this->beforeUpdateCMSFields(function (FieldList $fields) {
5556
$fields->removeByName('ElementPromos');

0 commit comments

Comments
 (0)