You are here

function references_dialog_references_dialog_search_attachables in References dialog 7

Implements hook_references_dialog_search_attachables().

File

./references_dialog.module, line 245
This the main module file.

Code

function references_dialog_references_dialog_search_attachables() {
  $fields = field_info_fields();
  $dialog_widgets = references_dialog_widgets();
  $applicable_instances = array();
  foreach ($fields as $field_name => $field) {
    foreach ($field['bundles'] as $entity_type => $bundles) {
      foreach ($bundles as $bundle_name) {
        $instance = field_info_instance($entity_type, $field_name, $bundle_name);
        $widget_type = $instance['widget']['type'];
        if (in_array($widget_type, array_keys($dialog_widgets)) && $instance['widget']['settings']['references_dialog_search']) {

          // If the entity type is specified, in the declaration, add it here.
          $dialog_widget = $dialog_widgets[$widget_type];
          if (isset($dialog_widget['entity_type'])) {
            $attachable_type = $dialog_widget['entity_type'];
          }
          elseif (isset($dialog_widgets[$instance['widget']['type']]['type_callback'])) {
            $attachable_type = $dialog_widget['type_callback']($instance, $field);
          }
          if (isset($attachable_type)) {
            $attachable_name = _references_dialog_get_attachable_name_by_instance($instance);
            $applicable_instances[$attachable_type][$attachable_name] = array(
              'label' => $instance['bundle'] . ': ' . $instance['label'],
              'query' => 'references_dialog_field_attachable_query',
              'widget' => $dialog_widget,
            );
          }
        }
      }
    }
  }
  return $applicable_instances;
}