eZ Community » Forums » Developer » How to change object attribute in...
expandshrink

How to change object attribute in workflow?

How to change object attribute in workflow?

Sunday 13 May 2012 8:11:35 am - 2 replies

I have one hidden attribute, which cannot be edited by user. That attribute has to be updated depending on what user has enetered in other attributes, and use external webservice to get value.

I made workflow event, and triger it "before publish".

Now i stuck. I have value which has to be set to attribute, but ... how?

Modified on Sunday 13 May 2012 8:12:11 am by Vytautas Germanavičius

Sunday 13 May 2012 11:41:40 am

There are a few ways of doing it...and it really depends on what type of datatype etc.

But this is the easiest example - note this does not create a new version - which depending on what exactly you are doing may or may not be a good idea:

                $dataMap=$Node->DataMap();
                $attribute=$dataMap['class_identifier'];
                $attribute->setAttribute('data_text', 'text you want to insert' );
                $attribute->sync();

Monday 14 May 2012 7:46:58 am

Remember it is much more appropriate to use the eZContentObjectAttribute API instead of setting attribute's low level persistent object attribute storage contents in the manner shown by Steven.

See: http://pubsvn.ez.no/doxygen/trunk/html/classeZContentObjectAttribute.html

http://pubsvn.ez.no/doxygen/trunk/html/ezcontentobjectattribute_8php_source.html#l01194

One side note, remember nodes for objects do not exist until 'after' they are published so at most 'before publish' you can only modify the object and not the node soon to be published (in the given scenario).

Here is an example which uses the eZ Publish kernel API directly to achieve better results overall.

$object = eZContentObject::fetch( $objectID );
$objectDataMap = $object->dataMap();
$objectAttribute = $objectDataMap['class_identifier'];
$objectAttribute->setContent("Variable String Input");
$objectAttribute->storeData();

In the above example your using the more popular and accepted setContent method and storeData method which are in most situations better choices for most people. Also remember that the input requirement for a specific datatype's attribute's setContent method are different based on the datatype in question so do your research on the datatype your working with first to ensure you always provide the best input possible.

I hope this helps ...

Cheers,
Heath

Modified on Monday 14 May 2012 7:47:52 am by // Heath

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from