views_natural_sort.views.inc 1.31 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php
/**
 * @file
 * Views related hooks.
 *
 * Automatically included by views. Because of the nature of this module this
 * is most of the code.
 */

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
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['field']['field']) && in_array($view_field_data['field']['field'], $schema_fields[$table])) || in_array($view_field, $schema_fields[$table])) &&
        $view_field_data['sort']['handler'] == 'views_handler_sort') {
        // 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
}