hook_field_extra_fields on node types stored in variable I am developing a module. It adds a button to certain content types:

function mymodule_node_view($node, $view_mode, $langcode) {
  ....
  $node-&gt;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' =&gt; 'checkboxes',
    '#options' =&gt; $options, //node types
    '#default_value' =&gt; 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() {
  $extra_fields=array();
  $mymodule_types = variable_get('mymodule_node_types', array());
  .....
  $display_elements['mymodule_button'] = array(
     ...
    'weight' =&gt; 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.
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";