I tried implementing the example.
It fails, in that it does not show me anything on the manage fields page.

I tried replacing the suggested hook_entity_info() by hook_field_info(), which is to my knowledge the correct hook.
I also changed the default formatter to "text_default".
Now it is showing a new row with label "Add new virtual field" on the manage fields pages.
It is however not showing any field types in the field drop-down.

Could someone explain to me how it is supposed to work (maybe with a working example)?

Comments

xen’s picture

Status: Active » Fixed

Docs has been fixed.

It most likely isn't showing any fields as the text_default formatter doesn't per default support your virtual field type. You can fix it using hook_field_formatter_info_alter(), but then you must make sure that your load function creates the value as text_default expects it.

The safer bet is creating a new formatter for your field.

There's a new virtual_field_test.module included in the latest dev. While it's meant for running tests, it's also a working example.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.