You are here

public static function FrontMatterTest::createFrontMatterSource in Drupal 10

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/Component/FrontMatter/FrontMatterTest.php \Drupal\Tests\Component\FrontMatter\FrontMatterTest::createFrontMatterSource()

Creates a front matter source string.

Parameters

array|null $yaml: The YAML array to prepend as a front matter block.

string $content: The source contents.

Return value

string The new source.

2 calls to FrontMatterTest::createFrontMatterSource()
FrontMatterTest::testFrontMatter in core/tests/Drupal/KernelTests/Core/Theme/FrontMatterTest.php
Test Twig template front matter.
FrontMatterTest::testFrontMatterData in core/tests/Drupal/Tests/Component/FrontMatter/FrontMatterTest.php
Tests the parsed data from front matter.

File

core/tests/Drupal/Tests/Component/FrontMatter/FrontMatterTest.php, line 35

Class

FrontMatterTest
Tests front matter parsing helper methods.

Namespace

Drupal\Tests\Component\FrontMatter

Code

public static function createFrontMatterSource(?array $yaml, string $content = self::SOURCE) : string {

  // Encode YAML and wrap in a front matter block.
  $frontMatter = '';
  if (is_array($yaml)) {
    $yaml = $yaml ? trim(Yaml::encode($yaml)) . "\n" : '';
    $frontMatter = FrontMatter::SEPARATOR . "\n{$yaml}" . FrontMatter::SEPARATOR . "\n";
  }
  return $frontMatter . $content;
}