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