Cancelled
Push — master ( b1ac67...38ef72 )
by Nic
111:57 queued 111:57
created

PageSectionBlock::getPageSections()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * Class PageSectionBlock
5
 *
6
 * @method HasManyList $Sections
7
 */
8
class PageSectionBlock extends Block
9
{
10
11
    /**
12
     * @var string
13
     */
14
    private static $singular_name = 'Page Section Block';
15
16
    /**
17
     * @var string
18
     */
19
    private static $plural_name = 'Page Section Blocks';
20
21
    /**
22
     * @var array
23
     */
24
    private static $has_many = [
25
        'Sections' => 'PageSectionObject',
26
    ];
27
28
    /**
29
     * @return FieldList
30
     */
31 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...
32
    {
33 1
        $fields = parent::getCMSFields();
34
35 1
        if ($this->ID) {
36
            // Sections
37 1
            $config = GridFieldConfig_RecordEditor::create();
38 1
            if (class_exists('GridFieldSortableRows')) {
39
                $config->addComponent(new GridFieldSortableRows('SortOrder'));
40
            }
41 1
            $config->removeComponentsByType('GridFieldAddExistingAutocompleter');
42 1
            $config->removeComponentsByType('GridFieldDeleteAction');
43 1
            $config->addComponent(new GridFieldDeleteAction(false));
44 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...
45 1
            $fields->addFieldsToTab('Root.Sections', array(
46 1
                $sectionsField,
47 1
            ));
48 1
        }
49
50 1
        return $fields;
51
    }
52
53
    /**
54
     * @return mixed
55
     */
56
    public function getPageSections()
57
    {
58
        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...
59
    }
60
}