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

eZ Community » Forums » Developer » Unable to add alternative_text to...

Unable to add alternative_text to image using PHP

Unable to add alternative_text to image using PHP

Tuesday 21 April 2015 10:57:57 am - 4 replies

I am trying to create an image object using PHP. I am able to add the image source but unable to add the image alternative_text.

$params = array();
$params['class_identifier'] = $bilde_class_identifier;
$params['creator_id']       = $param_userID;
$params['parent_node_id']   = $parent_of_bilde;
$params['language']         = $bilde_language;
$params['attributes'] = array(
               'image' => $imagePath,
               'alternative_text' => 'This is the alternative text');
$contentObject = eZContentFunctions::createAndPublishObject($params);

Modified on Tuesday 21 April 2015 11:00:04 am by Jyotirmoy Biswas

Tuesday 21 April 2015 11:13:50 am

Hello Jyotirmoy,

Does your your image content class have have an ezstring content class attribute using the identifier 'alternative_text'?

This seems like it would not be a problem since we all regularly store ezstring data this way all the time.


I notice that this attribute is not provided by default (or at least not documented). 

Which leads me to realize your trying to use the datatype feature to store 'alternative_text' which requires a different solution (than your using) since it is not a separate attribute but rather part of the same 'image' (class attribute identifier) attribute input.

Here is the documentation on the fromString implementation:

Though it seems the ezimage from string docs are a little out of date.

Based on the datatype code review the new input format for the fromString function is pipe delimited string concatenation.  

array( 'image' => $imagePath + '|' + 'This is the alternative text', // rest of attributes ),

I hope this helps!


Modified on Tuesday 21 April 2015 11:24:28 am by // Heath

Tuesday 21 April 2015 11:31:06 am

Hi Heath,

Thanks for your reply. While viewing the content class I can not see the class attribute "alternative_text". But while editing any object from admin end, I am able to see the "alternative_text" input box, just below the image. And if I add the alternative text(just below the image) from admin end, it works good.

From database I can see an XML block:

<?xml version="1.0" encoding="utf-8"?>

<ezimage serial_number="1" is_valid="1"......

If I change the "alternative_text" on that XML block from database manually, the changes are visible on the site.

Is there a way to add it through the PHP code from the module?

Tuesday 21 April 2015 11:36:55 am

Hi Heath,

Thanks for your update.

It works good!!

This is the thing I was looking for.

Thanks again,

Jyotirmoy Biswas

Tuesday 21 April 2015 12:04:43 pm

Hello Jyotirmoy,

Happy to help you reach the solution you needed.

Can you login to and then click the checkbox at the top of your original post near the title? It is the box with the checkbox inside. It turns green when you have clicked it correctly.

Doing this indicates your question has been solved.

Thanks again for your continued support!

Take it eZ!



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

36 542 Users on board!

Forums menu

Proudly Developed with from