forked from theodo/TheodoRogerCmsBundle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow using LayoutExtractor for to extract layout
- Loading branch information
1 parent
d86b988
commit d6f0822
Showing
3 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Theodo\RogerCmsBundle\Extractor; | ||
|
||
/** | ||
* Implement this interface to extract layout string from a template. | ||
* This can be useful if you have other Twig extensions that parse layouts. | ||
* | ||
* @author Marek Kalnik <[email protected]> | ||
*/ | ||
interface LayoutExtractorInterface | ||
{ | ||
/** | ||
* Function extracting the layout from template. | ||
* If no layout found this should return a empty string. | ||
* | ||
* @param string $template | ||
* | ||
* @return string | ||
*/ | ||
public function getLayout($template); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,13 +5,14 @@ | |
use Symfony\Component\Form\DataTransformerInterface; | ||
use Symfony\Component\Form\Exception\TransformationFailedException; | ||
use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
use Theodo\RogerCmsBundle\Extractor\LayoutExtractorInterface; | ||
|
||
/** | ||
* This DataTransformer splits page content on template and proper content | ||
* | ||
* @autor Marek Kalnik <[email protected]> | ||
*/ | ||
class LayoutExtractor implements DataTransformerInterface | ||
class LayoutExtractor implements DataTransformerInterface, LayoutExtractorInterface | ||
{ | ||
/** | ||
* Receives page content and splits it | ||
|
@@ -83,6 +84,22 @@ public function reverseTransform($array) | |
return $pageContent; | ||
} | ||
|
||
/** | ||
* Extracts layout from given twig template | ||
* | ||
* @param string $template | ||
*/ | ||
public function getLayout($template) | ||
{ | ||
if ($layout = trim($this->matchLayoutName($template), '"')) { | ||
return 'layout:' . $layout; | ||
} | ||
|
||
$layout = trim($this->matchTemplateName($template), '"'); | ||
|
||
return $layout; | ||
} | ||
|
||
/** | ||
* @param String $pageContent Content to find layout name in. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters