public function write(&$text)
    {
        // All: Add the action if left empty
        if (preg_match_all('#<\s*form.*?action=""#im', $text, $matches, PREG_SET_ORDER)) {
            $view   = $this->getTemplate()->getView();
            $state  = $view->getModel()->getState();
            $action = $view->getRoute(http_build_query($state->getData($state->isUnique())));
            
            foreach ($matches as $match) {
                $str  = str_replace('action=""', 'action="'.$action.'"', $match[0]);
                $text = str_replace($match[0], $str, $text);
            }
        }
        
        // POST : Add token
        $matches = array();
        preg_match_all('/(<form.*method="post".*>)/i', $text, $matches, PREG_SET_ORDER);
       
        foreach ($matches as $match) {
            $input = PHP_EOL.'<input type="hidden" name="'.$this->_tokenName().'" value="'.$this->_tokenValue().'" />';
            $text = str_replace($match[0], $match[0].$input, $text, $count);
        }
       
        // GET : Add token to .-anahita-grid forms
        $matches = array();
        preg_match_all('#(<\s*?form\s+?.*?class=(?:\'|")[^\'"]*?-anahita-grid.*?(?:\'|").*?)#im', $text, $matches, PREG_SET_ORDER);
        
        foreach ($matches as $match) {
            $input = ' data-token-name="'.$this->_tokenName().'" data-token-value="'.$this->_tokenValue().'"';
            $text= str_replace($match[0], $match[0].$input, $text, $count);
        }
        
        // GET : Add query params
        $matches = array();
        if (preg_match_all('#<form.*action=".*\?(.*)".*method="get".*>#iU', $text, $matches)) {
            foreach ($matches[1] as $key => $query) {
                parse_str(str_replace('&amp;', '&', $query), $query);
                
                $input = $this->_renderQuery($query);
                $text  = str_replace($matches[0][$key], $matches[0][$key].$input, $text);
            }
        }
        
        return $this;
    }
public function write(&$text)
    {
        // All: Add the action if left empty
        if (preg_match_all('#<\s*form.*?action=""#im', $text, $matches, PREG_SET_ORDER)) {
            $view   = $this->getTemplate()->getView();
            $state  = $view->getModel()->getState();
            $action = $view->getRoute(http_build_query($state->getData($state->isUnique())));
            
            foreach ($matches as $match) {
                $str  = str_replace('action=""', 'action="'.$action.'"', $match[0]);
                $text = str_replace($match[0], $str, $text);
            }
        }
        
        // POST : Add token
        $matches = array();
        preg_match_all('/(<form.*method="post".*>)/i', $text, $matches, PREG_SET_ORDER);
       
        foreach ($matches as $match) {
            $input = PHP_EOL.'<input type="hidden" name="'.$this->_tokenName().'" value="'.$this->_tokenValue().'" />';
            $text = str_replace($match[0], $match[0].$input, $text, $count);
        }
       
        // GET : Add token to .-anahita-grid forms
        $matches = array();
        preg_match_all('#(<\s*?form\s+?.*?class=(?:\'|")[^\'"]*?-anahita-grid.*?(?:\'|").*?)#im', $text, $matches, PREG_SET_ORDER);
        
        foreach ($matches as $match) {
            $input = ' data-token-name="'.$this->_tokenName().'" data-token-value="'.$this->_tokenValue().'"';
            $text= str_replace($match[0], $match[0].$input, $text, $count);
        }
        
        // GET : Add query params
        $matches = array();
        if (preg_match_all('#<form.*action=".*\?(.*)".*method="get".*>#iU', $text, $matches)) {
            foreach ($matches[1] as $key => $query) {
                parse_str(str_replace('&amp;', '&', $query), $query);
                
                $input = $this->_renderQuery($query);
                $text  = str_replace($matches[0][$key], $matches[0][$key].$input, $text);
            }
        }
        
        return $this;
    }
public function write ( & $ text ) { // All: Add the action if left empty if ( preg_match_all ( '#<\s*form.*?action=""#im' , $ text , $ matches , PREG_SET_ORDER ) ) { $ view = $ this -> getTemplate ( ) -> getView ( ) ; $ state = $ view -> getModel ( ) -> getState ( ) ; $ action = $ view -> getRoute ( http_build_query ( $ state -> getData ( $ state -> isUnique ( ) ) ) ) ; foreach ( $ matches as $ match ) { $ str = str_replace ( 'action=""' , 'action="' . $ action . '"' , $ match [ 0 ] ) ; $ text = str_replace ( $ match [ 0 ] , $ str , $ text ) ; } } // POST : Add token $ matches = array ( ) ; preg_match_all ( '/(<form.*method="post".*>)/i' , $ text , $ matches , PREG_SET_ORDER ) ; foreach ( $ matches as $ match ) { $ input = PHP_EOL . '<input type="hidden" name="' . $ this -> _tokenName ( ) . '" value="' . $ this -> _tokenValue ( ) . '" />' ; $ text = str_replace ( $ match [ 0 ] , $ match [ 0 ] . $ input , $ text , $ count ) ; } // GET : Add token to .-anahita-grid forms $ matches = array ( ) ; preg_match_all ( '#(<\s*?form\s+?.*?class=(?:\'|")[^\'"]*?-anahita-grid.*?(?:\'|").*?)#im' , $ text , $ matches , PREG_SET_ORDER ) ; foreach ( $ matches as $ match ) { $ input = ' data-token-name="' . $ this -> _tokenName ( ) . '" data-token-value="' . $ this -> _tokenValue ( ) . '"' ; $ text = str_replace ( $ match [ 0 ] , $ match [ 0 ] . $ input , $ text , $ count ) ; } // GET : Add query params $ matches = array ( ) ; if ( preg_match_all ( '#<form.*action=".*\?(.*)".*method="get".*>#iU' , $ text , $ matches ) ) { foreach ( $ matches [ 1 ] as $ key => $ query ) { parse_str ( str_replace ( '&amp;' , '&' , $ query ) , $ query ) ; $ input = $ this -> _renderQuery ( $ query ) ; $ text = str_replace ( $ matches [ 0 ] [ $ key ] , $ matches [ 0 ] [ $ key ] . $ input , $ text ) ; } } return $ this ; }
Add unique token field

@param string
@return LibBaseTemplateFilterForm
Add unique token field