hook_widget_settings(): How to only add settings for certain field types?

We encourage users to post events happening in the community to the community events group on https://www.drupal.org.
xjm's picture

The Content Taxonomy module provides an option to indent child terms in its select list in the same way that the core taxonomy module does. This option is a checkbox in content_taxonomy_options_widget_settings(), thus:

<?php
    $form
['settings']['show_depth'] = array(
       
'#type' => 'checkbox',
       
'#title' => t('Indent child terms with \' - \' signs'),
       
'#default_value' => is_numeric($widget['show_depth']) ? $widget['show_depth'] : 1,
       
'#description' => t('If this option is checked, a hierarchy gets visualized by indenting child terms, otherwise it\'s a flat list'),
    );
?>

Unfortunately, since this is added with hook_widget_settings() and not hook_field_settings(), this option is not available when using a custom widget (like that of the multiselect module).

Now, if I simply implement hook_widget_settings() in the second module with a clone of content_taxonomy_options_widget_settings(), it works just fine with no additional changes. However, that results in the settings fieldset appearing on the configuration form of every field that uses the second module's widget, not just content taxonomy fields. Unfortunately, hook_widget_settings() doesn't get any information about the field, so I have no way of restricting it to content taxonomy fields only. So:

Is there any way to get the field type in hook_widget_settings() using the API (and is this a good idea?) If not, what would you suggest instead?