diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php index 578208acf0..99ff3b13a5 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php @@ -8,6 +8,7 @@ use Ibexa\Contracts\Core\Repository\Repository; use Ibexa\Contracts\Core\Repository\Values\Content\Content; +use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface; use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; use Ibexa\Contracts\Core\Repository\Values\Content\Field; use Ibexa\Contracts\Core\Repository\Values\ValueObject; @@ -137,15 +138,16 @@ public function getFunctions(): array } /** - * @param \Ibexa\Contracts\Core\Repository\Values\ValueObject $content Must be a valid Content or ContentInfo object. + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data Must be a valid Content, ContentInfo, or ContentAwareInterface object. * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType When $content is not a valid Content or ContentInfo object. + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType When $content is not a valid Content, ContentInfo, or ContentAwareInterface object. * * @return string */ - public function getTranslatedContentName(ValueObject $content, $forcedLanguage = null) + public function getTranslatedContentName(object $data, $forcedLanguage = null) { + $content = $this->resolveData($data); if ($content instanceof Content) { return $this->translationHelper->getTranslatedContentName($content, $forcedLanguage); } elseif ($content instanceof ContentInfo) { @@ -153,9 +155,9 @@ public function getTranslatedContentName(ValueObject $content, $forcedLanguage = } throw new InvalidArgumentType( - '$content', - sprintf('%s or %s', Content::class, ContentInfo::class), - $content + '$data', + sprintf('%s or %s or %s', Content::class, ContentInfo::class, ContentAwareInterface::class), + $data ); } @@ -163,43 +165,43 @@ public function getTranslatedContentName(ValueObject $content, $forcedLanguage = * Returns the translated field, very similar to getTranslatedFieldValue but this returns 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 \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data * @param string $fieldDefIdentifier Identifier for the field we want to get. * @param string $forcedLanguage Locale we want the field in (e.g. "cro-HR"). Null by default (takes current locale). * * @return \Ibexa\Contracts\Core\Repository\Values\Content\Field */ - public function getTranslatedField(Content $content, $fieldDefIdentifier, $forcedLanguage = null) + public function getTranslatedField(object $data, $fieldDefIdentifier, $forcedLanguage = null) { - return $this->translationHelper->getTranslatedField($content, $fieldDefIdentifier, $forcedLanguage); + return $this->translationHelper->getTranslatedField($this->getContent($data), $fieldDefIdentifier, $forcedLanguage); } /** - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data * @param string $fieldDefIdentifier Identifier for the field we want to get the value from. * @param string $forcedLanguage 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. */ - public function getTranslatedFieldValue(Content $content, $fieldDefIdentifier, $forcedLanguage = null) + public function getTranslatedFieldValue(object $data, $fieldDefIdentifier, $forcedLanguage = null) { - return $this->translationHelper->getTranslatedField($content, $fieldDefIdentifier, $forcedLanguage)->value; + return $this->translationHelper->getTranslatedField($this->getContent($data), $fieldDefIdentifier, $forcedLanguage)->value; } /** - * Gets name of a FieldDefinition name by loading ContentType based on Content/ContentInfo object. + * Gets name of a FieldDefinition name by loading ContentType based on Content/ContentInfo/ContentAwareInterface object. * - * @param \Ibexa\Contracts\Core\Repository\Values\ValueObject $content Must be Content or ContentInfo object + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data Must be Content, ContentInfo, or ContentAwareInterface object * @param string $fieldDefIdentifier Identifier for the field we want to get the name from * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType When $content is not a valid Content object. + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType When $content is not a valid Content, ContentInfo, or ContentAwareInterface object. * * @return string|null */ - public function getTranslatedFieldDefinitionName(ValueObject $content, $fieldDefIdentifier, $forcedLanguage = null) + public function getTranslatedFieldDefinitionName(object $data, $fieldDefIdentifier, $forcedLanguage = null) { - if ($contentType = $this->getContentType($content)) { + if ($contentType = $this->getContentType($this->resolveData($data))) { return $this->translationHelper->getTranslatedFieldDefinitionProperty( $contentType, $fieldDefIdentifier, @@ -208,23 +210,25 @@ public function getTranslatedFieldDefinitionName(ValueObject $content, $fieldDef ); } - throw new InvalidArgumentType('$content', 'Content|ContentInfo', $content); + throw new InvalidArgumentType( + '$data', + sprintf('%s or %s or %s', Content::class, ContentInfo::class, ContentAwareInterface::class), + $data + ); } /** - * Gets name of a FieldDefinition description by loading ContentType based on Content/ContentInfo object. + * Gets name of a FieldDefinition description by loading ContentType based on Content/ContentInfo/ContentAwareInterface object. * - * @param \Ibexa\Contracts\Core\Repository\Values\ValueObject $content Must be Content or ContentInfo object + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data Must be Content, ContentInfo, or ContentAwareInterface object * @param string $fieldDefIdentifier Identifier for the field we want to get the name from * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). Null by default (takes current locale) * - * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType When $content is not a valid Content object. - * * @return string|null */ - public function getTranslatedFieldDefinitionDescription(ValueObject $content, $fieldDefIdentifier, $forcedLanguage = null) + public function getTranslatedFieldDefinitionDescription(object $data, $fieldDefIdentifier, $forcedLanguage = null) { - if ($contentType = $this->getContentType($content)) { + if ($contentType = $this->getContentType($this->resolveData($data))) { return $this->translationHelper->getTranslatedFieldDefinitionProperty( $contentType, $fieldDefIdentifier, @@ -233,11 +237,20 @@ public function getTranslatedFieldDefinitionDescription(ValueObject $content, $f ); } - throw new InvalidArgumentType('$content', 'Content|ContentInfo', $content); + throw new InvalidArgumentType( + '$data', + sprintf('%s or %s or %s', Content::class, ContentInfo::class, ContentAwareInterface::class), + $data + ); } - public function hasField(Content $content, string $fieldDefIdentifier): bool + /** + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data + */ + public function hasField(object $data, string $fieldDefIdentifier): bool { + $content = $this->getContent($data); + return $content->getContentType()->hasFieldDefinition($fieldDefIdentifier); } @@ -250,7 +263,7 @@ public function getFieldGroupName(string $identifier): ?string * Checks if a given field is considered empty. * This method accepts field as Objects or by identifiers. * - * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content $content + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data * @param \Ibexa\Contracts\Core\Repository\Values\Content\Field|string $fieldDefIdentifier Field or Field Identifier to * get the value from. * @param string $forcedLanguage Locale we want the content name translation in (e.g. "fre-FR"). @@ -258,13 +271,13 @@ public function getFieldGroupName(string $identifier): ?string * * @return bool */ - public function isFieldEmpty(Content $content, $fieldDefIdentifier, $forcedLanguage = null) + public function isFieldEmpty(object $data, $fieldDefIdentifier, $forcedLanguage = null) { if ($fieldDefIdentifier instanceof Field) { $fieldDefIdentifier = $fieldDefIdentifier->fieldDefIdentifier; } - return $this->fieldHelper->isFieldEmpty($content, $fieldDefIdentifier, $forcedLanguage); + return $this->fieldHelper->isFieldEmpty($this->getContent($data), $fieldDefIdentifier, $forcedLanguage); } /** @@ -285,8 +298,12 @@ private function getContentType(ValueObject $content) } } - public function getFirstFilledImageFieldIdentifier(Content $content) + /** + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data + */ + public function getFirstFilledImageFieldIdentifier(object $data) { + $content = $this->getContent($data); foreach ($content->getFieldsByLanguage() as $field) { $fieldTypeIdentifier = $content->getContentType() ->getFieldDefinition($field->fieldDefIdentifier) @@ -305,6 +322,50 @@ public function getFirstFilledImageFieldIdentifier(Content $content) return null; } + + /** + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data + * + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType + */ + private function resolveData(object $data): ValueObject + { + if ($data instanceof Content || $data instanceof ContentInfo) { + return $data; + } + + if ($data instanceof ContentAwareInterface) { + return $data->getContent(); + } + + throw new InvalidArgumentType( + '$content', + sprintf('%s or %s or %s', Content::class, ContentInfo::class, ContentAwareInterface::class), + $data, + ); + } + + /** + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data + * + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType + */ + private function getContent(object $data): Content + { + if ($data instanceof Content) { + return $data; + } + + if ($data instanceof ContentAwareInterface) { + return $data->getContent(); + } + + throw new InvalidArgumentType( + '$content', + sprintf('%s or %s', Content::class, ContentAwareInterface::class), + $data, + ); + } } class_alias(ContentExtension::class, 'eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension\ContentExtension'); diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php index 8a5767b3cb..a5b41bf533 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php @@ -7,9 +7,11 @@ namespace Ibexa\Core\MVC\Symfony\Templating\Twig\Extension; use Ibexa\Contracts\Core\Repository\Values\Content\Content; +use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface; use Ibexa\Contracts\Core\Repository\Values\Content\Field; use Ibexa\Contracts\Core\Repository\Values\ContentType\FieldDefinition; use Ibexa\Core\Base\Exceptions\InvalidArgumentException; +use Ibexa\Core\Base\Exceptions\InvalidArgumentType; use Ibexa\Core\Helper\TranslationHelper; use Ibexa\Core\MVC\Symfony\FieldType\View\ParameterProviderRegistryInterface; use Ibexa\Core\MVC\Symfony\Templating\FieldBlockRendererInterface; @@ -52,17 +54,22 @@ public function __construct( public function getFunctions() { - $renderFieldCallable = function (Environment $environment, Content $content, $fieldIdentifier, array $params = []) { + $renderFieldCallable = function (Environment $environment, $data, $fieldIdentifier, array $params = []) { $this->fieldBlockRenderer->setTwig($environment); - return $this->renderField($content, $fieldIdentifier, $params); + return $this->renderField($this->getContent($data), $fieldIdentifier, $params); }; - $renderFieldDefinitionSettingsCallable = function (Environment $environment, FieldDefinition $fieldDefinition, array $params = []) { - $this->fieldBlockRenderer->setTwig($environment); + $renderFieldDefinitionSettingsCallable = + function ( + Environment $environment, + FieldDefinition $fieldDefinition, + array $params = [] + ) { + $this->fieldBlockRenderer->setTwig($environment); - return $this->renderFieldDefinitionSettings($fieldDefinition, $params); - }; + return $this->renderFieldDefinitionSettings($fieldDefinition, $params); + }; return [ new TwigFunction( @@ -210,6 +217,27 @@ private function getFieldTypeIdentifier(Content $content, Field $field) return $this->fieldTypeIdentifiers[$key]; } + + /** + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $content + * + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType + */ + private function getContent(object $content): Content + { + if ($content instanceof Content) { + return $content; + } + if ($content instanceof ContentAwareInterface) { + return $content->getContent(); + } + + throw new InvalidArgumentType( + '$content', + sprintf('%s or %s', Content::class, ContentAwareInterface::class), + $content, + ); + } } class_alias(FieldRenderingExtension::class, 'eZ\Publish\Core\MVC\Symfony\Templating\Twig\Extension\FieldRenderingExtension'); diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php index 29143878bb..0b3d982937 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php @@ -9,6 +9,8 @@ namespace Ibexa\Core\MVC\Symfony\Templating\Twig\Extension; use Ibexa\Contracts\Core\Repository\Values\Content\Content; +use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface; +use Ibexa\Core\Base\Exceptions\InvalidArgumentType; use Ibexa\Core\MVC\Symfony\Event\ResolveRenderOptionsEvent; use Ibexa\Core\MVC\Symfony\Templating\RenderContentStrategy; use Ibexa\Core\MVC\Symfony\Templating\RenderOptions; @@ -58,14 +60,39 @@ public function getFunctions(): array ]; } - public function renderContent(Content $content, array $options = []): string + /** + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data + */ + public function renderContent(object $data, array $options = []): string { $renderOptions = new RenderOptions($options); $event = $this->eventDispatcher->dispatch( new ResolveRenderOptionsEvent($renderOptions) ); - return $this->renderContentStrategy->render($content, $event->getRenderOptions()); + return $this->renderContentStrategy->render($this->getContent($data), $event->getRenderOptions()); + } + + /** + * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data + * + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType + */ + private function getContent(object $data): Content + { + if ($data instanceof Content) { + return $data; + } + + if ($data instanceof ContentAwareInterface) { + return $data->getContent(); + } + + throw new InvalidArgumentType( + '$content', + sprintf('%s or %s', Content::class, ContentAwareInterface::class), + $data, + ); } } diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php b/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php index 7696b0ab8d..3c9e394804 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php @@ -9,6 +9,7 @@ use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\ContentTypeService; use Ibexa\Contracts\Core\Repository\Repository; +use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface; use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; use Ibexa\Contracts\Core\Repository\Values\Content\Field; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; @@ -126,6 +127,20 @@ protected function getContent(string $contentTypeIdentifier, array $fieldsData, return $content; } + /** + * @param array $fieldsData + * @param array $namesData + */ + protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): ContentAwareInterface + { + $content = $this->getContent($contentTypeIdentifier, $fieldsData, $namesData); + + $mock = $this->createMock(ContentAwareInterface::class); + $mock->method('getContent')->willReturn($content); + + return $mock; + } + private function getConfigResolverMock() { $mock = $this->createMock(ConfigResolverInterface::class); diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php b/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php index 96646006f7..9ee0304ce2 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php @@ -7,6 +7,7 @@ namespace Ibexa\Tests\Core\MVC\Symfony\Templating\Twig\Extension; use Ibexa\Contracts\Core\Repository\ContentService; +use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface; use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; use Ibexa\Contracts\Core\Repository\Values\Content\Field; use Ibexa\Contracts\Core\SiteAccess\ConfigResolverInterface; @@ -131,6 +132,20 @@ protected function getContent($contentTypeIdentifier, array $fieldsData, array $ return $content; } + /** + * @param array $fieldsData + * @param array $namesData + */ + protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): ContentAwareInterface + { + $content = $this->getContent($contentTypeIdentifier, $fieldsData, $namesData); + + $mock = $this->createMock(ContentAwareInterface::class); + $mock->method('getContent')->willReturn($content); + + return $mock; + } + private function getTemplatePath($tpl) { return 'templates/' . $tpl; diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_content_field_identifier_first_filled_image.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_content_field_identifier_first_filled_image.test new file mode 100644 index 0000000000..5679178ac9 --- /dev/null +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_content_field_identifier_first_filled_image.test @@ -0,0 +1,59 @@ +--TEST-- +"ez_content_field_identifier_first_filled_image" function +--TEMPLATE-- +{% if not ez_content_field_identifier_first_filled_image(content) %} + empty +{% else %} + {{ ez_content_field_identifier_first_filled_image(content) }} +{% endif %} + +--DATA-- +return [ + 'content' => $this->getContent( + 'test_content', + [ + 'ezimage' => [ + 'id' => 125, + 'fieldDefIdentifier' => 'photo', + 'value' => 'value', + 'languageCode' => 'fre-FR', + ], + ] + ), +]; +--EXPECT-- +photo + +--DATA-- +return [ + 'content' => $this->getContent( + 'test_content', + [ + 'ezstring' => [ + 'id' => 125, + 'fieldDefIdentifier' => 'string', + 'value' => 'value', + 'languageCode' => 'fre-FR', + ], + ] + ), +]; +--EXPECT-- +empty + +--DATA-- +return [ + 'content' => $this->getContentAwareObject( + 'test_content', + [ + 'ezimage' => [ + 'id' => 125, + 'fieldDefIdentifier' => 'photo', + 'value' => 'value', + 'languageCode' => 'fre-FR', + ], + ] + ), +]; +--EXPECT-- +photo diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field.test index 28ead38efd..fd34c372d2 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field.test @@ -47,3 +47,21 @@ return array( --EXPECT-- foo2 bar3 + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'article', + array( + 'ezstring' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR' + ) + ) + ) +) +--EXPECT-- +foo2 +foo2 diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_description.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_description.test index 4cf367a387..96411ce37e 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_description.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_description.test @@ -47,3 +47,25 @@ return array( --EXPECT-- American description British description + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'article', + array( + 'ezstring' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR', + 'fieldDefDescriptions' => array( + 'eng-US' => 'American description', + 'fre-FR' => 'French description', + ) + ) + ) + ) +) +--EXPECT-- +French description +French description diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_name.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_name.test index a650008d88..1bee21568e 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_name.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_name.test @@ -47,3 +47,25 @@ return array( --EXPECT-- American name British name + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'article', + array( + 'ezstring' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR', + 'fieldDefNames' => array( + 'eng-US' => 'American name', + 'fre-FR' => 'French name', + ) + ) + ) + ) +) +--EXPECT-- +French name +French name diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_value.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_value.test index 5bc40c14c4..4ef97356e4 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_value.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_field_value.test @@ -47,3 +47,21 @@ return array( --EXPECT-- foo2 bar3 + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'article', + array( + 'ezstring' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR' + ) + ) + ) +) +--EXPECT-- +foo2 +foo2 diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_is_field_empty.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_is_field_empty.test index 7130bd95e5..41bb6793a0 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_is_field_empty.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_is_field_empty.test @@ -78,3 +78,21 @@ return array( ) --EXPECT-- empty + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'data', + array( + 'ezdata' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR' + ) + ) + ), + 'field' => $this->getField( false )->fieldDefIdentifier +) +--EXPECT-- +not empty diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_content_field_identifier_first_filled_image.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_content_field_identifier_first_filled_image.test new file mode 100644 index 0000000000..af8c83334e --- /dev/null +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_content_field_identifier_first_filled_image.test @@ -0,0 +1,59 @@ +--TEST-- +"ibexa_content_field_identifier_first_filled_image" function +--TEMPLATE-- +{% if not ibexa_content_field_identifier_first_filled_image(content) %} + empty +{% else %} + {{ ibexa_content_field_identifier_first_filled_image(content) }} +{% endif %} + +--DATA-- +return [ + 'content' => $this->getContent( + 'test_content', + [ + 'ezimage' => [ + 'id' => 125, + 'fieldDefIdentifier' => 'photo', + 'value' => 'value', + 'languageCode' => 'fre-FR', + ], + ] + ), +]; +--EXPECT-- +photo + +--DATA-- +return [ + 'content' => $this->getContent( + 'test_content', + [ + 'ezstring' => [ + 'id' => 125, + 'fieldDefIdentifier' => 'string', + 'value' => 'value', + 'languageCode' => 'fre-FR', + ], + ] + ), +]; +--EXPECT-- +empty + +--DATA-- +return [ + 'content' => $this->getContentAwareObject( + 'test_content', + [ + 'ezimage' => [ + 'id' => 125, + 'fieldDefIdentifier' => 'photo', + 'value' => 'value', + 'languageCode' => 'fre-FR', + ], + ] + ), +]; +--EXPECT-- +photo diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_content_name.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_content_name.test index 40ebad8c52..0c2a74fc17 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_content_name.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_content_name.test @@ -19,6 +19,21 @@ return array( French French +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'article', + array(), + array( + 'eng-US' => 'American', + 'fre-FR' => 'French' + ) + ) +) +--EXPECT-- +French +French + --DATA-- return array( 'content' => $this->getContent( diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field.test index e11d68be38..d9852f6826 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field.test @@ -47,3 +47,21 @@ return array( --EXPECT-- foo2 bar3 + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'article', + array( + 'ezstring' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR' + ) + ) + ) +) +--EXPECT-- +foo2 +foo2 diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_description.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_description.test index 67ffe1a861..91102c8037 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_description.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_description.test @@ -1,4 +1,5 @@ --TEST-- + "ibexa_field_description" function --TEMPLATE-- {{ ibexa_field_description( content, 'testfield' ) }} @@ -47,3 +48,25 @@ return array( --EXPECT-- American description British description + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'article', + array( + 'ezstring' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR', + 'fieldDefDescriptions' => array( + 'eng-US' => 'American description', + 'fre-FR' => 'French description', + ) + ) + ) + ) +) +--EXPECT-- +French description +French description diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_name.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_name.test index 3d2e2f4c98..ab7ce24cbe 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_name.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_name.test @@ -47,3 +47,25 @@ return array( --EXPECT-- American name British name + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'article', + array( + 'ezstring' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR', + 'fieldDefNames' => array( + 'eng-US' => 'American name', + 'fre-FR' => 'French name', + ) + ) + ) + ) +) +--EXPECT-- +French name +French name diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_value.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_value.test index 0041060de7..557fff3258 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_value.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_field_value.test @@ -47,3 +47,21 @@ return array( --EXPECT-- foo2 bar3 + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'article', + array( + 'ezstring' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR' + ) + ) + ) +) +--EXPECT-- +foo2 +foo2 diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_has_field.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_has_field.test index bd9964c30a..36eced7576 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_has_field.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_has_field.test @@ -21,3 +21,21 @@ return [ --EXPECT-- YES NO + +--DATA-- +return [ + 'content' => $this->getContentAwareObject( + 'test_content', + [ + 'ezstring' => [ + 'id' => 125, + 'fieldDefIdentifier' => 'existing', + 'value' => 'value', + 'languageCode' => 'eng-GB', + ], + ] + ), +]; +--EXPECT-- +YES +NO diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_is_field_empty.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_is_field_empty.test index 2a8ee2bc65..62f4de3cc2 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_is_field_empty.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_is_field_empty.test @@ -78,3 +78,21 @@ return array( ) --EXPECT-- empty + +--DATA-- +return array( + 'content' => $this->getContentAwareObject( + 'data', + array( + 'ezdata' => array( + 'id' => 5, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR' + ) + ) + ), + 'field' => $this->getField( false )->fieldDefIdentifier +) +--EXPECT-- +not empty diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/field_rendering_functions/ez_render_field.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/field_rendering_functions/ez_render_field.test index a402f0f118..bec94f84d5 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/field_rendering_functions/ez_render_field.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/field_rendering_functions/ez_render_field.test @@ -4,6 +4,7 @@ {% extends 'templates/base.html.twig' %} {% block content %} {{ ez_render_field( nooverride, 'testfield' ) }} +{{ ez_render_field( contentaware, 'testfield' ) }} {{ ez_render_field( overrides, 'testfield' ) }} {{ ez_render_field( notdefault, 'testfield' ) }} {{ ez_render_field( data, 'testfield' ) }} @@ -26,6 +27,17 @@ return array( ), ) ), + 'contentaware' => $this->getContentAwareObject( + 'contentaware', + array( + 'eznooverride' => array( + 'id' => 2, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR' + ), + ) + ), 'overrides' => $this->getContent( 'overrides', array( @@ -63,6 +75,7 @@ return array( ) --EXPECT-- default (no override) +default (no override) override2 not default field id: 5 contentInfo id: 42 versionInfo versionNo: 64 attr class: ezdata-field parameters:empty diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/field_rendering_functions/ibexa_render_field.test b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/field_rendering_functions/ibexa_render_field.test index 24642e0b9f..0229e0b1a4 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/field_rendering_functions/ibexa_render_field.test +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/field_rendering_functions/ibexa_render_field.test @@ -4,6 +4,7 @@ {% extends 'templates/base.html.twig' %} {% block content %} {{ ibexa_render_field( nooverride, 'testfield' ) }} +{{ ibexa_render_field( contentaware, 'testfield' ) }} {{ ibexa_render_field( overrides, 'testfield' ) }} {{ ibexa_render_field( notdefault, 'testfield' ) }} {{ ibexa_render_field( data, 'testfield' ) }} @@ -26,6 +27,17 @@ return array( ), ) ), + 'contentaware' => $this->getContentAwareObject( + 'contentaware', + array( + 'eznooverride' => array( + 'id' => 2, + 'fieldDefIdentifier' => 'testfield', + 'value' => 'foo2', + 'languageCode' => 'fre-FR' + ), + ) + ), 'overrides' => $this->getContent( 'overrides', array( @@ -63,6 +75,7 @@ return array( ) --EXPECT-- default (no override) +default (no override) override2 not default field id: 5 contentInfo id: 42 versionInfo versionNo: 64 attr class: ezdata-field parameters:empty