Skip to content

Commit

Permalink
Merge pull request sonata-project#3193 from Koc/twig-deprecations
Browse files Browse the repository at this point in the history
Remove usage of deprecated Twig stuff
  • Loading branch information
soullivaneuh committed Aug 26, 2015
2 parents e4c515e + 9a05d8e commit 8ce1a1b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 27 deletions.
2 changes: 1 addition & 1 deletion Resources/views/CRUD/base_list.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ file that was distributed with this source code.
<div class="filter_container {{ admin.datagrid.hasActiveFilters ? 'active' : 'inactive' }}">
{% for filter in admin.datagrid.filters %}
<div class="form-group">
{% if filter.label is not sameas(false) %}
{% if filter.label is not same as(false) %}
<label for="{{ form.children[filter.formName].children['value'].vars.id }}">{{ admin.trans(filter.label, {}, filter.translationDomain) }}</label>
{% endif %}
{% set attr = form.children[filter.formName].children['type'].vars.attr|default({}) %}
Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Core/search.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ file that was distributed with this source code.

<h1>{{ 'title_search_results'|trans({'%query%': query}, 'SonataAdminBundle') }}</h1>

{% if query is defined and query is not sameas(false) %}
{% if query is defined and query is not same as(false) %}
{% set count = 0 %}
<div class="row">

Expand Down
2 changes: 1 addition & 1 deletion Resources/views/Form/filter_admin_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ file that was distributed with this source code.

{% block checkbox_widget %}
{% spaceless %}
{% if label is not sameas(false) and label is empty %}
{% if label is not same as(false) and label is empty %}
{% set label = name|humanize %}
{% endif %}
{% if form.parent != null and 'choice' not in form.parent.vars.block_prefixes %}
Expand Down
6 changes: 3 additions & 3 deletions Resources/views/Form/form_admin_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ file that was distributed with this source code.
{% endif%}

{#{{ sonata_admin.admin.getConfigurationPool().getOption('form_type') }}#}
{% if label is not sameas(false) %}
{% if label is not same as(false) %}
{% set label_attr = label_attr|merge({'class': label_attr.class|default('') ~ label_class }) %}

{% if not compound %}
Expand Down Expand Up @@ -153,7 +153,7 @@ file that was distributed with this source code.
{% if sonata_admin is not defined or not sonata_admin_enabled or not sonata_admin.field_description %}
<div class="form-group {% if errors|length > 0%} has-error{% endif %}">
{{ form_label(form, label|default(null)) }}
<div class="{% if label is sameas(false) %}sonata-collection-row-without-label{% endif %}">
<div class="{% if label is same as(false) %}sonata-collection-row-without-label{% endif %}">
{{ form_widget(form, {'horizontal': false, 'horizontal_input_wrapper_class': ''}) }} {# {'horizontal': false, 'horizontal_input_wrapper_class': ''} needed to avoid MopaBootstrapBundle messing with the DOM #}
{% if errors|length > 0 %}
<div class="help-block sonata-ba-field-error-messages">
Expand All @@ -172,7 +172,7 @@ file that was distributed with this source code.
{% endif %}
{% endblock %}

{% set has_label = sonata_admin.field_description.options.name is defined or label is not sameas(false) %}
{% set has_label = sonata_admin.field_description.options.name is defined or label is not same as(false) %}
<div class="{{ div_class }} sonata-ba-field sonata-ba-field-{{ sonata_admin.edit }}-{{ sonata_admin.inline }} {% if errors|length > 0 %}sonata-ba-field-error{% endif %} {% if not has_label %}sonata-collection-row-without-label{% endif %}">

{{ form_widget(form, {'horizontal': false, 'horizontal_input_wrapper_class': ''}) }} {# {'horizontal': false, 'horizontal_input_wrapper_class': ''} needed to avoid MopaBootstrapBundle messing with the DOM #}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Twig/Extension/SonataAdminExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SonataAdminExtensionTest extends \PHPUnit_Framework_TestCase
private $twigExtension;

/**
* @var Twig_Environment
* @var \Twig_Environment
*/
private $environment;

Expand Down
30 changes: 10 additions & 20 deletions Twig/Extension/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,15 @@ public function initRuntime(\Twig_Environment $environment)
public function getFilters()
{
return array(
'render_list_element' => new \Twig_Filter_Method($this, 'renderListElement', array('is_safe' => array('html'))),
'render_view_element' => new \Twig_Filter_Method($this, 'renderViewElement', array('is_safe' => array('html'))),
'render_view_element_compare' => new \Twig_Filter_Method($this, 'renderViewElementCompare', array('is_safe' => array('html'))),
'render_relation_element' => new \Twig_Filter_Method($this, 'renderRelationElement'),
'sonata_urlsafeid' => new \Twig_Filter_Method($this, 'getUrlsafeIdentifier'),
'sonata_xeditable_type' => new \Twig_Filter_Method($this, 'getXEditableType'),
new \Twig_SimpleFilter('render_list_element', array($this, 'renderListElement'), array('is_safe' => array('html'))),
new \Twig_SimpleFilter('render_view_element', array($this, 'renderViewElement'), array('is_safe' => array('html'))),
new \Twig_SimpleFilter('render_view_element_compare', array($this, 'renderViewElementCompare'), array('is_safe' => array('html'))),
new \Twig_SimpleFilter('render_relation_element', array($this, 'renderRelationElement')),
new \Twig_SimpleFilter('sonata_urlsafeid', array($this, 'getUrlsafeIdentifier')),
new \Twig_SimpleFilter('sonata_xeditable_type', array($this, 'getXEditableType')),
);
}

/**
* {@inheritdoc}
*/
public function getTokenParsers()
{
return array();
}

/**
* {@inheritdoc}
*/
Expand All @@ -90,7 +82,7 @@ public function getName()
* @param FieldDescriptionInterface $fieldDescription
* @param string $defaultTemplate
*
* @return \Twig_TemplateInterface
* @return \Twig_Template
*/
protected function getTemplate(FieldDescriptionInterface $fieldDescription, $defaultTemplate)
{
Expand Down Expand Up @@ -132,12 +124,12 @@ public function renderListElement($object, FieldDescriptionInterface $fieldDescr

/**
* @param FieldDescriptionInterface $fieldDescription
* @param \Twig_TemplateInterface $template
* @param \Twig_Template $template
* @param array $parameters
*
* @return string
*/
public function output(FieldDescriptionInterface $fieldDescription, \Twig_TemplateInterface $template, array $parameters = array())
public function output(FieldDescriptionInterface $fieldDescription, \Twig_Template $template, array $parameters = array())
{
$content = $template->render($parameters);

Expand Down Expand Up @@ -303,9 +295,7 @@ public function renderRelationElement($element, FieldDescriptionInterface $field
*/
public function getUrlsafeIdentifier($model)
{
$admin = $this->pool->getAdminByClass(
ClassUtils::getClass($model)
);
$admin = $this->pool->getAdminByClass(ClassUtils::getClass($model));

return $admin->getUrlsafeIdentifier($model);
}
Expand Down

0 comments on commit 8ce1a1b

Please sign in to comment.