Skip to content

Commit 0f92f14

Browse files
committed
Use Shortcode\Processor directly instead of ShortCodeFacade (Case 89286)
1 parent 87d0c4f commit 0f92f14

3 files changed

Lines changed: 26 additions & 16 deletions

File tree

DependencyInjection/Compiler/ShortcodeCompilerPass.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@
77
use Symfony\Component\DependencyInjection\Reference;
88

99
/**
10-
* CompilerPass that prepares the shortcode facade and the GuideController (if configured).
10+
* CompilerPass that prepares the shortcode handler container and the GuideController (if configured).
1111
*/
1212
class ShortcodeCompilerPass implements CompilerPassInterface
1313
{
1414
public function process(ContainerBuilder $container)
1515
{
1616
$shortcodeServices = $container->findTaggedServiceIds('webfactory.shortcode');
1717

18-
// add services tagged with webfactory.shortcode.facade as handlers to the short code facade
19-
$serviceDefinition = $container->findDefinition('webfactory.shortcode.facade');
18+
// add services tagged with webfactory.shortcode as handlers to the short code handler container
19+
$handlerContainer = $container->findDefinition('webfactory.shortcode.handler_container');
2020
foreach ($shortcodeServices as $id => $shortcodeTags) {
2121
foreach ($shortcodeTags as $shortcodeTag) {
22-
$serviceDefinition->addMethodCall('addHandler', [$shortcodeTag['shortcode'], new Reference($id)]);
22+
$handlerContainer->addMethodCall('add', [$shortcodeTag['shortcode'], new Reference($id)]);
2323
}
2424
}
2525

Resources/config/shortcodes.xml

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,27 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66
<services>
77

8-
<!-- Definition of a ShortcodeFacade instance. -->
9-
<service id="webfactory.shortcode.facade" class="Thunder\Shortcode\ShortcodeFacade">
8+
<!-- Definition of a Shortcode HandlerContainer instance. -->
9+
<service id="webfactory.shortcode.handler_container" class="Thunder\Shortcode\HandlerContainer\HandlerContainer">
1010
<!-- Event handler that removes <p>...</p> tag that directly wrap shortcodes. -->
11-
<call method="addEventHandler">
11+
<call method="add">
1212
<argument type="constant">\Thunder\Shortcode\Events::REPLACE_SHORTCODES</argument>
1313
<argument type="service">
1414
<service class="Webfactory\ShortcodeBundle\Handler\RemoveWrappingParagraphElementsEventHandler"/>
1515
</argument>
1616
</call>
1717
</service>
1818

19+
<!-- Definition of a Shortcode RegularParser instance. -->
20+
<service id="webfactory.shortcode.regular_parser" class="Thunder\Shortcode\Parser\RegularParser">
21+
</service>
22+
23+
<!-- Definition of a Shortcode Processor instance. -->
24+
<service id="webfactory.shortcode.processor" class="Thunder\Shortcode\Processor\Processor">
25+
<argument type="service" id="webfactory.shortcode.regular_parser" />
26+
<argument type="service" id="webfactory.shortcode.handler_container" />
27+
</service>
28+
1929
<!-- Base definition for the EmbedForShortcodeHandler with esi renderer. -->
2030
<service abstract="true" id="webfactory.shortcode.embed_esi_for_shortcode_handler" class="Webfactory\ShortcodeBundle\Handler\EmbeddedShortcodeHandler" lazy="true">
2131
<argument type="service" id="fragment.handler"/>
@@ -34,9 +44,9 @@
3444
<argument type="service" id="logger" on-invalid="null" />
3545
</service>
3646

37-
<!-- Twig extension providing the |shortcodes filter. The content will be passed to the ShortcodeFacade. -->
47+
<!-- Twig extension providing the |shortcodes filter. The content will be passed to the Shortcode Processor. -->
3848
<service id="Webfactory\ShortcodeBundle\Twig\ShortcodeExtension" class="Webfactory\ShortcodeBundle\Twig\ShortcodeExtension">
39-
<argument type="service" id="webfactory.shortcode.facade"/>
49+
<argument type="service" id="webfactory.shortcode.processor"/>
4050
<tag name="twig.extension"/>
4151
</service>
4252

Twig/ShortcodeExtension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
namespace Webfactory\ShortcodeBundle\Twig;
44

5-
use Thunder\Shortcode\ShortcodeFacade;
5+
use Thunder\Shortcode\Processor\Processor;
66
use Twig\Extension\AbstractExtension;
77
use Twig\TwigFilter;
88

@@ -11,15 +11,15 @@
1111
*/
1212
final class ShortcodeExtension extends AbstractExtension
1313
{
14-
/** @var ShortcodeFacade */
15-
private $facade;
14+
/** @var Processor */
15+
private $processor;
1616

1717
/**
18-
* @param ShortcodeFacade $facade
18+
* @param Processor $processor
1919
*/
20-
public function __construct(ShortcodeFacade $facade)
20+
public function __construct(Processor $processor)
2121
{
22-
$this->facade = $facade;
22+
$this->processor = $processor;
2323
}
2424

2525
public function getFilters()
@@ -36,6 +36,6 @@ public function getFilters()
3636
*/
3737
public function processShortcodes($content)
3838
{
39-
return $this->facade->process($content);
39+
return $this->processor->process($content);
4040
}
4141
}

0 commit comments

Comments
 (0)