Passed
Push — master ( 3abeb3...edd76b )
by Jason
03:04 queued 01:02
created

PromoObject::getSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
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
The private property $singular_name is not used, and could be removed.
Loading history...
23
24
    /**
25
     * @return string
26
     */
27
    private static $plural_name = 'Promos';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
28
29
    /**
30
     * @var array
31
     */
32
    private static $belongs_many_many = array(
0 ignored issues
show
introduced by
The private property $belongs_many_many is not used, and could be removed.
Loading history...
33
        'ElementPromos' => ElementPromos::class,
34
    );
35
36
    /**
37
     * @var string
38
     */
39
    private static $table_name = 'PromoObject';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
40
41
    /**
42
     * @var array
43
     */
44
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
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