Passed
Pull Request — master (#3)
by Jason
02:09
created

ElementSectionNavigation::ElementSummary()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Elements\Section\Elements;
4
5
use DNADesign\Elemental\Models\BaseElement;
6
use DNADesign\Elemental\Models\ElementalArea;
7
use DNADesign\ElementalList\Model\ElementList;
0 ignored issues
show
Bug introduced by
The type DNADesign\ElementalList\Model\ElementList was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use SilverStripe\ORM\FieldType\DBField;
9
use SilverStripe\ORM\FieldType\DBHTMLText;
10
11
/**
12
 * Class ElementSectionNavigation.
13
 */
14
class ElementSectionNavigation extends BaseElement
15
{
16
    /**
17
     * @var string
18
     */
19
    private static $icon = 'sectionnav-icon';
0 ignored issues
show
introduced by
The private property $icon is not used, and could be removed.
Loading history...
20
21
    /**
22
     * @var string
23
     */
24
    private static $singular_name = 'Section Navigation Element';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
25
26
    /**
27
     * @var string
28
     */
29
    private static $plural_name = 'Section Navigation Elements';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
30
31
    /**
32
     * @var string
33
     */
34
    private static $table_name = 'ElementSectionNavigation';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
35
36
    /**
37
     * @return null|\SilverStripe\ORM\DataObject
38
     * @throws \SilverStripe\ORM\ValidationException
39
     */
40 1
    public function getPage()
41
    {
42 1
        $area = $this->Parent();
43
44 1
        if ($area instanceof ElementalArea && $area->exists()) {
45
            if ($area->getOwnerPage() instanceof ElementList && $area->getOwnerPage()->exists()) {
46
                return $area->getOwnerPage()->getPage();
47
            } else {
48
                return $area->getOwnerPage();
49
            }
50
        }
51 1
        return parent::getPage();
52
    }
53
54
    /**
55
     * @return bool|\SilverStripe\ORM\SS_List
56
     */
57 1
    public function getSectionNavigation()
58
    {
59 1
        if ($page = $this->getPage()) {
60
            if ($page->Children()->Count() > 0) {
61
                return $page->Children();
62
            } elseif ($page->Parent()) {
63
                return $page->Parent()->Children();
64
            } else {
65
                return false;
66
            }
67
        }
68
69 1
        return false;
70
    }
71
72
    /**
73
     * @return DBHTMLText
74
     */
75 1
    public function ElementSummary()
76
    {
77 1
        return DBField::create_field('HTMLText', '<p>Section Navigation</p>')->Summary(20);
78
    }
79
80
    /**
81
     * @return string
82
     */
83 1
    public function getType()
84
    {
85 1
        return _t(__CLASS__.'.BlockType', 'Section Navigation');
86
    }
87
}
88