Skip to content

Instantly share code, notes, and snippets.

@bwaidelich
Created February 24, 2012 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bwaidelich/1899672 to your computer and use it in GitHub Desktop.
Save bwaidelich/1899672 to your computer and use it in GitHub Desktop.
Fluid Interceptors (Replace Tabs by underscores)
<?php
abstract class Tx_BlogExample_Controller_AbstractController extends Tx_Extbase_MVC_Controller_ActionController {
protected $defaultViewObjectName = 'Tx_BlogExample_View_TemplateView';
// ...
}
?>
<?php
class Tx_BlogExample_View_Interceptor_ReplaceTabs implements Tx_Fluid_Core_Parser_InterceptorInterface {
/**
* @var boolean
*/
protected $interceptorEnabled = TRUE;
/**
* @var Tx_Extbase_Object_ObjectManagerInterface
*/
protected $objectManager;
/**
* @param Tx_Extbase_Object_ObjectManagerInterface $objectManager
* @return void
*/
public function injectObjectManager(Tx_Extbase_Object_ObjectManagerInterface $objectManager) {
$this->objectManager = $objectManager;
}
/**
* @param Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $node
* @param integer $interceptorPosition One of the INTERCEPT_* constants for the current interception point
* @param Tx_Fluid_Core_Parser_ParsingState $parsingState the current parsing state. Not needed in this interceptor.
* @return Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface
*/
public function process(Tx_Fluid_Core_Parser_SyntaxTree_NodeInterface $node, $interceptorPosition, Tx_Fluid_Core_Parser_ParsingState $parsingState) {
$nodeText = $node->getText();
$replacedNode = $this->objectManager->create('Tx_Fluid_Core_Parser_SyntaxTree_TextNode', str_replace(chr(9), '_', $nodeText));
return $replacedNode;
}
/**
* @return array Array of INTERCEPT_* constants
*/
public function getInterceptionPoints() {
return array(
self::INTERCEPT_TEXT
);
}
}
?>
<?php
class Tx_BlogExample_View_TemplateView extends Tx_Fluid_View_TemplateView {
/**
* @return Tx_Fluid_Core_Parser_Configuration
*/
protected function buildParserConfiguration() {
$parserConfiguration = parent::buildParserConfiguration();
$parserConfiguration->addInterceptor($this->objectManager->get('Tx_BlogExample_View_Interceptor_ReplaceTabs'));
return $parserConfiguration;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment