silverstripe-autotoc 

silverstripe-autotoc Commit Details

Date:2017-12-21 17:43:11 (3 years 29 days ago)
Author:Nicola Fontana
Branch:dev, master
Commit:94378c699b4c44dde3f2064616f49ab31d3c7caf
Parents: a0a809cc8035e4b6f2bb7b08445541e15bc17b82
Message:Use the injector for instantiating the Tocifier

Changes:
Msrc/AutotocExtension.php (5 diffs)

File differences

src/AutotocExtension.php
22
33
44
5
65
76
7
88
99
1010
......
2323
2424
2525
26
26
2727
2828
2929
......
3737
3838
3939
40
40
4141
4242
4343
......
110110
111111
112112
113
113
114114
115115
116116
......
135135
136136
137137
138
138
139139
140140
141141
namespace eNTiDi\Autotoc;
use eNTiDi\Autotoc\Tocifier;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Extension;
use SilverStripe\Core\Injector\Injector;
use SilverStripe\ORM\ArrayList;
use SilverStripe\View\ArrayData;
private static function convertNode($node)
{
$data = ArrayData::create([
$data = new ArrayData([
'Id' => $node['id'],
'Title' => $node['title']
]);
private static function convertChildren($children)
{
$list = ArrayList::create();
$list = new ArrayList();
foreach ($children as $child) {
$list->push(self::convertNode($child));
private function getTocifier()
{
if (is_null($this->tocifier)) {
$tocifier = new Tocifier($this->getHtml());
$tocifier = Injector::inst()->create('Tocifier');
// TODO: not sure this is the best approach... maybe I
// should look to $this->owner->dataRecord before
$config = Config::inst()->get(__CLASS__, 'augment_callback');
return '';
}
return ArrayData::create([
return new ArrayData([
'Children' => self::convertChildren($toc)
]);
}

Archive Download the corresponding diff file