0

hook_field_formatter_info() and hook_field_widget_info return an array containing a "settings" index. I want to know when is it used. What happens if it is empty, or just omitted?

My formatter and widget for my custom field does have settings. It's just that during widget/formatter definition the settings are not known yet.

2

If the hooks your module implements don't set that array index, the function invoking them will set them to an empty array. See _field_info_collate_types().

  foreach (module_implements('field_widget_info') as $module) {
    $widget_types = (array) module_invoke($module, 'field_widget_info');
    foreach ($widget_types as $name => $widget_info) {
      // Provide defaults.
      $widget_info += array(
        'settings' => array(),
      );
      $info['widget types'][$name] = $widget_info;
      $info['widget types'][$name]['module'] = $module;
    }
  }
  foreach (module_implements('field_formatter_info') as $module) {
    $formatter_types = (array) module_invoke($module, 'field_formatter_info');
    foreach ($formatter_types as $name => $formatter_info) {
      // Provide defaults.
      $formatter_info += array(
        'settings' => array(),
      );
      $info['formatter types'][$name] = $formatter_info;
      $info['formatter types'][$name]['module'] = $module;
    }
  }

It is then up to the module implementing those hooks, and any related one, to correctly handle the values for that array index, even in the case another module changes it to a value the module is not expecting.

| improve this answer | |
  • Does any part of core depend on 'settings'? (my module doesn't). tnx – hkoosha Jun 15 '13 at 12:43
  • Not that I know of. It's the module implementing the formatter or the widget that depends from that, eventually. There is the Field UI module that could use that array index, but I think it just passes it to the necessary hooks. – kiamlaluno Jun 15 '13 at 15:31

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.