| 1 | <?php |
||
| 2 | |||
| 3 | namespace Dynamic\Foxy\Discounts\Extension; |
||
| 4 | |||
| 5 | use Dynamic\Foxy\Discounts\Model\Discount; |
||
| 6 | use SilverShop\HasOneField\HasOneButtonField; |
||
| 7 | use SilverStripe\Forms\FieldList; |
||
| 8 | use SilverStripe\Forms\GridField\GridFieldAddExistingAutocompleter; |
||
| 9 | use SilverStripe\ORM\DataExtension; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Class MemberExtension |
||
| 13 | * @package Dynamic\Foxy\Discounts\Extension |
||
| 14 | */ |
||
| 15 | class MemberExtension extends DataExtension |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @var string[] |
||
| 19 | */ |
||
| 20 | private static $has_one = [ |
||
|
0 ignored issues
–
show
introduced
by
Loading history...
|
|||
| 21 | 'Discount' => Discount::class, |
||
| 22 | ]; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @param FieldList $fields |
||
| 26 | */ |
||
| 27 | public function updateCMSFields(FieldList $fields) |
||
| 28 | { |
||
| 29 | $fields->removeByName([ |
||
| 30 | 'DiscountID', |
||
| 31 | ]); |
||
| 32 | |||
| 33 | if ($this->owner->exists()) { |
||
| 34 | $fields->addFieldToTab( |
||
| 35 | 'Root.Main', |
||
| 36 | $discountButton = HasOneButtonField::create($this->owner, 'Discount'), |
||
| 37 | 'FirstName' |
||
| 38 | ); |
||
| 39 | |||
| 40 | $discountButton->getConfig()->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 |