|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Sunnysideup\ElementalToc; |
|
4
|
|
|
|
|
5
|
|
|
use DNADesign\Elemental\Models\ElementContent; |
|
6
|
|
|
use SilverStripe\Forms\FieldList; |
|
7
|
|
|
use SilverStripe\Forms\HTMLEditor\HTMLEditorField; |
|
8
|
|
|
use SilverStripe\Forms\LiteralField; |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Class \Sunnysideup\ElementalToc\ElementToc |
|
12
|
|
|
* |
|
13
|
|
|
* @property bool $WithNumbers |
|
14
|
|
|
*/ |
|
15
|
|
|
class ElementToc extends ElementContent |
|
16
|
|
|
{ |
|
17
|
|
|
private static $icon = 'font-icon-list'; |
|
18
|
|
|
|
|
19
|
|
|
|
|
20
|
|
|
private static $table_name = 'ElementToc'; |
|
21
|
|
|
|
|
22
|
|
|
private static $singular_name = 'table of contents'; |
|
23
|
|
|
|
|
24
|
|
|
private static $plural_name = 'tables of contents'; |
|
25
|
|
|
|
|
26
|
|
|
private static $description = 'Table of Contents for Blocks'; |
|
27
|
|
|
|
|
28
|
|
|
private static $db = [ |
|
29
|
|
|
'WithNumbers' => 'Boolean', |
|
30
|
|
|
]; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Re-title the HTML field to Content |
|
34
|
|
|
* |
|
35
|
|
|
* {@inheritDoc} |
|
36
|
|
|
*/ |
|
37
|
|
|
public function getCMSFields() |
|
38
|
|
|
{ |
|
39
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
40
|
|
|
/** @var HTMLEditorField $editorField */ |
|
41
|
|
|
$fields->removeByName('HTML'); |
|
42
|
|
|
$fields->addFieldsToTab( |
|
43
|
|
|
'Root.Main', |
|
44
|
|
|
[ |
|
45
|
|
|
LiteralField::create('TOC', $this->getHTML()) |
|
46
|
|
|
] |
|
47
|
|
|
); |
|
48
|
|
|
}); |
|
49
|
|
|
return parent::getCMSFields(); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function getToc() |
|
53
|
|
|
{ |
|
54
|
|
|
return $this->Parent() |
|
55
|
|
|
->Elements() |
|
56
|
|
|
->exclude(['ID' => $this->ID]) |
|
57
|
|
|
->filter(['Sort:GreaterThanOrEqual' => $this->Sort]); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function getHTML() |
|
61
|
|
|
{ |
|
62
|
|
|
return $this->renderWith("SunnySideUp\\ElementalToC\\ElementToC"); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function getType() |
|
66
|
|
|
{ |
|
67
|
|
|
return 'Table of Contents'; |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|