function tripal_get_field_types

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

Retrieves a list of TripalField types.

The TripalField classes can be added by a site developer and should be placed in the [module]/includes/TripalFields directory. Tripal will support any field as long as it is in this directory and extends the TripalField class. To support dynamic inclusion of new fields this function will look for TripalField class files and return a type for each one.

Return value

A list of TripalField names.

Related topics

3 calls to tripal_get_field_types()
tripal_field_info in tripal/includes/tripal.fields.inc
Implements hook_field_info().
tripal_field_views_data in tripal/includes/tripal.fields.inc
Implements hook_field_views_data();
tripal_views_data_alter in tripal/tripal.views.inc
Implements hook views_data_alter()

File

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

Code

function tripal_get_field_types() {
  $types = 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/TripalFields/ directory.
    $fields_path = drupal_get_path('module', $module) . '/includes/TripalFields';
    $field_files = file_scan_directory($fields_path, '/.*\.inc$/');
    // Iterate through the fields, include the file and run the info function.
    foreach ($field_files as $file) {
      // Ignore the formatter and widget classes for now.
      if (preg_match('/_formatter|_widget/', $file->name)) {
        continue;
      }
      $field_type = $file->name;
      module_load_include('inc', $module, 'includes/TripalFields/' . $field_type . '/' . $field_type);
      if (class_exists($field_type) and is_subclass_of($field_type, 'TripalField')) {
        $types[] = $field_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, '/.*\.inc$/');
    foreach ($field_files as $file) {
      // Ignore the formatter and widget classes for now.
      if (preg_match('/_formatter|_widget/', $file->name)) {
        continue;
      }
      $field_type = $file->name;
      $file_path = realpath(".") . '/' . $library_path . '/' . $field_type . '/' . $field_type . '.inc';
      if (file_exists($file_path)) {
        require_once ($file_path);
        if (class_exists($field_type) and is_subclass_of($field_type, 'TripalField')) {
          $types[] = $field_type;
        }
      }
    }
  }
  return $types;
}