MemberExtension   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 11
c 1
b 0
f 0
dl 0
loc 26
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A updateCMSFields() 0 14 2
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
The private property $has_one is not used, and could be removed.
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