views_natural_sort.views.inc 1.34 KB
Newer Older
1
<?php
2

3 4
/**
 * @file
5
 * Views related hooks for the Views Natural Sort module.
6 7
 */

8
/**
9
 * Implements hook_views_data_alter().
10
 */
11 12 13
function views_natural_sort_views_data_alter(&$views_data) {
  $supported_entity_properties = views_natural_sort_get_supported_entity_properties();
  $schema_fields = array();
14 15
  foreach ($supported_entity_properties as $entity => $properties) {
    foreach ($properties as $property => $schema_info) {
16 17 18 19 20 21 22 23 24 25 26 27
      if (empty($schema_fields[$schema_info['base_table']])) {
        $schema_fields[$schema_info['base_table']] = array();
      }
      $schema_fields[$schema_info['base_table']][] = $schema_info['schema_field'];
    }
  }
  foreach ($views_data as $table => &$data) {
    if (empty($schema_fields[$table])) {
      continue;
    }
    foreach ($data as $view_field => &$view_field_data) {
      if (isset($view_field_data['field']) &&
28 29 30 31
        isset($view_field_data['sort']) &&
        $view_field_data['sort']['handler'] == 'views_handler_sort' &&
        ((isset($view_field_data['field']['field']) && in_array($view_field_data['field']['field'], $schema_fields[$table])) ||
          in_array($view_field, $schema_fields[$table]))) {
32 33 34
        // We've verified that this is a perfect candidate to add our sort
        // handler to.
        $view_field_data['sort']['handler'] = 'views_natural_sort_handler_sort';
35 36 37
      }
    }
  }
38
}