0

I tried copying the functions from the field module in example modules to get a field to show up in Manage Fields without necessarily any functionality

Looking at the answer to this question, only field_create_field() and hook_field_info() should do the trick but I never got that working with the following code:

function entityreference_add_new_field_info() { return array( 'entityreference_add_link' => array( 'label' => t('Entityreference link'), 'description' => t('Entityreference link'), 'default_widget' => 'entityreference_link_widget', 'default_formatter' => 'entityreference_link_formatter', ), ); field_create_field('entityreference_add_link'); } 

Putting field_create_field() outside of hook_field_info() returns 'call to undefined function' error.

Update: Here's one thing I've tried without success:

function entityreference_add_new_field_info() { return array( 'entityreference_add_link' => array( 'label' => t('Entityreference link'), 'description' => t('Entityreference link'), 'default_widget' => 'entityreference_link_widget', 'default_formatter' => 'entityreference_link_formatter', ), ); field_create_field('entityreference_add_link'); $instance = array( 'field_name' => 'entityrefernce_add_link', 'entity_type' => 'node', 'label' => 'The Link', 'bundle' => 'node', ); field_create_instance($instance); } enter code here 

1 Answer 1

0

You have already created the definition of the field, but you also need to create an actual instance of that field to use it.

$instance = array( 'field_name' => $your_field_name, 'entity_type' => 'node', 'label' => $your_field_label, 'bundle' => 'node', ); field_create_instance($instance); 

That plus what you have above should be the minimum you need to get a field to appear in your management screen.

See the field_create_instance() docs for more info about available options.

2
  • Ok tried something that didn't work I'll edit my question with the update. I also would like to add that in www.drupal.org/projects/example there is an example of a field module that constructs a field that you can choose in Manage Fields without a field_create_instance module. Commented Jun 27, 2012 at 19:53
  • Looks like those createfield and create_instance functions are used in .install files? I noticed that those functions are used when fields are created on the fly when a new bundle is installed. Am I correct that you can't choose those fields in Manage Fields and use them for other bundels where you set a widget and give it a name? Commented Jun 28, 2012 at 7:58

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.