Skip to content

Commit 782ac8d

Browse files
thewilkybarkidfabpot
authored andcommitted
[TwigBundle][DX] Only add the Twig WebLinkExtension if the WebLink component is enabled
1 parent 03fd0a9 commit 782ac8d

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

UndefinedCallableHandler.php

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\Twig;
1313

14+
use Symfony\Bundle\FullStack;
1415
use Twig\Error\SyntaxError;
1516

1617
/**
@@ -55,14 +56,21 @@ class UndefinedCallableHandler
5556
'workflow_marked_places' => 'workflow',
5657
);
5758

59+
private static $fullStackEnable = array(
60+
'form' => 'enable "framework.form"',
61+
'security-core' => 'add the "SecurityBundle"',
62+
'security-http' => 'add the "SecurityBundle"',
63+
'web-link' => 'enable "framework.web_link"',
64+
'workflow' => 'enable "framework.workflows"',
65+
);
66+
5867
public static function onUndefinedFilter($name)
5968
{
6069
if (!isset(self::$filterComponents[$name])) {
6170
return false;
6271
}
6372

64-
// Twig will append the source context to the message, so that it will end up being like "[...] Unknown filter "%s" in foo.html.twig on line 123."
65-
throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown filter "%s".', self::$filterComponents[$name], $name));
73+
self::onUndefined($name, 'filter', self::$filterComponents[$name]);
6674
}
6775

6876
public static function onUndefinedFunction($name)
@@ -71,6 +79,15 @@ public static function onUndefinedFunction($name)
7179
return false;
7280
}
7381

74-
throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown function "%s".', self::$functionComponents[$name], $name));
82+
self::onUndefined($name, 'function', self::$functionComponents[$name]);
83+
}
84+
85+
private static function onUndefined($name, $type, $component)
86+
{
87+
if (\class_exists(FullStack::class) && isset(self::$fullStackEnable[$component])) {
88+
throw new SyntaxError(sprintf('Did you forget to %s? Unknown %s "%s".', self::$fullStackEnable[$component], $type, $name));
89+
}
90+
91+
throw new SyntaxError(sprintf('Did you forget to run "composer require symfony/%s"? Unknown %s "%s".', $component, $type, $name));
7592
}
7693
}

0 commit comments

Comments
 (0)