From 89bea7541918e26654396124c3e8926c6cebc14d Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Mon, 27 Jan 2025 09:39:29 +0100 Subject: [PATCH 1/9] Support for ContentAwareInterface in ibexa_* Twig functions added --- .../Twig/Extension/ContentExtension.php | 125 +++++++++++++----- .../Extension/FieldRenderingExtension.php | 35 ++++- .../Twig/Extension/RenderContentExtension.php | 29 +++- .../Twig/Extension/ContentExtensionTest.php | 25 ++++ ...FieldRenderingExtensionIntegrationTest.php | 25 ++++ ...t_field_identifier_first_filled_image.test | 59 +++++++++ .../_fixtures/content_functions/ez_field.test | 18 +++ .../ez_field_description.test | 22 +++ .../content_functions/ez_field_name.test | 22 +++ .../content_functions/ez_field_value.test | 18 +++ .../content_functions/ez_is_field_empty.test | 18 +++ ...t_field_identifier_first_filled_image.test | 59 +++++++++ .../content_functions/ibexa_content_name.test | 15 +++ .../content_functions/ibexa_field.test | 18 +++ .../ibexa_field_description.test | 23 ++++ .../content_functions/ibexa_field_name.test | 22 +++ .../content_functions/ibexa_field_value.test | 18 +++ .../content_functions/ibexa_has_field.test | 18 +++ .../ibexa_is_field_empty.test | 18 +++ .../ez_render_field.test | 13 ++ .../ibexa_render_field.test | 13 ++ 21 files changed, 573 insertions(+), 40 deletions(-) create mode 100644 tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ez_content_field_identifier_first_filled_image.test create mode 100644 tests/lib/MVC/Symfony/Templating/Twig/Extension/_fixtures/content_functions/ibexa_content_field_identifier_first_filled_image.test diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php index 578208acf0..09869070a9 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; @@ -94,14 +95,14 @@ public function getFunctions(): array [$this, 'isFieldEmpty'], $this->getDeprecationOptions('ibexa_field_is_empty'), ), - new TwigFunction( - 'ibexa_has_field', - [$this, 'hasField'] - ), new TwigFunction( 'ibexa_field_is_empty', [$this, 'isFieldEmpty'] ), + new TwigFunction( + 'ibexa_has_field', + [$this, 'hasField'] + ), new TwigFunction( 'ez_field_name', [$this, 'getTranslatedFieldDefinitionName'], @@ -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\ValueObject|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data 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) * - * @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($data, $forcedLanguage = null) { + $content = $this->getValueObject($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($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($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\ValueObject|\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($data, $fieldDefIdentifier, $forcedLanguage = null) { - if ($contentType = $this->getContentType($content)) { + if ($contentType = $this->getContentType($this->getValueObject($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\ValueObject|\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($data, $fieldDefIdentifier, $forcedLanguage = null) { - if ($contentType = $this->getContentType($content)) { + if ($contentType = $this->getContentType($this->getValueObject($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($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($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($data) { + $content = $this->getContent($data); foreach ($content->getFieldsByLanguage() as $field) { $fieldTypeIdentifier = $content->getContentType() ->getFieldDefinition($field->fieldDefIdentifier) @@ -305,6 +322,46 @@ public function getFirstFilledImageFieldIdentifier(Content $content) return null; } + + /** + * @param \Ibexa\Contracts\Core\Repository\Values\ValueObject|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data + * + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType + */ + private function getValueObject($data): ValueObject + { + if ($data instanceof ContentAwareInterface) { + $data = $data->getContent(); + } elseif (!$data instanceof ValueObject) { + throw new InvalidArgumentType( + '$data', + sprintf('%s', ValueObject::class), + $data + ); + } + + return $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($data): Content + { + if ($data instanceof ContentAwareInterface) { + $data = $data->getContent(); + } elseif (!$data instanceof Content) { + throw new InvalidArgumentType( + '$data', + sprintf('%s', Content::class), + $data + ); + } + + return $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..11bbce1210 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,14 +54,19 @@ 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); }; @@ -210,6 +217,26 @@ 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($content): Content + { + if ($content instanceof ContentAwareInterface) { + $content = $content->getContent(); + } elseif (!$content instanceof Content) { + throw new InvalidArgumentType( + '$content', + sprintf('%s', Content::class), + $content + ); + } + + return $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..eb748d5886 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,37 @@ 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($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($data): Content + { + if ($data instanceof ContentAwareInterface) { + $data = $data->getContent(); + } elseif (!$data instanceof Content) { + throw new InvalidArgumentType( + '$data', + sprintf('%s', Content::class), + $data + ); + } + + return $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..137d7c25a9 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php @@ -9,6 +9,8 @@ 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\Content as APIContent; +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 +128,29 @@ 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); + + return new class($content) implements ContentAwareInterface { + private APIContent $content; + + public function __construct(APIContent $content) + { + $this->content = $content; + } + + public function getContent(): APIContent + { + return $this->content; + } + }; + } + 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..07bae39a44 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php @@ -7,6 +7,8 @@ namespace Ibexa\Tests\Core\MVC\Symfony\Templating\Twig\Extension; use Ibexa\Contracts\Core\Repository\ContentService; +use Ibexa\Contracts\Core\Repository\Values\Content\Content as APIContent; +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 +133,29 @@ 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); + + return new class($content) implements ContentAwareInterface { + private APIContent $content; + + public function __construct(APIContent $content) + { + $this->content = $content; + } + + public function getContent(): APIContent + { + return $this->content; + } + }; + } + 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..0150e28894 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' ) }} +{{ ibexa_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 From 48a68b10b03c3751aa4afe0beab2e8f045caf046 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Mon, 27 Jan 2025 11:01:55 +0100 Subject: [PATCH 2/9] Support for ContentAwareInterface in ibexa_* Twig functions added --- .../Templating/Twig/Extension/FieldRenderingExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php index 11bbce1210..9f60a934b7 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php @@ -68,8 +68,8 @@ function ( ) { $this->fieldBlockRenderer->setTwig($environment); - return $this->renderFieldDefinitionSettings($fieldDefinition, $params); - }; + return $this->renderFieldDefinitionSettings($fieldDefinition, $params); + }; return [ new TwigFunction( From 1a7c54374d9ca635dc0a9f5463c591316759b633 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Mon, 27 Jan 2025 13:18:07 +0100 Subject: [PATCH 3/9] Support for ContentAwareInterface in ibexa_* Twig functions added --- .../Symfony/Templating/Twig/Extension/ContentExtension.php | 4 ++-- .../Templating/Twig/Extension/FieldRenderingExtension.php | 2 +- .../Templating/Twig/Extension/RenderContentExtension.php | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php index 09869070a9..fdb9bc2be6 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php @@ -335,7 +335,7 @@ private function getValueObject($data): ValueObject } elseif (!$data instanceof ValueObject) { throw new InvalidArgumentType( '$data', - sprintf('%s', ValueObject::class), + sprintf('%s or %s', ValueObject::class, ContentAwareInterface::class), $data ); } @@ -355,7 +355,7 @@ private function getContent($data): Content } elseif (!$data instanceof Content) { throw new InvalidArgumentType( '$data', - sprintf('%s', Content::class), + sprintf('%s pr %s', Content::class, ContentAwareInterface::class), $data ); } diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php index 9f60a934b7..0a109c35ce 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php @@ -230,7 +230,7 @@ private function getContent($content): Content } elseif (!$content instanceof Content) { throw new InvalidArgumentType( '$content', - sprintf('%s', Content::class), + sprintf('%s or %s', Content::class, ContentAwareInterface::class), $content ); } diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php index eb748d5886..5312a280f6 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php @@ -85,7 +85,7 @@ private function getContent($data): Content } elseif (!$data instanceof Content) { throw new InvalidArgumentType( '$data', - sprintf('%s', Content::class), + sprintf('%s or %s', Content::class, ContentAwareInterface::class), $data ); } From 5e6e389360aa7d54a5c1314d198a23c66e8cbd04 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Tue, 28 Jan 2025 14:24:58 +0100 Subject: [PATCH 4/9] Fixes after CR --- .../Templating/Twig/Extension/ContentExtension.php | 8 ++++---- .../field_rendering_functions/ez_render_field.test | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php index fdb9bc2be6..621f83d3d7 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php @@ -95,14 +95,14 @@ public function getFunctions(): array [$this, 'isFieldEmpty'], $this->getDeprecationOptions('ibexa_field_is_empty'), ), - new TwigFunction( - 'ibexa_field_is_empty', - [$this, 'isFieldEmpty'] - ), new TwigFunction( 'ibexa_has_field', [$this, 'hasField'] ), + new TwigFunction( + 'ibexa_field_is_empty', + [$this, 'isFieldEmpty'] + ), new TwigFunction( 'ez_field_name', [$this, 'getTranslatedFieldDefinitionName'], 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 0150e28894..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,7 +4,7 @@ {% extends 'templates/base.html.twig' %} {% block content %} {{ ez_render_field( nooverride, 'testfield' ) }} -{{ ibexa_render_field( contentaware, 'testfield' ) }} +{{ ez_render_field( contentaware, 'testfield' ) }} {{ ez_render_field( overrides, 'testfield' ) }} {{ ez_render_field( notdefault, 'testfield' ) }} {{ ez_render_field( data, 'testfield' ) }} From b29aabcaf897d88d664286cad4dc4769ecfa9652 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Tue, 4 Feb 2025 12:15:25 +0100 Subject: [PATCH 5/9] Fixes after CR --- .../Twig/Extension/ContentExtension.php | 42 +++++++++---------- .../Extension/FieldRenderingExtension.php | 2 +- .../Twig/Extension/RenderContentExtension.php | 4 +- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php index 621f83d3d7..637831aec0 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php @@ -138,16 +138,16 @@ public function getFunctions(): array } /** - * @param \Ibexa\Contracts\Core\Repository\Values\ValueObject|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data 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 ContentAware 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, ContentInfo or ContentAwareInterface object. + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType When $content is not a valid Content, ContentInfo, or ContentAwareInterface object. * * @return string */ - public function getTranslatedContentName($data, $forcedLanguage = null) + public function getTranslatedContentName(object $data, $forcedLanguage = null) { - $content = $this->getValueObject($data); + $content = $this->resolveData($data); if ($content instanceof Content) { return $this->translationHelper->getTranslatedContentName($content, $forcedLanguage); } elseif ($content instanceof ContentInfo) { @@ -171,7 +171,7 @@ public function getTranslatedContentName($data, $forcedLanguage = null) * * @return \Ibexa\Contracts\Core\Repository\Values\Content\Field */ - public function getTranslatedField($data, $fieldDefIdentifier, $forcedLanguage = null) + public function getTranslatedField(object $data, $fieldDefIdentifier, $forcedLanguage = null) { return $this->translationHelper->getTranslatedField($this->getContent($data), $fieldDefIdentifier, $forcedLanguage); } @@ -183,7 +183,7 @@ public function getTranslatedField($data, $fieldDefIdentifier, $forcedLanguage = * * @return mixed A primitive type or a field type Value object depending on the field type. */ - public function getTranslatedFieldValue($data, $fieldDefIdentifier, $forcedLanguage = null) + public function getTranslatedFieldValue(object $data, $fieldDefIdentifier, $forcedLanguage = null) { return $this->translationHelper->getTranslatedField($this->getContent($data), $fieldDefIdentifier, $forcedLanguage)->value; } @@ -191,17 +191,17 @@ public function getTranslatedFieldValue($data, $fieldDefIdentifier, $forcedLangu /** * Gets name of a FieldDefinition name by loading ContentType based on Content/ContentInfo/ContentAwareInterface object. * - * @param \Ibexa\Contracts\Core\Repository\Values\ValueObject|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data Must be Content, ContentInfo or ContentAwareInterface 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, ContentInfo or ContentAwareInterface object. + * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType When $content is not a valid Content, ContentInfo, or ContentAwareInterface object. * * @return string|null */ - public function getTranslatedFieldDefinitionName($data, $fieldDefIdentifier, $forcedLanguage = null) + public function getTranslatedFieldDefinitionName(object $data, $fieldDefIdentifier, $forcedLanguage = null) { - if ($contentType = $this->getContentType($this->getValueObject($data))) { + if ($contentType = $this->getContentType($this->resolveData($data))) { return $this->translationHelper->getTranslatedFieldDefinitionProperty( $contentType, $fieldDefIdentifier, @@ -220,15 +220,15 @@ public function getTranslatedFieldDefinitionName($data, $fieldDefIdentifier, $fo /** * Gets name of a FieldDefinition description by loading ContentType based on Content/ContentInfo/ContentAwareInterface object. * - * @param \Ibexa\Contracts\Core\Repository\Values\ValueObject|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data Must be Content, ContentInfo or ContentAwareInterface 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) * * @return string|null */ - public function getTranslatedFieldDefinitionDescription($data, $fieldDefIdentifier, $forcedLanguage = null) + public function getTranslatedFieldDefinitionDescription(object $data, $fieldDefIdentifier, $forcedLanguage = null) { - if ($contentType = $this->getContentType($this->getValueObject($data))) { + if ($contentType = $this->getContentType($this->resolveData($data))) { return $this->translationHelper->getTranslatedFieldDefinitionProperty( $contentType, $fieldDefIdentifier, @@ -247,7 +247,7 @@ public function getTranslatedFieldDefinitionDescription($data, $fieldDefIdentifi /** * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data */ - public function hasField($data, string $fieldDefIdentifier): bool + public function hasField(object $data, string $fieldDefIdentifier): bool { $content = $this->getContent($data); @@ -271,7 +271,7 @@ public function getFieldGroupName(string $identifier): ?string * * @return bool */ - public function isFieldEmpty($data, $fieldDefIdentifier, $forcedLanguage = null) + public function isFieldEmpty(object $data, $fieldDefIdentifier, $forcedLanguage = null) { if ($fieldDefIdentifier instanceof Field) { $fieldDefIdentifier = $fieldDefIdentifier->fieldDefIdentifier; @@ -301,7 +301,7 @@ private function getContentType(ValueObject $content) /** * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data */ - public function getFirstFilledImageFieldIdentifier($data) + public function getFirstFilledImageFieldIdentifier(object $data) { $content = $this->getContent($data); foreach ($content->getFieldsByLanguage() as $field) { @@ -324,18 +324,18 @@ public function getFirstFilledImageFieldIdentifier($data) } /** - * @param \Ibexa\Contracts\Core\Repository\Values\ValueObject|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data + * @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 getValueObject($data): ValueObject + private function resolveData(object $data): ValueObject { if ($data instanceof ContentAwareInterface) { $data = $data->getContent(); - } elseif (!$data instanceof ValueObject) { + } elseif (!$data instanceof Content && !$data instanceof ContentInfo) { throw new InvalidArgumentType( '$data', - sprintf('%s or %s', ValueObject::class, ContentAwareInterface::class), + sprintf('%s or %s or %s', Content::class, ContentInfo::class, ContentAwareInterface::class), $data ); } @@ -348,7 +348,7 @@ private function getValueObject($data): ValueObject * * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType */ - private function getContent($data): Content + private function getContent(object $data): Content { if ($data instanceof ContentAwareInterface) { $data = $data->getContent(); diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php index 0a109c35ce..e6b0adae79 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php @@ -223,7 +223,7 @@ private function getFieldTypeIdentifier(Content $content, Field $field) * * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType */ - private function getContent($content): Content + private function getContent(object $content): Content { if ($content instanceof ContentAwareInterface) { $content = $content->getContent(); diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php index 5312a280f6..c6fe0a5e24 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php @@ -63,7 +63,7 @@ public function getFunctions(): array /** * @param \Ibexa\Contracts\Core\Repository\Values\Content\Content|\Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface $data */ - public function renderContent($data, array $options = []): string + public function renderContent(object $data, array $options = []): string { $renderOptions = new RenderOptions($options); $event = $this->eventDispatcher->dispatch( @@ -78,7 +78,7 @@ public function renderContent($data, array $options = []): string * * @throws \Ibexa\Core\Base\Exceptions\InvalidArgumentType */ - private function getContent($data): Content + private function getContent(object $data): Content { if ($data instanceof ContentAwareInterface) { $data = $data->getContent(); From ead4159e2b1b05cdce67f501bd351ddb1981d997 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Tue, 4 Feb 2025 12:25:12 +0100 Subject: [PATCH 6/9] Fixes after CR --- .../Symfony/Templating/Twig/Extension/ContentExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php index 637831aec0..84de5769ce 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php @@ -191,7 +191,7 @@ public function getTranslatedFieldValue(object $data, $fieldDefIdentifier, $forc /** * Gets name of a FieldDefinition name by loading ContentType based on Content/ContentInfo/ContentAwareInterface 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 \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) * @@ -220,7 +220,7 @@ public function getTranslatedFieldDefinitionName(object $data, $fieldDefIdentifi /** * Gets name of a FieldDefinition description by loading ContentType based on Content/ContentInfo/ContentAwareInterface 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 \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) * From 22c3e9a148b71c66d1f82572c53ac0cc72685c26 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Tue, 4 Feb 2025 13:31:42 +0100 Subject: [PATCH 7/9] Fixes after CR --- .../MVC/Symfony/Templating/Twig/Extension/ContentExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php index 84de5769ce..530a3249f1 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php @@ -138,7 +138,7 @@ public function getFunctions(): array } /** - * @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 ContentAware 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, ContentInfo, or ContentAwareInterface object. From ee5b43c66bc647283649a92163e2113e9459f2f3 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Tue, 4 Feb 2025 14:29:41 +0100 Subject: [PATCH 8/9] Fixes after CR --- .../Twig/Extension/ContentExtension.php | 36 ++++++++++--------- .../Extension/FieldRenderingExtension.php | 17 ++++----- .../Twig/Extension/RenderContentExtension.php | 18 +++++----- .../Twig/Extension/ContentExtensionTest.php | 20 ++++------- ...FieldRenderingExtensionIntegrationTest.php | 20 ++++------- 5 files changed, 51 insertions(+), 60 deletions(-) diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php index 530a3249f1..99ff3b13a5 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtension.php @@ -330,17 +330,19 @@ public function getFirstFilledImageFieldIdentifier(object $data) */ private function resolveData(object $data): ValueObject { + if ($data instanceof Content || $data instanceof ContentInfo) { + return $data; + } + if ($data instanceof ContentAwareInterface) { - $data = $data->getContent(); - } elseif (!$data instanceof Content && !$data instanceof ContentInfo) { - throw new InvalidArgumentType( - '$data', - sprintf('%s or %s or %s', Content::class, ContentInfo::class, ContentAwareInterface::class), - $data - ); + return $data->getContent(); } - return $data; + throw new InvalidArgumentType( + '$content', + sprintf('%s or %s or %s', Content::class, ContentInfo::class, ContentAwareInterface::class), + $data, + ); } /** @@ -350,17 +352,19 @@ private function resolveData(object $data): ValueObject */ private function getContent(object $data): Content { + if ($data instanceof Content) { + return $data; + } + if ($data instanceof ContentAwareInterface) { - $data = $data->getContent(); - } elseif (!$data instanceof Content) { - throw new InvalidArgumentType( - '$data', - sprintf('%s pr %s', Content::class, ContentAwareInterface::class), - $data - ); + return $data->getContent(); } - return $data; + throw new InvalidArgumentType( + '$content', + sprintf('%s or %s', Content::class, ContentAwareInterface::class), + $data, + ); } } diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php index e6b0adae79..a5b41bf533 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtension.php @@ -225,17 +225,18 @@ private function getFieldTypeIdentifier(Content $content, Field $field) */ private function getContent(object $content): Content { + if ($content instanceof Content) { + return $content; + } if ($content instanceof ContentAwareInterface) { - $content = $content->getContent(); - } elseif (!$content instanceof Content) { - throw new InvalidArgumentType( - '$content', - sprintf('%s or %s', Content::class, ContentAwareInterface::class), - $content - ); + return $content->getContent(); } - return $content; + throw new InvalidArgumentType( + '$content', + sprintf('%s or %s', Content::class, ContentAwareInterface::class), + $content, + ); } } diff --git a/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php b/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php index c6fe0a5e24..0b3d982937 100644 --- a/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php +++ b/src/lib/MVC/Symfony/Templating/Twig/Extension/RenderContentExtension.php @@ -80,17 +80,19 @@ public function renderContent(object $data, array $options = []): string */ private function getContent(object $data): Content { + if ($data instanceof Content) { + return $data; + } + if ($data instanceof ContentAwareInterface) { - $data = $data->getContent(); - } elseif (!$data instanceof Content) { - throw new InvalidArgumentType( - '$data', - sprintf('%s or %s', Content::class, ContentAwareInterface::class), - $data - ); + return $data->getContent(); } - return $data; + 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 137d7c25a9..eb1cf6b798 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php @@ -9,7 +9,6 @@ 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\Content as APIContent; use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface; use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; use Ibexa\Contracts\Core\Repository\Values\Content\Field; @@ -131,24 +130,17 @@ protected function getContent(string $contentTypeIdentifier, array $fieldsData, /** * @param array $fieldsData * @param array $namesData + * + * @return \Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): ContentAwareInterface + protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): object { $content = $this->getContent($contentTypeIdentifier, $fieldsData, $namesData); - return new class($content) implements ContentAwareInterface { - private APIContent $content; - - public function __construct(APIContent $content) - { - $this->content = $content; - } + $mock = $this->createMock(ContentAwareInterface::class); + $mock->method('getContent')->willReturn($content); - public function getContent(): APIContent - { - return $this->content; - } - }; + return $mock; } private function getConfigResolverMock() diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php b/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php index 07bae39a44..b2a4497f0f 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php @@ -7,7 +7,6 @@ namespace Ibexa\Tests\Core\MVC\Symfony\Templating\Twig\Extension; use Ibexa\Contracts\Core\Repository\ContentService; -use Ibexa\Contracts\Core\Repository\Values\Content\Content as APIContent; use Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface; use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; use Ibexa\Contracts\Core\Repository\Values\Content\Field; @@ -136,24 +135,17 @@ protected function getContent($contentTypeIdentifier, array $fieldsData, array $ /** * @param array $fieldsData * @param array $namesData + * + * @return \Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): ContentAwareInterface + protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): object { $content = $this->getContent($contentTypeIdentifier, $fieldsData, $namesData); - return new class($content) implements ContentAwareInterface { - private APIContent $content; - - public function __construct(APIContent $content) - { - $this->content = $content; - } + $mock = $this->createMock(ContentAwareInterface::class); + $mock->method('getContent')->willReturn($content); - public function getContent(): APIContent - { - return $this->content; - } - }; + return $mock; } private function getTemplatePath($tpl) From 43c90f4184527ebfc5b57a76fca337d045b85208 Mon Sep 17 00:00:00 2001 From: MateuszKolankowski Date: Tue, 4 Feb 2025 14:59:18 +0100 Subject: [PATCH 9/9] Fixes after CR --- .../Templating/Twig/Extension/ContentExtensionTest.php | 4 +--- .../Twig/Extension/FieldRenderingExtensionIntegrationTest.php | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php b/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php index eb1cf6b798..3c9e394804 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/ContentExtensionTest.php @@ -130,10 +130,8 @@ protected function getContent(string $contentTypeIdentifier, array $fieldsData, /** * @param array $fieldsData * @param array $namesData - * - * @return \Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): object + protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): ContentAwareInterface { $content = $this->getContent($contentTypeIdentifier, $fieldsData, $namesData); diff --git a/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php b/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php index b2a4497f0f..9ee0304ce2 100644 --- a/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php +++ b/tests/lib/MVC/Symfony/Templating/Twig/Extension/FieldRenderingExtensionIntegrationTest.php @@ -135,10 +135,8 @@ protected function getContent($contentTypeIdentifier, array $fieldsData, array $ /** * @param array $fieldsData * @param array $namesData - * - * @return \Ibexa\Contracts\Core\Repository\Values\Content\ContentAwareInterface|\PHPUnit\Framework\MockObject\MockObject */ - protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): object + protected function getContentAwareObject(string $contentTypeIdentifier, array $fieldsData, array $namesData = []): ContentAwareInterface { $content = $this->getContent($contentTypeIdentifier, $fieldsData, $namesData);