function HelpTopicsSyntaxTest::leaveNode

Same name and namespace in other branches
  1. 11.x core/modules/help/tests/src/Kernel/HelpTopicsSyntaxTest.php \Drupal\Tests\help\Kernel\HelpTopicsSyntaxTest::leaveNode()

File

core/modules/help/tests/src/Kernel/HelpTopicsSyntaxTest.php, line 391

Class

HelpTopicsSyntaxTest
Verifies that all core Help topics can be rendered and comply with standards.

Namespace

Drupal\Tests\help\Kernel

Code

public function leaveNode(Node $node, Environment $env) : ?Node {
  if (!$this->manner) {
    return $node;
  }
  // For all special processing, we want to remove variables, set statements,
  // and assorted Twig expression calls (if, do, etc.).
  if ($node instanceof SetNode || $node instanceof PrintNode || $node instanceof AbstractExpression) {
    return NULL;
  }
  if ($node instanceof TwigNodeTrans) {
    // Count the number of translated chunks.
    $this->maxChunk++;
    if ($this->manner == 'remove_translated') {
      // Remove all translated text.
      return NULL;
    }
    elseif ($this->manner == 'replace_translated') {
      // Replace with a dummy string.
      $node = new TextNode('dummy', 0);
    }
    elseif ($this->manner == 'translated_chunk') {
      // Return the text only if it's the next chunk we're supposed to return.
      // Add a wrapper, because non-translated nodes will still be returned.
      if ($this->maxChunk == $this->returnChunk) {
        return new TextNode(static::DELIMITER . $this->extractText($node) . static::DELIMITER, 0);
      }
      else {
        return NULL;
      }
    }
  }
  if ($this->manner == 'remove_translated' && $node instanceof TextNode) {
    // For this processing, we also want to remove all HTML tags and
    // whitespace from TextNodes.
    $text = $node->getAttribute('data');
    $text = strip_tags($text);
    $text = preg_replace('|\\s+|', '', $text);
    return new TextNode($text, 0);
  }
  return $node;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.