Completed
Push — master ( 6815df...d4e03c )
by Jason
05:43
created

PageSectionBlock::singular_name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
3
/**
4
 * Class PageSectionBlock
5
 *
6
 * @method HasManyList $Sections
7
 */
8
class PageSectionBlock extends Block
9
{
10
    /**
11
     * @return string
12
     */
13 9
    public function singular_name()
14
    {
15 9
        return _t('PageSectionBlock.SINGULARNAME', 'Page Sections Block');
16
    }
17
18
    /**
19
     * @return string
20
     */
21
    public function plural_name()
22
    {
23
        return _t('PageSectionBlock.PLURALNAME', 'Page Sections Blocks');
24
    }
25
26
    /**
27
     * @var array
28
     */
29
    private static $has_many = [
30
        'Sections' => 'PageSectionObject',
31
    ];
32
33
    /**
34
     * @return FieldList
35
     */
36 1 View Code Duplication
    public function getCMSFields()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38 1
        $fields = parent::getCMSFields();
39
40 1
        if ($this->ID) {
41
            // Sections
42 1
            $config = GridFieldConfig_RecordEditor::create();
43 1
            if (class_exists('GridFieldOrderableRows')) {
44 1
                $config->addComponent(new GridFieldOrderableRows('SortOrder'));
45 1
            }
46 1
            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
47 1
            $config->removeComponentsByType('GridFieldDeleteAction');
48 1
            $config->addComponent(new GridFieldDeleteAction(false));
49 1
            $sectionsField = GridField::create('Sections', 'Sections', $this->Sections()->sort('SortOrder'), $config);
0 ignored issues
show
Bug introduced by
The method Sections() does not exist on PageSectionBlock. Did you maybe mean getPageSections()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
50 1
            $fields->addFieldsToTab('Root.Sections', array(
51 1
                $sectionsField,
52 1
            ));
53 1
        }
54
55 1
        return $fields;
56
    }
57
58
    /**
59
     * @return mixed
60
     */
61
    public function getPageSections()
62
    {
63
        return $this->Sections()->sort('SortOrder');
0 ignored issues
show
Bug introduced by
The method Sections() does not exist on PageSectionBlock. Did you maybe mean getPageSections()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
64
    }
65
}