Skip to content

Commit

Permalink
bug #22652 [Workflow] Move twig extension registration to twig bundle…
Browse files Browse the repository at this point in the history
… (ogizanagi)

This PR was merged into the 3.2 branch.

Discussion
----------

[Workflow] Move twig extension registration to twig bundle

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | not really
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | N/A
| License       | MIT
| Doc PR        | N/A

It's probably very late, but I think the twig extension registration is supposed to be done from the `TwigBundle` rather than the `FrameworkBundle`. Fortunately, it doesn't cause any issue currently when using the framework bundle and the workflow component without twig, because it only creates a `workflow.twig_extension` service you'll probably never call, and the `twig.extension` tag is never processed. But still, creates a useless service that cannot be called (and is not removed because it's public).

So this PR aims for consistency over other twig extensions registration, and removing this service when not using twig.
It isn't a BC break to me, as you usually already use the `TwigBundle` for other extensions.

Commits
-------

3fc80d1 [Workflow] Move twig extension registration to twig bundle
  • Loading branch information
fabpot committed May 8, 2017
2 parents ec92b68 + 3fc80d1 commit f389fa3
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
Expand Up @@ -22,10 +22,5 @@
<service id="workflow.marking_store.single_state" class="Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore" abstract="true" />

<service id="workflow.registry" class="Symfony\Component\Workflow\Registry" />

<service id="workflow.twig_extension" class="Symfony\Bridge\Twig\Extension\WorkflowExtension">
<argument type="service" id="workflow.registry" />
<tag name="twig.extension" />
</service>
</services>
</container>
Expand Up @@ -18,6 +18,7 @@
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
use Symfony\Component\Stopwatch\Stopwatch;
use Symfony\Component\Workflow\Workflow;
use Symfony\Component\Yaml\Parser as YamlParser;

/**
Expand Down Expand Up @@ -115,6 +116,13 @@ public function process(ContainerBuilder $container)
if (class_exists(ExpressionLanguage::class)) {
$container->getDefinition('twig.extension.expression')->addTag('twig.extension');
}

$container->addResource(new ClassExistenceResource(Workflow::class));
if (!class_exists(Workflow::class) || !$container->has('workflow.registry')) {
$container->removeDefinition('workflow.twig_extension');
} else {
$container->getDefinition('workflow.twig_extension')->addTag('twig.extension');
}
}

private function getComposerRootDir($rootDir)
Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Expand Up @@ -106,6 +106,10 @@

<service id="twig.extension.debug" class="Twig_Extension_Debug" public="false" />

<service id="workflow.twig_extension" class="Symfony\Bridge\Twig\Extension\WorkflowExtension">
<argument type="service" id="workflow.registry" />
</service>

<service id="twig.translation.extractor" class="Symfony\Bridge\Twig\Translation\TwigExtractor">
<argument type="service" id="twig" />
<tag name="translation.extractor" alias="twig" />
Expand Down

0 comments on commit f389fa3

Please sign in to comment.