function tripal_get_field_formatters

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

Retrieves a list of TripalFieldFormatters.

The TripalFieldFormatter 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 TripalFieldFormatter class.

Return value

A list of TripalFieldFormatter names.

Related topics

1 call to tripal_get_field_formatters()
tripal_field_formatter_info in tripal/includes/tripal.fields.inc
Implements hook_field_formatter_info().

File

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

Code

function tripal_get_field_formatters() {
  $formatters = 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, '/.*_formatter\.inc$/');
    // Iterate through the fields, include the file and run the info function.
    foreach ($field_files as $file) {
      $formatter_type = $file->name;
      $field_type = preg_replace('/(^.*)_formatter/', '$1', $formatter_type);
      module_load_include('inc', $module, 'includes/TripalFields/' . $field_type . '/' . $formatter_type);
      if (class_exists($formatter_type) and is_subclass_of($formatter_type, 'TripalFieldFormatter')) {
        $formatters[] = $formatter_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, '/.*_formatter\.inc$/');
    foreach ($field_files as $file) {
      $formatter_type = $file->name;
      $field_type = preg_replace('/(^.*)_formatter/', '$1', $formatter_type);
      $file_path = realpath(".") . '/' . $library_path . '/' . $field_type . '/' . $formatter_type . '.inc';
      if (file_exists($file_path)) {
        require_once ($file_path);
        if (class_exists($formatter_type) and is_subclass_of($formatter_type, 'TripalFieldFormatter')) {
          $formatters[] = $formatter_type;
        }
      }
    }
  }
  return $formatters;
}