Сломался сайт после модуля Simple TOC

Главные вкладки

Аватар пользователя drup-user drup-user 6 июля 2018 в 1:47

Здравствуйте. Установил Simple TOC для создания авто-оглавления страниц сайта. Все какое-то время работало.
Решил отредактировать статью и удалил один h4 заголовок.

После чего сайт падает при заходе на страницу с оглавлением или просто в админку "содержимое", вижу такое сообщение:
img_2018_07_06_01_40_33

В журнале событий вижу следующее
Error: Call to a member function appendChild() on null в функции simple_toc_build_toc() (строка 419 в файле /var/www/drupal/sites/all/modules/simple_toc/simple_toc.module).

Нашел в модуле строку 419

<?phpfunction simple_toc_build_toc($html, $settings) {

  // If the html does not contain headings, return nothing.
  if (preg_match('!<h[1-6].*>.*</h[1-6]>!', $html) == FALSE) return FALSE;

  // Create a DOMDocument and populate it with the supplied HTML.
  $dom_html = new TocDOMDocument();
  libxml_use_internal_errors(true);
  // Encoding the HTML as UTF-8 - in order to handle special characters.
  $dom_html->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
  libxml_clear_errors();
  $xpath = new DOMXPath($dom_html);
  $last = 1;

  // Create a DOMDocument for the TOC.
  $dom_toc = new TocDOMDocument();

  // Create a div to wrap the entire TOC.
  $elmnt = $dom_toc->createElement('div');
  $elmnt->setAttribute('class', 'toc-wrapper');
  $dom_toc->appendChild($elmnt);

  // Add a title to the TOC, if configured.
  if ($settings['title_type']) {
    $elmnt = $dom_toc->createElement($settings['title_type'], t($settings['title_text']));
    $elmnt->setAttribute('class', 'toc-title');
    $dom_toc->firstChild->appendChild($elmnt);
  }

  // Create a top TOC element, and set the head to it.
  $elmnt = $dom_toc->createElement($settings['toc_type']);
  $elmnt->setAttribute('class', 'toc');
  $dom_toc->firstChild->appendChild($elmnt);
  $head = &$dom_toc->firstChild->lastChild;

  // Get all H1, H2, …, H6 elements from the HTML.
  foreach ($xpath->query('//*[self::h1 or self::h2 or self::h3 or self::h4 or self::h5 or self::h6]') as $headline) {

    // Get level of current headline.
    sscanf($headline->tagName, 'h%u', $curr);

    // Move head reference if necessary.
    if ($curr < $last) {
      // Move upwards.
      for ($i = $curr; $i < $last; $i++) {
        $head = &$head->parentNode->parentNode;
      }
    }
    elseif ($curr > $last && $head->lastChild) {
      // Move downwards and create new sub-toc wrappers.
      for ($i = $last; $i < $curr; $i++) {
        $elmnt = $dom_toc->createElement($settings['toc_type']);
        $elmnt->setAttribute('class', 'indented toc-h' . $curr . '-wrap');
//       Строка 419
$head->lastChild->appendChild($elmnt);
        $head = &$head->lastChild->lastChild;
      }
    }
    $last = $curr;

    // Add the TOC item to its wrapper.
    if ($settings['toc_type'] == 'div') {
      $elmnt = $dom_toc->createElement('div');
    }
    else {
      $elmnt = $dom_toc->createElement('li');
    }
    $elmnt->setAttribute('class', 'toc-h' . $last);
    $head->appendChild($elmnt);
?>

Что теперь делать? Пробовал вернуть все назад - не помогает.

Лучший ответ

Аватар пользователя drup-user drup-user 7 июля 2018 в 17:51

Всем спасибо, если кто найдет тему в гугле, то проблему решил так:

Модуль крашится, если не верно указать структуру заголовков. Например, если после <h2> идет сразу <h4> - модуль вылетит.

Комментарии

Аватар пользователя ivnish ivnish 6 июля 2018 в 7:21

Если нет drush, а его наверняка нет, то можно поставить в таблице system "status=0" у этого модуля, и очистить все таблицы cache*

Аватар пользователя drup-user drup-user 7 июля 2018 в 17:51

Всем спасибо, если кто найдет тему в гугле, то проблему решил так:

Модуль крашится, если не верно указать структуру заголовков. Например, если после <h2> идет сразу <h4> - модуль вылетит.