function tripal_get_field_widgets

3.x tripal.fields.api.inc tripal_get_field_widgets()

Retrieves a list of TripalFieldWidgets.

The TripalFieldWidget classes can be added by a site developer and should be placed in the [module]/includes/TripalFields directory. Tripal will support any widget as long as it is in this directory and extends the TripalFieldWidget class.

Return value

A list of TripalFieldWidget names.

Related topics

1 call to tripal_get_field_widgets()
tripal_field_widget_info in tripal/includes/tripal.fields.inc
Implements hook_field_widget_info();

File

tripal/api/tripal.fields.api.inc, line 189
Provides an application programming interface (API) for working with fields attached to TripalEntity content types (bundles).

Code

function tripal_get_field_widgets() {
  $widgets = array();

  $modules = module_list(TRUE);
  foreach ($modules as $module) {

    // Only run this for modules that are enabled.
    if (!module_exists($module)) {
      continue;
    }

    // Find all of the files in the tripal_chado/includes/fields directory.
    $fields_path = drupal_get_path('module', $module) . '/includes/TripalFields';
    $field_files = file_scan_directory($fields_path, '/.*_widget\.inc$/');
    // Iterate through the fields, include the file and run the info function.
    foreach ($field_files as $file) {
      $widget_type = $file->name;
      $field_type = preg_replace('/(^.*)_widget/', '$1', $widget_type);
      module_load_include('inc', $module, 'includes/TripalFields/' . $field_type . '/' . $widget_type);
      if (class_exists($widget_type) and is_subclass_of($widget_type, 'TripalFieldWidget')) {
        $widgets[] = $widget_type;
      }
    }
  }

  // If the libraries module is enabled then we want to look for a TripalFields
  // library folder and see if our field exist there.
  if (module_exists('libraries')) {
    $library_path = libraries_get_path('TripalFields');
    $fields_path = realpath(".") . '/' . $library_path;
    $field_files = file_scan_directory($fields_path, '/.*_widget\.inc$/');
    foreach ($field_files as $file) {
      $widget_type = $file->name;
      $field_type = preg_replace('/(^.*)_widget/', '$1', $widget_type);
      $file_path = realpath(".") . '/' . $library_path . '/' . $field_type . '/' . $widget_type . '.inc';
      if (file_exists($file_path)) {
        require_once ($file_path);
        if (class_exists($widget_type) and is_subclass_of($widget_type, 'TripalFieldWidget')) {
          $widgets[] = $widget_type;
        }
      }
    }
  }
  return $widgets;
}