public function renderDocumentToc(\Twig_Environment $twig, $toc = null, $deep = 0)
{
if (null === $toc) {
$toc = $this->getCarewGlobals($twig)->document;
}
if (is_object($toc) && $toc instanceof Document) {
$toc = $toc->getToc();
}
if (!is_array($toc)) {
throw new \InvalidArgumentException('First argument given to render_document_toc must be a Document or an array of TOC');
}
if (1 == count($toc)) {
$first = reset($toc);
if (!isset($first['title'])) {
$toc = $first['children'];
}
}
$parameters = array('children' => $toc, 'deep' => $deep);
return $this->renderBlock($twig, 'document_toc', $parameters);
}