Skip to content

[Twig] Fix Twig namespaces #9994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions components/form.rst
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
use Symfony\Bridge\Twig\Extension\FormExtension;
use Symfony\Component\Form\FormRenderer;
use Symfony\Bridge\Twig\Form\TwigRendererEngine;
use Twig\Environment;
use Twig\Loader\FilesystemLoader;
use Twig\RuntimeLoader\FactoryRuntimeLoader;

// the Twig file that holds all the default markup for rendering forms
// this file comes with TwigBridge
Expand All @@ -191,12 +194,12 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
// the path to your other templates
$viewsDirectory = realpath(__DIR__.'/../views');

$twig = new Twig_Environment(new Twig_Loader_Filesystem(array(
$twig = new Environment(new FilesystemLoader(array(
$viewsDirectory,
$vendorTwigBridgeDirectory.'/Resources/views/Form',
)));
$formEngine = new TwigRendererEngine(array($defaultFormTheme), $twig);
$twig->addRuntimeLoader(new \Twig_FactoryRuntimeLoader(array(
$twig->addRuntimeLoader(new FactoryRuntimeLoader(array(
FormRenderer::class => function () use ($formEngine, $csrfManager) {
return new FormRenderer($formEngine, $csrfManager);
},
Expand All @@ -213,7 +216,7 @@ to bootstrap or access Twig and add the :class:`Symfony\\Bridge\\Twig\\Extension
->getFormFactory();

.. versionadded:: 1.30
The ``Twig_FactoryRuntimeLoader`` was introduced in Twig 1.30.
The ``Twig\\RuntimeLoader\\FactoryRuntimeLoader`` was introduced in Twig 1.30.

The exact details of your `Twig Configuration`_ will vary, but the goal is
always to add the :class:`Symfony\\Bridge\\Twig\\Extension\\FormExtension`
Expand Down Expand Up @@ -253,7 +256,7 @@ installed:
$ composer require symfony/translation symfony/config

Next, add the :class:`Symfony\\Bridge\\Twig\\Extension\\TranslationExtension`
to your ``Twig_Environment`` instance::
to your ``Twig\\Environment`` instance::

use Symfony\Component\Form\Forms;
use Symfony\Component\Translation\Translator;
Expand Down
3 changes: 2 additions & 1 deletion controller/service.rst
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ service and use it directly::
namespace App\Controller;

use Symfony\Component\HttpFoundation\Response;
use Twig\Environment;

class HelloController
{
private $twig;

public function __construct(\Twig_Environment $twig)
public function __construct(Environment $twig)
{
$this->twig = $twig;
}
Expand Down
2 changes: 1 addition & 1 deletion reference/configuration/twig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ called to determine the default escaping applied to the template.
base_template_class
~~~~~~~~~~~~~~~~~~~

**type**: ``string`` **default**: ``'Twig_Template'``
**type**: ``string`` **default**: ``'Twig\\Template'``

Twig templates are compiled into PHP classes before using them to render
contents. This option defines the base class from which all the template classes
Expand Down
2 changes: 1 addition & 1 deletion service_container.rst
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ But, with ``autoconfigure: true``, you don't need the tag. In fact, if you're us
the :ref:`default services.yaml config <service-container-services-load-example>`,
you don't need to do *anything*: the service will be automatically loaded. Then,
``autoconfigure`` will add the ``twig.extension`` tag *for* you, because your class
implements ``Twig_ExtensionInterface``. And thanks to ``autowire``, you can even add
implements ``Twig\\Extension\\ExtensionInterface``. And thanks to ``autowire``, you can even add
constructor arguments without any configuration.

.. _container-public:
Expand Down
4 changes: 2 additions & 2 deletions service_container/tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ Autoconfiguring Tags

If you enable :ref:`autoconfigure <services-autoconfigure>`, then some tags are
automatically applied for you. That's true for the ``twig.extension`` tag: the
container sees that your class extends ``Twig_Extension`` (or more accurately,
that it implements ``Twig_ExtensionInterface``) and adds the tag for you.
container sees that your class extends ``AbstractExtension`` (or more accurately,
that it implements ``ExtensionInterface``) and adds the tag for you.

.. tip::

Expand Down
6 changes: 4 additions & 2 deletions templating/twig_extension.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,16 @@ callable defined in ``getFilters()``::
namespace App\Twig;

use App\Twig\AppRuntime;
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class AppExtension extends \Twig_Extension
class AppExtension extends AbstractExtension
{
public function getFilters()
{
return array(
// the logic of this filter is now implemented in a different class
new \Twig_SimpleFilter('price', array(AppRuntime::class, 'priceFilter')),
new TwigFilter('price', array(AppRuntime::class, 'priceFilter')),
);
}
}
Expand Down