function FrontMatterTest::createFrontMatterSource
Same name in other branches
- 9 core/tests/Drupal/Tests/Component/FrontMatter/FrontMatterTest.php \Drupal\Tests\Component\FrontMatter\FrontMatterTest::createFrontMatterSource()
- 11.x 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 37
Class
- FrontMatterTest
- Tests front matter parsing helper methods.
Namespace
Drupal\Tests\Component\FrontMatterCode
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;
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.