Class

eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension\ContentExtension

class ContentExtension extends Twig_Extension

Twig content extension for eZ Publish specific usage.

Exposes helpers to play with public API objects.

Methods

__construct(Repository $repository, TranslationHelper $translationHelper, FieldHelper $fieldHelper, LoggerInterface $logger = null)

array getFunctions()

Returns a list of functions to add to the existing list.

string getName()

Returns the name of the extension.

string getTranslatedContentName(ValueObject $content, string $forcedLanguage = null)

Field getTranslatedField(Content $content, string $fieldDefIdentifier, string $forcedLanguage = null)

Returns the translated field, very similar to getTranslatedFieldValue but this returns the whole field.

mixed getTranslatedFieldValue(Content $content, string $fieldDefIdentifier, string $forcedLanguage = null)

string|null getTranslatedFieldDefinitionName(ValueObject $content, string $fieldDefIdentifier, string $forcedLanguage = null)

Gets name of a FieldDefinition name by loading ContentType based on Content/ContentInfo object.

string|null getTranslatedFieldDefinitionDescription(ValueObject $content, string $fieldDefIdentifier, string $forcedLanguage = null)

Gets name of a FieldDefinition description by loading ContentType based on Content/ContentInfo object.

string|null getTranslatedProperty(ValueObject $object, string $property, string $forcedLanguage = null)

Gets translated property generic helper.

bool isFieldEmpty(Content $content, Field|string $fieldDefIdentifier, string $forcedLanguage = null)

Checks if a given field is considered empty.

getFirstFilledImageFieldIdentifier(Content $content)

Details

at line 50
public __construct(Repository $repository, TranslationHelper $translationHelper, FieldHelper $fieldHelper, LoggerInterface $logger = null)

Parameters

Repository $repository
TranslationHelper $translationHelper
FieldHelper $fieldHelper
LoggerInterface $logger

at line 67
public array getFunctions()

Returns a list of functions to add to the existing list.

Return Value

array

at line 110
public string getName()

Returns the name of the extension.

Return Value

string The extension name

at line 123
public string getTranslatedContentName(ValueObject $content, string $forcedLanguage = null)

Parameters

ValueObject $content Must be a valid Content or ContentInfo object.
string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Return Value

string

Exceptions

InvalidArgumentType When $content is not a valid Content or ContentInfo object.

at line 144
public Field getTranslatedField(Content $content, string $fieldDefIdentifier, string $forcedLanguage = null)

Returns the translated field, very similar to getTranslatedFieldValue but this returns the whole field.

To be used with ezimagealias for example, which requires the whole field.

Parameters

Content $content
string $fieldDefIdentifier Identifier for the field we want to get.
string $forcedLanguage Locale we want the field in (e.g. "cro-HR"). Null by default (takes current locale).

Return Value

Field

at line 156
public mixed getTranslatedFieldValue(Content $content, string $fieldDefIdentifier, string $forcedLanguage = null)

Parameters

Content $content
string $fieldDefIdentifier Identifier for the field we want to get the value from.
string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale).

Return Value

mixed A primitive type or a field type Value object depending on the field type.

at line 172
public string|null getTranslatedFieldDefinitionName(ValueObject $content, string $fieldDefIdentifier, string $forcedLanguage = null)

Gets name of a FieldDefinition name by loading ContentType based on Content/ContentInfo object.

Parameters

ValueObject $content Must be Content or ContentInfo object
string $fieldDefIdentifier Identifier for the field we want to get the name from
string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Return Value

string|null

Exceptions

InvalidArgumentType When $content is not a valid Content object.

at line 197
public string|null getTranslatedFieldDefinitionDescription(ValueObject $content, string $fieldDefIdentifier, string $forcedLanguage = null)

Gets name of a FieldDefinition description by loading ContentType based on Content/ContentInfo object.

Parameters

ValueObject $content Must be Content or ContentInfo object
string $fieldDefIdentifier Identifier for the field we want to get the name from
string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Return Value

string|null

Exceptions

InvalidArgumentType When $content is not a valid Content object.

at line 229
public string|null getTranslatedProperty(ValueObject $object, string $property, string $forcedLanguage = null)

Gets translated property generic helper.

For generic use, expects property in singular form. For instance if 'name' is provided it will first look for getName( $lang ) method, then property called ->names[$lang], in either case look for correct translation.

Languages will consist of either forced language or current SiteAccess languages list, in addition for property lookup helper will look for mainLanguage property and use it if either alwaysAvailable property is true or non- existing.

Parameters

ValueObject $object Can be any kid of Value object which directly holds the translated data
string $property Property name, example 'name', 'description'
string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)

Return Value

string|null

Exceptions

InvalidArgumentValue If $property does not exists as plural or as method

at line 261
public bool isFieldEmpty(Content $content, Field|string $fieldDefIdentifier, string $forcedLanguage = null)

Checks if a given field is considered empty.

This method accepts field as Objects or by identifiers.

Parameters

Content $content
Field|string $fieldDefIdentifier Field or Field Identifier to get the value from.
string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale).

Return Value

bool

at line 288
public getFirstFilledImageFieldIdentifier(Content $content)

Parameters

Content $content