class TocManager in TOC API 8
Defines a service that creates and manages table of contents instances.
Hierarchy
- class \Drupal\toc_api\TocManager implements TocManagerInterface
Expanded class hierarchy of TocManager
1 string reference to 'TocManager'
1 service uses TocManager
File
- src/
TocManager.php, line 12
Namespace
Drupal\toc_apiView source
class TocManager implements TocManagerInterface {
/**
* The config factory.
*
* @var \Drupal\Core\Config\ConfigFactoryInterface
*/
protected $configFactory;
/**
* The TOC instances.
*
* @var \Drupal\toc_api\Toc[]
*/
protected $tocs = [];
/**
* Constructs a new TocManager.
*
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The config factory.
*/
public function __construct(ConfigFactoryInterface $config_factory) {
$this->configFactory = $config_factory;
}
/**
* {@inheritdoc}
*/
public function create($id, $source, array $options = []) {
// Merge default TOC type options with passed options.
/** @var \Drupal\toc_api\TocTypeInterface $default_toc */
if ($default_toc = TocType::load('default')) {
$options = NestedArray::mergeDeep($default_toc
->getOptions(), $options);
}
// Create and store a reference to a new Toc.
$this->tocs[$id] = new Toc($source, $options);
return $this->tocs[$id];
}
/**
* {@inheritdoc}
*/
public function getToc($id) {
return isset($this->tocs[$id]) ? $this->tocs[$id] : NULL;
}
/**
* {@inheritdoc}
*/
public function reset($id = NULL) {
if ($id === NULL) {
$this->tocs = [];
}
else {
unset($this->tocs[$id]);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TocManager:: |
protected | property | The config factory. | |
TocManager:: |
protected | property | The TOC instances. | |
TocManager:: |
public | function |
Constructs a new TOC object. Overrides TocManagerInterface:: |
|
TocManager:: |
public | function |
Get the current TOC instance. Overrides TocManagerInterface:: |
|
TocManager:: |
public | function |
Reset the current TOC instance. Overrides TocManagerInterface:: |
|
TocManager:: |
public | function | Constructs a new TocManager. |