Completed
Push — master ( d78442...d3ce5f )
by Jason
03:09
created

src/Model/AccordionPanel.php (2 issues)

1
<?php
2
3
namespace Dynamic\Elements\Accordion\Model;
4
5
use DNADesign\Elemental\Forms\TextCheckboxGroupField;
6
use Dynamic\BaseObject\Model\BaseElementObject;
7
use Dynamic\Elements\Accordion\Elements\ElementAccordion;
8
use Sheadawson\Linkable\Forms\LinkField;
9
use Sheadawson\Linkable\Models\Link;
10
use SilverStripe\Assets\Image;
11
use SilverStripe\Forms\CheckboxField;
12
use SilverStripe\Forms\FieldList;
13
use SilverStripe\Forms\TextField;
14
use SilverStripe\ORM\DataObject;
15
use SilverStripe\Security\Member;
16
use SilverStripe\Security\Permission;
17
18
/**
19
 * Class AccordionPanel
20
 * @package Dynamic\Elements\Accordion\Model
21
 *
22
 * @property int $Sort
23
 *
24
 * @property int AccordionID
25
 * @method ElementAccordion Accordion()
26
 */
27
class AccordionPanel extends BaseElementObject
28
{
29
    /**
30
     * @var string
31
     */
32
    private static $singular_name = 'Accordion Panel';
33
34
    /**
35
     * @var string
36
     */
37
    private static $plural_name = 'Accordion Panels';
38
39
    /**
40
     * @var string
41
     */
42
    private static $description = 'A panel for a Accordion widget';
43
44
    /**
45
     * @var array
46
     */
47
    private static $db = [
0 ignored issues
show
The private property $db is not used, and could be removed.
Loading history...
48
        'Sort' => 'Int',
49
    ];
50
    /**
51
     * @var array
52
     */
53
    private static $has_one = [
54
        'Accordion' => ElementAccordion::class,
55
    ];
56
57
    /**
58
     * @var array Related objects to be published recursively on AccordionPanel::publishRecursively()
59
     */
60
    private static $owns = [
61
        'Image',
62
    ];
63
64
    /**
65
     * @var array Show the panel $Title by default
66
     */
67
    private static $defaults = [
68
        'ShowTitle' => true,
69
    ];
70
71
    /**
72
     * @var string
73
     */
74
    private static $default_sort = 'Sort';
75
76
    /**
77
     * @var string Database table name, default's to the fully qualified name
78
     */
79
    private static $table_name = 'AccordionPanel';
80
81
    /**
82
     * @return FieldList
83
     *
84
     * @throws \Exception
85
     */
86
    public function getCMSFields()
87
    {
88 1
        $this->beforeUpdateCMSFields(function ($fields) {
89
            /** @var FieldList $fields */
90 1
            $fields->removeByName([
91 1
                'Sort',
92
                'AccordionID',
93
            ]);
94
95 1
            $fields->dataFieldByName('Image')
96 1
                ->setFolderName('Uploads/Elements/Accordions');
97 1
        });
98
99 1
        return parent::getCMSFields();
100
    }
101
102
    /**
103
     * @return null
104
     */
105
    public function getPage()
106
    {
107
        $page = null;
108
109
        if ($this->AccordionID) {
110
            if ($this->Accordion()->hasMethod('getPage')) {
111
                $page = $this->Accordion()->getPage();
112
            }
113
        }
114
115
        return $page;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $page also could return the type SilverStripe\ORM\DataObject which is incompatible with the documented return type null.
Loading history...
116
    }
117
}
118