Skip to content

Commit

Permalink
IBX-1543: Replaced deprecated twig functions (#29)
Browse files Browse the repository at this point in the history
* IBX-1543: Replaced ez_content_name function

* IBX-1543: Added deprecation for ez_render function

* IBX-1543: Added deprecation for ez_render_*_query function

* IBX-1543: Replaced & deprecate ez_render_field function

* IBX-1543: Replaced ez_field_value function

* IBX-1543: Replaced ez_field function

* IBX-1543: Depreceted ez_field_name function

* IBX-1543: Depreceted ez_field_description function

* IBX-1543: Replaced ez_field_is_empty function

* IBX-1543: Replaced image related twig funtions

* IBX-1543: Replaced URL twig functions

* IBX-1543: Replaced rest of core extensions and filters function

* IBX-1543: Dropped removed `getName` function implementation

* IBX-1543: Replaced global `ezplatform` variable

* IBX-1543: Fixed code style

* IBX-1543: Added deprecation messeges to unit tests
  • Loading branch information
ViniTou authored Dec 2, 2021
1 parent 1c38e41 commit e766878
Show file tree
Hide file tree
Showing 46 changed files with 1,118 additions and 116 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class FieldDefinitionSettingsTemplates extends Templates
{
public const NODE_KEY = 'fielddefinition_settings_templates';
public const INFO = 'Template settings for field definition settings rendered by the ez_render_field_definition_settings() Twig function';
public const INFO = 'Template settings for field definition settings rendered by the ibexa_render_field_definition_settings() Twig function';
public const INFO_TEMPLATE_KEY = 'Template file where to find block definition to display field definition settings';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class FieldTemplates extends Templates
{
public const NODE_KEY = 'field_templates';
public const INFO = 'Template settings for fields rendered by the ez_render_field() Twig function';
public const INFO = 'Template settings for fields rendered by the ibexa_render_field() Twig function';
public const INFO_TEMPLATE_KEY = 'Template file where to find block definition to display fields';
}

Expand Down
40 changes: 20 additions & 20 deletions src/bundle/Core/Resources/views/content_fields.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@

{% block ezdatetime_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
{% if fieldSettings.useSeconds %}
{% set field_value = field.value.value|format_datetime( 'short', 'medium', locale=parameters.locale ) %}
{% else %}
Expand All @@ -79,7 +79,7 @@

{% block ezdate_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
{% set field_value = field.value.date|format_date( 'short', locale=parameters.locale ) %}
{{ block( 'simple_block_field' ) }}
{% endif %}
Expand All @@ -88,7 +88,7 @@

{% block eztime_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
{% if fieldSettings.useSeconds %}
{% set field_value = field.value.time|format_time( 'medium', locale=parameters.locale, timezone='UTC' ) %}
{% else %}
Expand All @@ -101,7 +101,7 @@

{% block ezemail_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
{% set field_value = field.value.email %}
<a href="mailto:{{ field.value.email|escape( 'url' ) }}" {{ block( 'field_attributes' ) }}>{{ field.value.email }}</a>
{% endif %}
Expand All @@ -110,7 +110,7 @@

{% block ezinteger_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
{% set field_value = field.value.value %}
{{ block( 'simple_inline_field' ) }}
{% endif %}
Expand All @@ -120,7 +120,7 @@
{# @todo: handle localization #}
{% block ezfloat_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
{% set field_value = field.value.value %}
{{ block( 'simple_inline_field' ) }}
{% endif %}
Expand All @@ -129,7 +129,7 @@

{% block ezurl_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
<a href="{{ field.value.link }}"
{{ block( 'field_attributes' ) }}>{{ field.value.text ? field.value.text : field.value.link }}</a>
{% endif %}
Expand All @@ -145,7 +145,7 @@

{% block ezkeyword_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
<ul {{ block( 'field_attributes' ) }}>
{% for keyword in field.value.values %}
<li>{{ keyword }}</li>
Expand Down Expand Up @@ -201,30 +201,30 @@

{% block ezbinaryfile_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% set route_reference = ez_route( 'ez_content_download', {
{% if not ibexa_field_is_empty( content, field ) %}
{% set route_reference = ibexa_route( 'ez_content_download', {
'content': content,
'fieldIdentifier': field.fieldDefIdentifier,
'inLanguage': content.prioritizedFieldLanguageCode,
'version': versionInfo.versionNo
} ) %}
<a href="{{ ez_path( route_reference ) }}"
{{ block( 'field_attributes' ) }}>{{ field.value.fileName }}</a>&nbsp;({{ field.value.fileSize|ez_file_size( 1 ) }})
<a href="{{ ibexa_path( route_reference ) }}"
{{ block( 'field_attributes' ) }}>{{ field.value.fileName }}</a>&nbsp;({{ field.value.fileSize|ibexa_file_size( 1 ) }})
{% endif %}
{% endapply %}
{% endblock %}

{% block ezmedia_field %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
{% apply spaceless %}
{% set type = fieldSettings.mediaType %}
{% set value = field.value %}
{% set route_reference = ez_route( 'ez_content_download', {
{% set route_reference = ibexa_route( 'ez_content_download', {
'content': content,
'fieldIdentifier': field.fieldDefIdentifier,
'version': versionInfo.versionNo
} ) %}
{% set download = ez_path( route_reference ) %}
{% set download = ibexa_path( route_reference ) %}
{% set width = value.width > 0 ? 'width="' ~ value.width ~ '"' : "" %}
{% set height = value.height > 0 ? 'height="' ~ value.height ~ '"' : "" %}
<div {{ block( 'field_attributes' ) }}>
Expand Down Expand Up @@ -277,7 +277,7 @@

{% block ezobjectrelationlist_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
<ul {{ block( 'field_attributes' ) }}>
{% for contentId in field.value.destinationContentIds %}
{% if parameters.available[contentId] %}
Expand Down Expand Up @@ -431,9 +431,9 @@
#}
{% block ezimage_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) %}
{% if not ibexa_field_is_empty( content, field ) %}
<figure {{ block( 'field_attributes' ) }}>
{% set imageAlias = ez_image_alias( field, versionInfo, parameters.alias|default( 'original' ) ) %}
{% set imageAlias = ibexa_image_alias( field, versionInfo, parameters.alias|default( 'original' ) ) %}
{% set src = imageAlias ? asset( imageAlias.uri ) : "//:0" %}
{% set attrs = {
class: parameters.class|default(''),
Expand All @@ -458,7 +458,7 @@

{% block ezimageasset_field %}
{% apply spaceless %}
{% if not ez_field_is_empty(content, field) and parameters.available %}
{% if not ibexa_field_is_empty(content, field) and parameters.available %}
<div {{ block('field_attributes') }}>
{{ render(controller('ez_content:embedAction', {
contentId: field.value.destinationContentId,
Expand All @@ -475,7 +475,7 @@

{% block ezobjectrelation_field %}
{% apply spaceless %}
{% if not ez_field_is_empty( content, field ) and parameters.available %}
{% if not ibexa_field_is_empty( content, field ) and parameters.available %}
<div {{ block( 'field_attributes' ) }}>
{{ render( controller( "ez_content:viewAction", {'contentId': field.value.destinationContentId, 'viewType': 'text_linked', 'layout': false} ) ) }}
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set image_field_identifier = ez_content_field_identifier_image_asset() %}
{% set image_field_identifier = ibexa_content_field_identifier_image_asset() %}

{% if image_field_identifier is not null %}
{{ ez_render_field(content, image_field_identifier, {
{{ ibexa_render_field(content, image_field_identifier, {
template: '@IbexaCore/content_fields.html.twig',
parameters: parameters
}) }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{% set content_name=ez_content_name(content) %}
{% set content_name=ibexa_content_name(content) %}

{% if objectParameters.doNotGenerateEmbedUrl is defined and objectParameters.doNotGenerateEmbedUrl %}
<h3>{{ content.name }}</h3>
{% else %}
{% if location is defined %}
<h3><a href="{{ ez_path(location) }}">{{ content_name }}</a></h3>
<h3><a href="{{ ibexa_path(location) }}">{{ content_name }}</a></h3>
{% else %}
<h3><a href="{{ ez_path(content) }}">{{ content_name }}</a></h3>
<h3><a href="{{ ibexa_path(content) }}">{{ content_name }}</a></h3>
{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set image_field_identifier = ez_content_field_identifier_first_filled_image(content) %}
{% set image_field_identifier = ibexa_content_field_identifier_first_filled_image(content) %}

{% if image_field_identifier is not null %}
{{ ez_render_field(
{{ ibexa_render_field(
content,
image_field_identifier,
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{%
set data_attributes_str = (data_attributes is defined)
? ' ' ~ data_attributes|ez_data_attributes_serialize
? ' ' ~ data_attributes|ibexa_data_attributes_serialize
: ''
%}

{% if objectParameters.doNotGenerateEmbedUrl is defined and objectParameters.doNotGenerateEmbedUrl %}
<span {% if class is defined %} class="{{ class }}"{% endif %}{{ data_attributes_str|raw }}>{{ content.name }}</span>
{% else %}
{% if location is defined %}
<a href="{{ ez_path(location) }}"{% if class is defined %} class="{{ class }}"{% endif %}{{ data_attributes_str|raw }}>{{ content.name }}</a>
<a href="{{ ibexa_path(location) }}"{% if class is defined %} class="{{ class }}"{% endif %}{{ data_attributes_str|raw }}>{{ content.name }}</a>
{% else %}
<a href="{{ ez_path(content) }}"{% if class is defined %} class="{{ class }}"{% endif %}{{ data_attributes_str|raw }}>{{ content.name }}</a>
<a href="{{ ibexa_path(content) }}"{% if class is defined %} class="{{ class }}"{% endif %}{{ data_attributes_str|raw }}>{{ content.name }}</a>
{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{% extends no_layout == true ? view_base_layout : page_layout %}
{% block content %}
<h2>{{ ez_content_name(content) }}</h2>
<h2>{{ ibexa_content_name(content) }}</h2>
{% for field in content.fieldsByLanguage(language|default(null)) %}
<h3>{{ field.fieldDefIdentifier }}</h3>
{{ ez_render_field(content, field.fieldDefIdentifier, {location: location|default(null)}) }}
{{ ibexa_render_field(content, field.fieldDefIdentifier, {location: location|default(null)}) }}
{% endfor %}
{% endblock %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set content_name=ez_content_name(content) %}
{% set content_name=ibexa_content_name(content) %}

{% if location is defined %}
<p><a href="{{ ez_path(location) }}">{{ content_name }}</a></p>
<p><a href="{{ ibexa_path(location) }}">{{ content_name }}</a></p>
{% else %}
<p>{{ content_name }}</p>
{% endif %}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% set content_name=ez_content_name(content) %}
{% set content_name=ibexa_content_name(content) %}

{% if location is defined %}
<a href="{{ ez_path(location) }}">{{ content_name }}</a>
<a href="{{ ibexa_path(location) }}">{{ content_name }}</a>
{% else %}
<p>{{ content_name }}</p>
{% endif %}
4 changes: 2 additions & 2 deletions src/bundle/Core/Resources/views/pagelayout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
<head>
<meta charset="utf-8">
{% if content is defined and title is not defined %}
{% set title = ez_content_name( content ) %}
{% set title = ibexa_content_name( content ) %}
{% endif %}
<title>{{ title|default( 'Home' ) }}</title>
<meta name="generator" content="Ibexa DXP"/>
{% if content is defined and content.contentInfo.mainLocationId %}
<link rel="canonical" href="{{ ez_path(content) }}" />
<link rel="canonical" href="{{ ibexa_path(content) }}" />
{% endif %}
</head>
<body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Ibexa\Contracts\Core\Repository\Values\Content\Field;

/**
* Interface for services providing additional parameters to a fieldtype's view template (using ez_render_field() helper).
* Interface for services providing additional parameters to a fieldtype's view template (using ibexa_render_field() helper).
* Each instance of this interface needs to be correctly registered in the ParameterProviderRegistry.
*
* @see \Ibexa\Core\MVC\Symfony\FieldType\View\ParameterProviderRegistryInterface
Expand Down
68 changes: 57 additions & 11 deletions src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,45 +58,91 @@ public function getFunctions()
return [
new TwigFunction(
'ez_content_name',
[$this, 'getTranslatedContentName'],
[
'deprecated' => '4.0',
'alternative' => 'ibexa_content_name',
]
),
new TwigFunction(
'ibexa_content_name',
[$this, 'getTranslatedContentName']
),
new TwigFunction(
'ez_field_value',
[$this, 'getTranslatedFieldValue'],
[
'deprecated' => '4.0',
'alternative' => 'ibexa_field_value',
]
),
new TwigFunction(
'ibexa_field_value',
[$this, 'getTranslatedFieldValue']
),
new TwigFunction(
'ez_field',
[$this, 'getTranslatedField'],
[
'deprecated' => '4.0',
'alternative' => 'ibexa_field',
]
),
new TwigFunction(
'ibexa_field',
[$this, 'getTranslatedField']
),
new TwigFunction(
'ez_field_is_empty',
[$this, 'isFieldEmpty'],
[
'deprecated' => '4.0',
'alternative' => 'ibexa_field_is_empty',
]
),
new TwigFunction(
'ibexa_field_is_empty',
[$this, 'isFieldEmpty']
),
new TwigFunction(
'ez_field_name',
[$this, 'getTranslatedFieldDefinitionName'],
[
'deprecated' => '4.0',
'alternative' => 'ibexa_field_name',
]
),
new TwigFunction(
'ibexa_field_name',
[$this, 'getTranslatedFieldDefinitionName']
),
new TwigFunction(
'ez_field_description',
[$this, 'getTranslatedFieldDefinitionDescription'],
[
'deprecated' => '4.0',
'alternative' => 'ibexa_field_description',
]
),
new TwigFunction(
'ibexa_field_description',
[$this, 'getTranslatedFieldDefinitionDescription']
),
new TwigFunction(
'ez_content_field_identifier_first_filled_image',
[$this, 'getFirstFilledImageFieldIdentifier'],
[
'deprecated' => '4.0',
'alternative' => 'ibexa_content_field_identifier_first_filled_image',
]
),
new TwigFunction(
'ibexa_content_field_identifier_first_filled_image',
[$this, 'getFirstFilledImageFieldIdentifier']
),
];
}

/**
* Returns the name of the extension.
*
* @return string The extension name
*/
public function getName()
{
return 'ezpublish.content';
}

/**
* @param \Ibexa\Contracts\Core\Repository\Values\ValueObject $content Must be a valid Content or ContentInfo object.
* @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
Expand All @@ -122,7 +168,7 @@ public function getTranslatedContentName(ValueObject $content, $forcedLanguage =

/**
* Returns the translated field, very similar to getTranslatedFieldValue but this returns the whole field.
* To be used with ez_image_alias for example, which requires the whole field.
* To be used with ibexa_image_alias for example, which requires the whole field.
*
* @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content
* @param string $fieldDefIdentifier Identifier for the field we want to get.
Expand Down
Loading

0 comments on commit e766878

Please sign in to comment.