1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace AntonyThorpe\SilverShopProductModel; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Forms\FieldList; |
|
|
|
|
6
|
|
|
use SilverStripe\ORM\ArrayLib; |
|
|
|
|
7
|
|
|
use SilverStripe\Forms\DropdownField; |
|
|
|
|
8
|
|
|
use SilverStripe\ORM\DataExtension; |
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Add model dropdown to Product where available |
12
|
|
|
* Extends SilverShop\Page\Product |
13
|
|
|
*/ |
14
|
|
|
class ProductExtension extends DataExtension |
15
|
|
|
{ |
16
|
|
|
public function updateCMSFields(FieldList $fields): void |
17
|
|
|
{ |
18
|
|
|
// if there are Models set in the Product Category then use a dropdown to select |
19
|
|
|
if ($this->getOwner()->Parent && $this->getOwner()->Parent->ProductModels()->count()) { |
20
|
|
|
$fields->replaceField( |
21
|
|
|
'Model', |
22
|
|
|
DropdownField::create( |
23
|
|
|
'Model', |
24
|
|
|
_t(self::class . 'ModelRequired', 'Model (required)'), |
|
|
|
|
25
|
|
|
ArrayLib::valuekey($this->getOwner()->Parent->ProductModels()->column('Title')) |
26
|
|
|
) |
27
|
|
|
->setEmptyString(_t(self::class . 'ModelSelect', 'Select...')) |
28
|
|
|
->setAttribute('Required', true) |
29
|
|
|
); |
30
|
|
|
} else { |
31
|
|
|
// Update Model for extended length |
32
|
|
|
// see config.yml for updated db settings |
33
|
|
|
$model = $fields->dataFieldByName('Model'); |
34
|
|
|
$model->setMaxLength(100); |
35
|
|
|
} |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* For the template within the GroupedList, provide the model's Description recorded within the ProductModel Class |
40
|
|
|
* @return string description of the model |
41
|
|
|
*/ |
42
|
|
|
public function getModelDescription(): string|null |
43
|
|
|
{ |
44
|
|
|
if ($this->getOwner()->Parent) { |
45
|
|
|
$productmodels = $this->getOwner()->Parent->ProductModels(); |
46
|
|
|
if ($productmodels->count() && $this->getOwner()->Model) { |
47
|
|
|
$model = $this->getOwner()->Model; |
48
|
|
|
return $productmodels->find('Title', $model)->Description; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
return null; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths