I am developing a module. It adds a button to certain content types:

function mymodule_node_view($node, $view_mode, $langcode) {
  $node->content['mymodule_button'] = drupal_get_form(....);

I give the option to configure what content types must have this button:

function mymodule_admin_settings() {
  $form['mymodule_node_types'] = array(
    '#type' => 'checkboxes',
    '#options' => $options, //node types
    '#default_value' => variable_get('mymodule_node_types', array()),
  return system_settings_form($form);

I want to configure the weight of the button through the 'manage display' page of each content type. For that I use the hook_field_extra_fields() implementation:

function mymodule_field_extra_fields() {
  $mymodule_types = variable_get('mymodule_node_types', array());
  $display_elements['mymodule_button'] = array(
    'weight' => 0,
  foreach ($mymodule_types as $type) {
    $extra_fields['node'][$type]['display'] = $display_elements;
  return $extra_fields;

I need when the admin changes the content types in the configuration page, the 'extra fields' will be shown only in the content types selected, not in the other ones. This function is not working this way with this code.

1 Answer 1


hook_field_extra_fields is invoked by FieldInfo::getBundleExtraFields. This method caches the extra fields info in the database.

cache_set("field_info:bundle_extra:$entity_type:$bundle", $info, 'cache_field');

So you want to empty cache when the affected bundles changes. That is, add a custom submit callback for mymodule_admin_settings() and check what bundles changes over the previous settings.

Tip to Empty the cache:

$cid = "field_info:bundle_extra:$entity_type:$bundle";
cache_clear_all($cid, 'cache_field', true);

You may prefer to empty the cache for all bundles. In this case, $cid is the common prefix for all bundles:

$cid = "field_info:bundle_extra:$entity_type";
  • It is not what I am asking. I already check this at the beggining of the hook_node_view implementation (.....).
    – Alfonso_MA
    Commented Sep 30, 2013 at 18:50
  • Sorry I read too fast and understood other thing. I'll Update my answer to actually answer.
    – jonhattan
    Commented Oct 1, 2013 at 8:43
  • I solved it with field_cache_clear() in the submit function of the configuration form. Thanks a lot!!!
    – Alfonso_MA
    Commented Oct 1, 2013 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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