Forums / Developer / Content object attribute id

Content object attribute id

Author Message

Sao Tavi

Monday 13 June 2011 10:26:03 am

I need in a custom template function (so in PHP and not in the template) to access the currently displayed content object (I actually need the attribute id of one of its attributes).

Also, I need to access the attribute id of its parent node's attribute and the attribute id of a object selected by object id.

How can I do this?

Thanks

Marko Žmak

Monday 13 June 2011 1:28:50 pm

You can use the attribute() method like this:

$object->attribute('id');

You will be able to get all the proprties that you can get in the template. You can also concatenate the attribute operator. For example, this.

$object.main_node.node_id

would in PHP be:

$object->attribute('main_node')->attribute('node_id')

This is valid for all eZP objects. For getting the attributes you need:

$object->attribute('data_map')

And this will give you an associative array of object's attributes, attribute identifiers will be the keys in array.

As for getting the currently displayed content ojbect, it really depens on where you wan't to use this function. Try looking at the docs.

--
Nothing is impossible. Not if you can imagine it!

Hubert Farnsworth

Sao Tavi

Thursday 16 June 2011 9:03:38 am

Thank you very much, this got me to the next step.

Now, my problem is: how can I check if the current user has the permission to edit the attribute?

Sao Tavi

Monday 20 June 2011 6:02:15 am

Found, it seems that there is a function, canEdit(), inherited from eZContentObjectTreeNode that does exactly this. I should have looked on the inheritance list before asking the question :D