AccordionPageExtension::updateCMSFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 11
nc 1
nop 1
1
<?php
2
3
4
/**
5
 * Class AccordionPageExtension
6
 *
7
 * @property Page|AccordionPageExtension $owner
8
 * @method DataList|AccordionItem[] AccordionItems()
9
 */
10
class AccordionPageExtension extends DataExtension
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    private static $description = '<p>Create Accordion items here, the title will be the header and the content will show on click. To add the accordion in the content, simply put [accordion] in the WYSIWYG editor at the place where you want the accordion to appear.</p>';
13
14
    private static $has_many = [
0 ignored issues
show
Unused Code introduced by
The property $has_many is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
15
        'AccordionItems' => 'AccordionItem'
16
    ];
17
18
    public function updateCMSFields(FieldList $fields)
19
    {
20
        $helptext = _t('Accordion.HELP', self::$description);
21
        $helpField = LiteralField::create('Help', $helptext);
22
        $gridFieldConfig = GridFieldConfig_RecordEditor::create();
23
        $gridFieldConfig->addComponent(new GridFieldOrderableRows('SortOrder'));
24
        $accordionGrid = GridField::create('AccordionItems', 'AccordionItems', $this->owner->AccordionItems(),
25
            $gridFieldConfig);
26
        $gridFieldConfig->removeComponentsByType('GridFieldAddExistingAutocompleter');
27
        $fields->addFieldsToTab('Root.Accordion', [
28
            $helpField,
29
            $accordionGrid
30
        ]);
31
    }
32
}