src/Frontend/Core/Engine/FormTokenParser.php line 8

Open in your IDE?
  1. <?php
  2. namespace Frontend\Core\Engine;
  3. /**
  4.  * Twig template tag for the start/opening element of a form tag.
  5.  */
  6. class FormTokenParser extends \Twig_TokenParser
  7. {
  8.     /**
  9.      * @param \Twig_Token $token
  10.      *
  11.      * @throws \Twig_Error_Syntax
  12.      *
  13.      * @return \Twig_Node
  14.      */
  15.     public function parse(\Twig_Token $token): \Twig_Node
  16.     {
  17.         $stream $this->parser->getStream();
  18.         $form $stream->expect(\Twig_Token::NAME_TYPE)->getValue();
  19.         $stream->expect(\Twig_Token::BLOCK_END_TYPE);
  20.         if (FormState::$current !== null) {
  21.             throw new \Twig_Error_Syntax(
  22.                 sprintf(
  23.                     'form [%s] not closed while opening form [%s]',
  24.                     FormState::$current,
  25.                     $form
  26.                 ),
  27.                 $token->getLine(),
  28.                 $stream->getFilename()
  29.             );
  30.         }
  31.         FormState::$current $form;
  32.         return new FormNode($form$token->getLine(), $this->getTag());
  33.     }
  34.     /**
  35.      * @return string
  36.      */
  37.     public function getTag(): string
  38.     {
  39.         return 'form';
  40.     }
  41. }