TocManager.php in TOC API 8
File
src/TocManager.php
View source
<?php
namespace Drupal\toc_api;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\toc_api\Entity\TocType;
class TocManager implements TocManagerInterface {
protected $configFactory;
protected $tocs = [];
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
public function create($id, $source, array $options = []) {
if ($default_toc = TocType::load('default')) {
$options = NestedArray::mergeDeep($default_toc
->getOptions(), $options);
}
$this->tocs[$id] = new Toc($source, $options);
return $this->tocs[$id];
}
public function getToc($id) {
return isset($this->tocs[$id]) ? $this->tocs[$id] : NULL;
}
public function reset($id = NULL) {
if ($id === NULL) {
$this->tocs = [];
}
else {
unset($this->tocs[$id]);
}
}
}
Classes
Name |
Description |
TocManager |
Defines a service that creates and manages table of contents instances. |