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

3 4 5 6 7 8 9 10
/**
 * @file
 * Views related hooks.
 *
 * Automatically included by views. Because of the nature of this module this
 * is most of the code.
 */

11 12 13
/**
 *
 */
14 15 16
function views_natural_sort_views_data_alter(&$views_data) {
  $supported_entity_properties = views_natural_sort_get_supported_entity_properties();
  $schema_fields = array();
17 18
  foreach ($supported_entity_properties as $entity => $properties) {
    foreach ($properties as $property => $schema_info) {
19 20 21 22 23 24 25 26 27 28 29 30
      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']) &&
31 32 33 34
        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]))) {
35 36 37
        // 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';
38 39 40
      }
    }
  }
41
}