You are here

function _better_statistics_get_custom_fields_by_module in Better Statistics 7

Returns arrays of fields keyed by the module that declares them. In addition, this function will attempt to apply sensible views handlers. This should be the only function used to get declared fields.

Return value

Arrays of declared statistics fields keyed by their declaring module.

9 calls to _better_statistics_get_custom_fields_by_module()
better_statistics_disable_fields in ./better_statistics.admin.inc
Disables a list of statistics fields.
better_statistics_enable_fields in ./better_statistics.admin.inc
Enables a list of statistics fields.
drush_better_statistics_stats_dis in ./better_statistics.drush.inc
Drush command callback for stats-dis.
drush_better_statistics_stats_en in ./better_statistics.drush.inc
Drush command callback for stats-en.
drush_better_statistics_stats_ls in ./better_statistics.drush.inc
Drush command callback for stats-ls.

... See full list

File

./better_statistics.admin.inc, line 543
Admin and config code for the Better Statistics module.

Code

function _better_statistics_get_custom_fields_by_module() {
  $declared = array();

  // Load all Statistics API inc files.
  $api_info = _better_statistics_include_handlers();
  foreach (module_implements('better_statistics_fields') as $module) {
    $fields = module_invoke($module, 'better_statistics_fields');
    foreach ($fields as $field => &$data) {

      // Try to provide a default title.
      if (!isset($data['views_field']['title'])) {
        $data['views_field']['title'] = $field;
      }

      // Try to provide a default help text.
      if (!isset($data['views_field']['help'])) {
        $data['views_field']['help'] = isset($data['schema']['description']) ? $data['schema']['description'] : '';
      }

      // Unless explicitly told not to, make our best guesses on Views handlers.
      if ($data['views_field']) {
        $guesses = _better_statistics_get_views_handlers($data['schema']);
        if ($guesses) {
          $data['views_field'] += $guesses;
        }
        else {
          $data['views_field'] = FALSE;
        }
      }

      // Include the path to the file containing the API callback. If this isn't
      // set, the callback is available anywhere Drupal is bootstrapped.
      if (isset($api_info[$module]['file_required'])) {
        $data['_file'] = $api_info[$module]['file_required'];
      }
    }

    // Return the fields, now with Views API defaults, keyed by the module.
    $declared[$module] = $fields;
  }
  return $declared;
}