This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » eZ Publish 5 Platform » Public API and Image Variation
expandshrink

Public API and Image Variation

Public API and Image Variation

Friday 12 April 2013 6:18:26 pm - 5 replies

Hi,

I would like to get an image variation in PHP with the public API.

I've done the following : 

$imageField = $contentService->loadContent( $searchHit->valueObject->versionInfo->contentInfo->id )->getFieldValue( 'menu_image' ); 
 $variation = $imageVariationService->getVariation( $imageField, $searchHit->valueObject->versionInfo, "small" );

The problem is that getVariation method expects as first argument an instance of eZ\Publish\API\Repository\Values\Content\Field but the getFieldValue() method returns an instanceof eZ\Publish\Core\FieldType\Image\Value

Can you help me understand what is the difference ? 
How can I get a field that is an instance of eZ\Publish\API\Repository\Values\Content\Field ?

Thanks !

Friday 12 April 2013 8:42:40 pm

Hi Matthieu,

you should use getField method of Content value object, like this:

$imageField = $contentService->loadContent( $searchHit->valueObject->versionInfo->contentInfo->id )->getField( 'menu_image' );

The difference is significant. The field (the instance of eZ\Publish\API\Repository\Values\Content\Field) corrensponds to the content object attribute in eZ Publish 4, while the field value corresponds to the object attribute value in eZ Publish 4.

Sunday 14 April 2013 10:21:41 am

Easy ! Thanks Edi ! 

Thursday 22 August 2013 8:57:24 pm

Hello.

I'm trying to use the getVariation function but it does't work. Please, can you tell me how did you get the $imageVariationService?

Thanks

Wednesday 28 August 2013 12:56:05 pm

Hello!

Any ideas on this? Thanks

Wednesday 28 August 2013 2:22:09 pm

Hi Kiko

You can get the image variation service like this in a controller:

$imageVariationService = $this->get( 'ezpublish.fieldType.ezimage.variation_service' );

You can also use it in a Twig template:

{% set imageAlias = ez_image_alias( <field>, <versionInfo>, <aliasName> ) %}
expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from