You are here

function _loft_data_grids_get_exporter_names in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 loft_data_grids.module \_loft_data_grids_get_exporter_names()

Return an array of Exporter classnames dynamically loaded and cached

Return value

array

Related topics

1 call to _loft_data_grids_get_exporter_names()
loft_data_grids_export_info in ./loft_data_grids.module
Return an array of exporters info

File

./loft_data_grids.module, line 78
Base module file for loft_data_grids

Code

function _loft_data_grids_get_exporter_names() {
  $exporters =& drupal_static(__FUNCTION__, array());
  if (empty($exporters)) {
    if ($cache = cache_get('loft_data_grids:exporters', 'cache')) {
      $exporters = empty($cache->data) ? NULL : $cache->data;
    }
    else {

      // Set the default values
      $exporters = array();
      $cache = (object) array(
        'data' => array(),
      );
    }
    if (empty($exporters)) {
      $info = loft_data_grids_info();

      // This is a protection against fatal errors when we include the $path.
      // This could happen on an upgrade from 1.x to 2.x
      if ($info['loaded']) {
        $possible = file_scan_directory($info['path'] . '/src', '/\\.php$/');
        foreach ($possible as $path => $data) {
          $class = loft_data_grids_ns($data->name);
          if (!class_exists($class) && !interface_exists($class)) {
            include_once $path;
          }
          if (in_array(loft_data_grids_ns('ExporterInterface'), class_implements($class))) {
            $class = new \ReflectionClass($class);
            if (!$class
              ->isAbstract()) {
              $exporters[] = $data->name;
            }
          }
        }

        // Formatters added by our module.
        $exporters[] = 'DrupalTableExporter';
        cache_set('loft_data_grids:exporters', $exporters, 'cache', CACHE_PERMANENT);
      }
    }
  }
  return $exporters;
}