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
  • 1
    Why not try it and find out? :)
    – Clive
    Jun 13, 2013 at 14:52
  • @Clive It's a little bit complicated! Maybe you could look at drupal.org/sandbox/lo2y4/2018089‎ if you had time.
    – hkoosha
    Jun 14, 2013 at 0:52

1 Answer 1

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.

2
  • Does any part of core depend on 'settings'? (my module doesn't). tnx
    – hkoosha
    Jun 15, 2013 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.
    – apaderno
    Jun 15, 2013 at 15:31

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.