You are here

protected function Toc::uniqueId in TOC API 8

Generate a unique header id.

Parameters

string $id: A header id.

Return value

string A unique header id, possibly suffixed with numeric increment.

1 call to Toc::uniqueId()
Toc::initialize in src/Toc.php
Initializes the table of content index and ensure unique header ids.

File

src/Toc.php, line 458

Class

Toc
Defines A class that parses the header tags from an HTML document.

Namespace

Drupal\toc_api

Code

protected function uniqueId($id) {
  $unique_id = $id;
  $i = 1;
  while (isset($this->ids[$id])) {
    $unique_suffix = '-' . sprintf("%02s", $i);
    $id = $unique_id . $unique_suffix;
    $i++;
  }
  return $id;
}