You are here

public function TocManager::create in TOC API 8

Constructs a new TOC object.

Parameters

string $id: ID used to track the TOC object's instance. Typically, the ID can be the TOC implementation's module name.

string $source: The HTML content that contains header tags used to create a table of contents.

array $options: (optional) An associative array of options used to generate a table of contents and bookmarked headers.

Return value

\Drupal\toc_api\TocInterface A new TOC object.

Overrides TocManagerInterface::create

File

src/TocManager.php, line 41

Class

TocManager
Defines a service that creates and manages table of contents instances.

Namespace

Drupal\toc_api

Code

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];
}