summaryrefslogtreecommitdiffstats
path: root/views_natural_sort.views.inc
blob: 5bcdda184de9719b61ce0e107e0312cfa40c34cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php

/**
 * @file
 * Views related hooks.
 *
 * Automatically included by views. Because of the nature of this module this
 * is most of the code.
 */

/**
 *
 */
function views_natural_sort_views_data_alter(&$views_data) {
  $supported_entity_properties = views_natural_sort_get_supported_entity_properties();
  $schema_fields = array();
  foreach ($supported_entity_properties as $entity => $properties) {
    foreach ($properties as $property => $schema_info) {
      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']) &&
        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]))) {
        // 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';
      }
    }
  }
}