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

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 00:55:16
Script start
Timing: Jan 30 2025 00:55:16
Module start 'layout'
Timing: Jan 30 2025 00:55:16
Module start 'content'
Timing: Jan 30 2025 00:55:16
Module end 'content'
Timing: Jan 30 2025 00:55:16
Script end

Main resources:

Total runtime0.0154 sec
Peak memory usage2,048.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 588.1328151.2109
Module start 'layout' 0.00630.0027 739.343836.6563
Module start 'content' 0.00910.0052 776.000090.1875
Module end 'content' 0.01430.0011 866.187533.9766
Script end 0.0153  900.1641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002214.3088140.0002
Check MTime0.00096.1458140.0001
Mysql Total
Database connection0.00074.418910.0007
Mysqli_queries0.003925.691230.0013
Looping result0.00000.071410.0000
Template Total0.00095.610.0009
Template load0.00064.211010.0006
Template processing0.00021.418210.0002
Override
Cache load0.00053.090810.0005
General
dbfile0.002113.353080.0003
String conversion0.00000.052840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs