eZ Community » Forums » eZ Publish 5 Platform » Getting Content (contentobject) from...
expandshrink

Getting Content (contentobject) from Field Value

Getting Content (contentobject) from Field Value

Wednesday 15 May 2013 6:57:52 pm - 13 replies

Hi. In legacy mode we could get contentobject from a datatype. i mean, you could do something like

$contentObject = $contentObjectAttribute->object();

I would like to do something similar in non legacy mode. that's why i build a function where i pass a field as param.

 function getContent( Field $field )

How can i get the content to which this field belongs?

Should i proceed in a different way?

Thank you.

Modified on Thursday 16 May 2013 10:11:34 am by Carlos Revillo

Thursday 16 May 2013 9:50:07 am

Good question.

I would have thought that it was easy to get the ->value from it. Is it not?

I still have to wrap my head around @property-read and eZ\Publish\API\Repository\Values\ValueObject...

...maybe a tutorial or a page on confluence would help us!

Thursday 16 May 2013 10:06:50 am

Probably it's easy, but i don't find it happy.gif Emoticon

Maybe because i still think in legacy way too much. There, in eZContentObjectAttribute class we had that contentobject_id property https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/classes/ezcontentobjectattribute.php#L42

and even that object function:

https://github.com/ezsystems/ezpublish-legacy/blob/master/kernel/classes/ezcontentobjectattribute.php#L397

I'm  actually working in a ez5 disquscomments datatype, and so i need to get the Content and Location to which the Field belongs in order to provide disqus with an identifier and the url. 

But all i can get from Field is the id ( that should be the contentobjectattribute_id in legacy) and the value of the field. 

In other words, i can easily get and show all fields of a Content but i can't find a content from their fields. 

Edit: I edited the post title to make it more clear what i'm trying to find. 

Modified on Thursday 16 May 2013 10:11:08 am by Carlos Revillo

Thursday 16 May 2013 10:34:44 am

It is not available on the Field object:

https://github.com/ezsystems/ezpublish-kernel/blob/master/eZ/Publish/API/Repository/Values/Content/Field.php

Might be that it is injected into the field template.

Modified on Thursday 16 May 2013 10:38:12 am by André R

Thursday 16 May 2013 10:37:35 am

I'll try that again, André, but i think i did some {{ dump(field) }} in the template (at least in the one i'm adding for my custom fieldtype) and same result. i couldn't find a reference to the Content

Modified on Thursday 16 May 2013 10:38:00 am by Carlos Revillo

Thursday 16 May 2013 11:01:03 am

Hi Carlos,

In the field template called with ez_render_field(), the Content and the Location are not available but you have access to the ContentInfo.

See https://confluence.ez.no/display/EZP/FieldType+template

If you need more than this, you can also pass arbitrary values in the params parameter while calling ez_render_field, see https://confluence.ez.no/display/EZP/ez_render_field

Cheers

Modified on Thursday 16 May 2013 11:02:19 am by Damien Pobel

Thursday 16 May 2013 11:10:30 am

Thanks Damien. i'll try with contentInfo and see what i can get from there. 

you're also saying that i can go like

 {{ ez_render_field( 'content', 'myfield', {locationId: 5624} ) }}

aren't you?

Thursday 16 May 2013 11:15:46 am

ContentInfo has both content id, current version and main location id, otherwise go the other approach of passing in more objects.
Ref: https://github.com/ezsystems/ezpu...itory/Values/Content/ContentInfo.php

Thursday 16 May 2013 11:26:43 am

Thanks. I'll give a try and let you know. 

Thursday 16 May 2013 11:43:49 am

Quote from Carlos Revillo :

Thanks Damien. i'll try with contentInfo and see what i can get from there. 

you're also saying that i can go like

 {{ ez_render_field( 'content', 'myfield', {locationId: 5624} ) }}

aren't you?

yes or even directly pass the Location

{{ ez_render_field( content, "yourfield", {'location': location} ) }}

Thursday 16 May 2013 12:35:06 pm

Sorry for misunderstanding the need.

I think this need is good enough to warrant a feature request for API developers.

I am working on a datatype today by coincidence, and have also a need which is hard to fulfill: when serializing attribute data for the legacy db schema, get some information from the field definition. But it seems that all that is passed around is a simple value, from which I can not get back to the field itself and its definition...

Thursday 16 May 2013 12:47:06 pm

@Gaetano: Can't you use a converter for that?

Edit: Forget it, now i missunderstood you. 

Modified on Thursday 16 May 2013 12:51:59 pm by Carlos Revillo

Thursday 16 May 2013 1:02:28 pm

ps: EZP-20882, EZP-20881

Thursday 16 May 2013 8:49:10 pm

i marked this as solved as indeed i can use contentInfo from the template and pass it to a controller. 

Thanks guys!. 

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from