16

I created a custom entity using Entity API that has certain properties defined in hook_schema() and also declared in entityPropertyInfo(), a class extending EntityDefaultMetadataController.

So far so good.

Now I'd like for users to be able to customize if and how these properties get displayed when viewing the entities so I implemented hook_field_extra_fields() and declared them.

Then, in my Controller which extends EntityAPIController I added the properties to the $content array in buildContent() as, outlined here.

It actually works pretty well and properties are rendered and respect the order and visibility settings in "Manage Display".

However, I can't seem to figure out how to add settings in Manage Display to customize the label positioning (inline/above/hidden) and, more importantly, how to specify custom formatters for these properties.

Any clues?

  • 1
    Do properties even support formatters? Since "Node" doesn't have "Title" under "Manage display", my first guess would be no. +1 for a good question though. – Letharion Apr 23 '12 at 8:50
  • Entity properties don't support formatters, no. You would need to implement that whole mechanism yourself – Clive Apr 23 '12 at 10:26
  • I was fearing that was the case – Alex Weber Apr 26 '12 at 22:04
7
+50

You could create a module providing a "property" field type. Store the the property to be formatted as an instance setting and then apply a formatter to that. It should be relatively straightforward. Relation module has a dummy field module which might help you in figuring out how to code this.

1

as you can see in field_ui_display_overview_form in modules/field_ui/field_ui.admin.inc the page Display setting will fill with $instances and $extra_fields:

$instances = field_info_instances($entity_type, $bundle);
$field_types = field_info_field_types();
$extra_fields = field_info_extra_fields($entity_type, $bundle, 'display');

in this function there is two loops which create the page:

foreach ($instances as $name => $instance) {
   ...
}

and

foreach ($extra_fields as $name => $extra_field) {
   ...
}

and only in first loop which iterate in fields there is options for label and formatter

so if you want this functionality on your properties (as @Clive said):

You would need to implement that whole mechanism yourself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.