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

Exposes helpers to play with public API objects.
Inheritance: extends Twig_Extensio\Twig_Extension
Show file Open project: ezsystems/ezpublish-kernel

Protected Properties

Property Type Description
$fieldHelper eZ\Publish\Core\Helper\FieldHelper
$logger Psr\Log\LoggerInterface
$repository eZ\Publish\API\Repository\Repository
$translationHelper eZ\Publish\Core\Helper\TranslationHelper

Public Methods

Method Description
__construct ( eZ\Publish\API\Repository\Repository $repository, TranslationHelper $translationHelper, FieldHelper $fieldHelper, Psr\Log\LoggerInterface $logger = null )
getFirstFilledImageFieldIdentifier ( eZ\Publish\API\Repository\Values\Content\Content $content )
getFunctions ( ) : array Returns a list of functions to add to the existing list.
getName ( ) : string Returns the name of the extension.
getTranslatedContentName ( eZ\Publish\API\Repository\Values\ValueObject $content, string $forcedLanguage = null ) : string
getTranslatedField ( eZ\Publish\API\Repository\Values\Content\Content $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : eZ\Publish\API\Repository\Values\Content\Field Returns the translated field, very similar to getTranslatedFieldValue but this returns the whole field.
getTranslatedFieldDefinitionDescription ( eZ\Publish\API\Repository\Values\ValueObject $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : string | null Gets name of a FieldDefinition description by loading ContentType based on Content/ContentInfo object.
getTranslatedFieldDefinitionName ( eZ\Publish\API\Repository\Values\ValueObject $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : string | null Gets name of a FieldDefinition name by loading ContentType based on Content/ContentInfo object.
getTranslatedFieldValue ( eZ\Publish\API\Repository\Values\Content\Content $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : mixed
getTranslatedProperty ( eZ\Publish\API\Repository\Values\ValueObject $object, string $property, string $forcedLanguage = null ) : string | null Gets translated property generic helper.
isFieldEmpty ( eZ\Publish\API\Repository\Values\Content\Content $content, eZ\Publish\API\Repository\Values\Content\Field | string $fieldDefIdentifier, string $forcedLanguage = null ) : boolean Checks if a given field is considered empty.

Private Methods

Method Description
getContentType ( eZ\Publish\API\Repository\Values\ValueObject $content ) : eZ\Publish\API\Repository\Values\ContentType\ContentType | null Get ContentType by Content/ContentInfo.

Method Details

__construct() public method

public __construct ( eZ\Publish\API\Repository\Repository $repository, TranslationHelper $translationHelper, FieldHelper $fieldHelper, Psr\Log\LoggerInterface $logger = null )
$repository eZ\Publish\API\Repository\Repository
$translationHelper eZ\Publish\Core\Helper\TranslationHelper
$fieldHelper eZ\Publish\Core\Helper\FieldHelper
$logger Psr\Log\LoggerInterface

getFirstFilledImageFieldIdentifier() public method

public getFirstFilledImageFieldIdentifier ( eZ\Publish\API\Repository\Values\Content\Content $content )
$content eZ\Publish\API\Repository\Values\Content\Content

getFunctions() public method

Returns a list of functions to add to the existing list.
public getFunctions ( ) : array
return array

getName() public method

Returns the name of the extension.
public getName ( ) : string
return string The extension name

getTranslatedContentName() public method

public getTranslatedContentName ( eZ\Publish\API\Repository\Values\ValueObject $content, string $forcedLanguage = null ) : string
$content eZ\Publish\API\Repository\Values\ValueObject Must be a valid Content or ContentInfo object.
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string

getTranslatedField() public method

To be used with ez_image_alias for example, which requires the whole field.
public getTranslatedField ( eZ\Publish\API\Repository\Values\Content\Content $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : eZ\Publish\API\Repository\Values\Content\Field
$content eZ\Publish\API\Repository\Values\Content\Content
$fieldDefIdentifier string Identifier for the field we want to get.
$forcedLanguage string Locale we want the field in (e.g. "cro-HR"). Null by default (takes current locale).
return eZ\Publish\API\Repository\Values\Content\Field

getTranslatedFieldDefinitionDescription() public method

Gets name of a FieldDefinition description by loading ContentType based on Content/ContentInfo object.
public getTranslatedFieldDefinitionDescription ( eZ\Publish\API\Repository\Values\ValueObject $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : string | null
$content eZ\Publish\API\Repository\Values\ValueObject Must be Content or ContentInfo object
$fieldDefIdentifier string Identifier for the field we want to get the name from
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string | null

getTranslatedFieldDefinitionName() public method

Gets name of a FieldDefinition name by loading ContentType based on Content/ContentInfo object.
public getTranslatedFieldDefinitionName ( eZ\Publish\API\Repository\Values\ValueObject $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : string | null
$content eZ\Publish\API\Repository\Values\ValueObject Must be Content or ContentInfo object
$fieldDefIdentifier string Identifier for the field we want to get the name from
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string | null

getTranslatedFieldValue() public method

public getTranslatedFieldValue ( eZ\Publish\API\Repository\Values\Content\Content $content, string $fieldDefIdentifier, string $forcedLanguage = null ) : mixed
$content eZ\Publish\API\Repository\Values\Content\Content
$fieldDefIdentifier string Identifier for the field we want to get the value from.
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale).
return mixed A primitive type or a field type Value object depending on the field type.

getTranslatedProperty() public method

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.
public getTranslatedProperty ( eZ\Publish\API\Repository\Values\ValueObject $object, string $property, string $forcedLanguage = null ) : string | null
$object eZ\Publish\API\Repository\Values\ValueObject Can be any kid of Value object which directly holds the translated data
$property string Property name, example 'name', 'description'
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale)
return string | null

isFieldEmpty() public method

This method accepts field as Objects or by identifiers.
public isFieldEmpty ( eZ\Publish\API\Repository\Values\Content\Content $content, eZ\Publish\API\Repository\Values\Content\Field | string $fieldDefIdentifier, string $forcedLanguage = null ) : boolean
$content eZ\Publish\API\Repository\Values\Content\Content
$fieldDefIdentifier eZ\Publish\API\Repository\Values\Content\Field | string Field or Field Identifier to get the value from.
$forcedLanguage string Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale).
return boolean

Property Details

$fieldHelper protected property

protected FieldHelper,eZ\Publish\Core\Helper $fieldHelper
return eZ\Publish\Core\Helper\FieldHelper

$logger protected property

protected LoggerInterface,Psr\Log $logger
return Psr\Log\LoggerInterface

$repository protected property

protected Repository,eZ\Publish\API\Repository $repository
return eZ\Publish\API\Repository\Repository

$translationHelper protected property

protected TranslationHelper,eZ\Publish\Core\Helper $translationHelper
return eZ\Publish\Core\Helper\TranslationHelper