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

eZ Community » Forums » eZ Publish 5 Platform » How to get the contentTypeIdentifier...
expandshrink

How to get the contentTypeIdentifier from a field object ?

How to get the contentTypeIdentifier from a field object ?

Thursday 28 February 2013 3:08:47 pm - 4 replies

This may be a stupid question but I'm stuck with this problem.

I've just a field object instance. I can get the field value, the field identifier, etc ... but there no data about his fieldType. How can I get it ?

Thursday 28 February 2013 5:13:16 pm

In which context exactly ? Where did you get the Field object from ?

Friday 01 March 2013 7:16:10 am

I need this the FieldType Identifier in 2 context :

1°) In a twig custom filter :

In a template I do something like this

content.getField('my_field')|my_custom_twig

In my twig filter function, I've got this

function my_custom_twig_filter($field){

... some code

}

2°) In a controller

For example, I've a homepage contentType witch allow to switch the top menu element. It's directed by menu_type field (ezselection)

I do something like this

$content = $contentService->getContent(2);
$field = $content->getField('menu_type')
$fieldTypeService = $this->repository->getFieldTypeService();
$fieldType = $fieldTypeService->getFieldType('ezselection');
$menuType = $fieldType->toHash( $field->value );

How do I replace the $fieldType = $fieldTypeService->getFieldType('ezselection'); ?

Thank's

Tuesday 05 March 2013 12:24:49 am

Emmanuel, for the in-controller case, something like this should work: 

$contentTypeService = $this->getRepository()->getContentTypeService();
$typeDef = $contentTypeService->loadContentTypeByIdentifier('article_or_whatever');
$fieldDef = $typeDef->getFieldDefinition('menu_type');
$menuType = $fieldDef-></span><span>fieldTypeIdentifier;

This is one of those areas that feels like a bit of a step back from 4. It would be nice if the Public API included convenience methods to navigate between content/contentInfo, field/fieldDef/value etc. Content::contentInfo does this for content objects, but more methods like that would be great.

Modified on Tuesday 05 March 2013 12:25:30 am by Joe Kepley

Wednesday 06 March 2013 9:22:35 am

Thank you very much Joe.

So I gess it's not possible to get the FieldType from the Field object alone, you must have the content object to get the fieldDefinition. 

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from