public function testParseRepeaterToRender() { $content = ''; $content .= '{repeater name="websiteRepeater" label="Website Repeater"}' . PHP_EOL; $content .= '<h1>{text name="websiteName" label="Website Name"}Our wonderful website{/text}</h1>' . PHP_EOL; $content .= '{textarea name="websiteContent" label="Website Content"}Here are all the reasons we like our website{/textarea}' . PHP_EOL; $content .= '{/repeater}' . PHP_EOL; $syntax = Parser::parse($content); /* * Default content */ $result = $syntax->render(); $expected = ''; $expected .= PHP_EOL; // Repeater open $expected .= '<h1>Our wonderful website</h1>' . PHP_EOL; $expected .= 'Here are all the reasons we like our website' . PHP_EOL; $expected .= PHP_EOL; // Repeater close $this->assertEquals($expected, $result); /* * Multiple repeats */ $sampleData = ['websiteRepeater' => [['websiteName' => 'Moo', 'websiteContent' => 'Cow'], ['websiteName' => 'Foo', 'websiteContent' => 'Bar']]]; $result = $syntax->render($sampleData); $expected = ''; $expected .= PHP_EOL; // Repeater open $expected .= '<h1>Moo</h1>' . PHP_EOL; $expected .= 'Cow' . PHP_EOL; $expected .= PHP_EOL; // Repeater divide $expected .= '<h1>Foo</h1>' . PHP_EOL; $expected .= 'Bar' . PHP_EOL; $expected .= PHP_EOL; // Repeater close $this->assertEquals($expected, $result); }
public function testParseVariableToEdit() { $content = '{variable type="text" name="websiteName" label="Website Name"}Our wonderful website{/variable}'; $result = Parser::parse($content)->toEditor(); $this->assertArrayHasKey('websiteName', $result); $this->assertArrayHasKey('type', $result['websiteName']); $this->assertArrayHasKey('default', $result['websiteName']); $this->assertArrayHasKey('label', $result['websiteName']); $this->assertEquals('text', $result['websiteName']['type']); $this->assertEquals('Our wonderful website', $result['websiteName']['default']); $this->assertEquals('Website Name', $result['websiteName']['label']); }
public function getSyntaxParser($content) { return Parser::parse($content); }
public function listLayoutSyntaxFields() { if (!($layout = $this->getLayoutObject())) { return []; } $syntax = SyntaxParser::parse($layout->markup, ['tagPrefix' => 'page:']); $result = $syntax->toEditor(); return $result; }
public function parseSyntaxFields($content) { try { return SyntaxParser::parse($content, ['varPrefix' => 'extraData.', 'tagPrefix' => 'page:'])->toTwig(); } catch (Exception $ex) { return $content; } }
public function listLayoutSyntaxFields() { if (!($layout = $this->getLayoutObject())) { return []; } $syntax = SyntaxParser::parse($layout->markup, ['tagPrefix' => 'page:']); $result = $syntax->toEditor(); // Field names cannot clash with conflicting visible names $result = array_diff_key($result, array_flip($this->visible)); return $result; }