Skip to content

Commit

Permalink
Merge 8bc4432 into 41592c3
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Dec 2, 2017
2 parents 41592c3 + 8bc4432 commit 49123a1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"symfony/twig-bridge": "^2.8 || ^3.2 || ^4.0",
"symfony/validator": "^2.8 || ^3.2 || ^4.0",
"twig/extensions": "^1.0",
"twig/twig": "^1.28 || ^2.0"
"twig/twig": "^1.34 || ^2.0"
},
"require-dev": {
"jms/di-extra-bundle": "^1.7",
Expand Down
35 changes: 20 additions & 15 deletions src/Twig/Extension/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,16 @@
use Sonata\AdminBundle\Admin\Pool;
use Sonata\AdminBundle\Exception\NoValueException;
use Symfony\Component\Translation\TranslatorInterface;
use Twig\Environment;
use Twig\Error\LoaderError;
use Twig\Extension\AbstractExtension;
use Twig\Template;
use Twig\TwigFilter;

/**
* @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
*/
class SonataAdminExtension extends \Twig_Extension
class SonataAdminExtension extends AbstractExtension
{
/**
* @var Pool
Expand Down Expand Up @@ -69,43 +74,43 @@ public function __construct(Pool $pool, LoggerInterface $logger = null, Translat
public function getFilters()
{
return [
new \Twig_SimpleFilter(
new TwigFilter(
'render_list_element',
[$this, 'renderListElement'],
[
'is_safe' => ['html'],
'needs_environment' => true,
]
),
new \Twig_SimpleFilter(
new TwigFilter(
'render_view_element',
[$this, 'renderViewElement'],
[
'is_safe' => ['html'],
'needs_environment' => true,
]
),
new \Twig_SimpleFilter(
new TwigFilter(
'render_view_element_compare',
[$this, 'renderViewElementCompare'],
[
'is_safe' => ['html'],
'needs_environment' => true,
]
),
new \Twig_SimpleFilter(
new TwigFilter(
'render_relation_element',
[$this, 'renderRelationElement']
),
new \Twig_SimpleFilter(
new TwigFilter(
'sonata_urlsafeid',
[$this, 'getUrlsafeIdentifier']
),
new \Twig_SimpleFilter(
new TwigFilter(
'sonata_xeditable_type',
[$this, 'getXEditableType']
),
new \Twig_SimpleFilter(
new TwigFilter(
'sonata_xeditable_choices',
[$this, 'getXEditableChoices']
),
Expand All @@ -130,7 +135,7 @@ public function getName()
* @return string
*/
public function renderListElement(
\Twig_Environment $environment,
Environment $environment,
$object,
FieldDescriptionInterface $fieldDescription,
$params = []
Expand Down Expand Up @@ -158,9 +163,9 @@ public function renderListElement(
*/
public function output(
FieldDescriptionInterface $fieldDescription,
\Twig_Template $template,
Template $template,
array $parameters,
\Twig_Environment $environment
Environment $environment
) {
$content = $template->render($parameters);

Expand Down Expand Up @@ -232,7 +237,7 @@ public function getValueFromFieldDescription(
* @return string
*/
public function renderViewElement(
\Twig_Environment $environment,
Environment $environment,
FieldDescriptionInterface $fieldDescription,
$object
) {
Expand Down Expand Up @@ -266,7 +271,7 @@ public function renderViewElement(
* @return string
*/
public function renderViewElementCompare(
\Twig_Environment $environment,
Environment $environment,
FieldDescriptionInterface $fieldDescription,
$baseObject,
$compareObject
Expand Down Expand Up @@ -453,13 +458,13 @@ public function getXEditableChoices(FieldDescriptionInterface $fieldDescription)
protected function getTemplate(
FieldDescriptionInterface $fieldDescription,
$defaultTemplate,
\Twig_Environment $environment
Environment $environment
) {
$templateName = $fieldDescription->getTemplate() ?: $defaultTemplate;

try {
$template = $environment->loadTemplate($templateName);
} catch (\Twig_Error_Loader $e) {
} catch (LoaderError $e) {
@trigger_error(
'Relying on default template loading on field template loading exception '.
'is deprecated since 3.1 and will be removed in 4.0. '.
Expand Down

0 comments on commit 49123a1

Please sign in to comment.