0

I have a drupal 7 site with the most recent updates to core and the views module. I am trying to build a view to show three pieces of content (training events) that should display the three most recent pieces of content, based on the date field set by the user corresponding to the date of a training event (i.e. the input date set by the user, not the date of the content's creation). The date field to set to accept start and end times to show the duration of the event.

The view is based on the content type with the date field and I am trying to implement a sort criteria set on the date field in descending order. The issue I'm having is that the dates do not order as expected: the ordering that is output is as follows: March 7th, 2019; February 2nd, 2019; and then September 27th, 2016. The ordering is also incorrect for an ascending sort, with September 27th, 2016 followed by September 5th, 2016, and then February 2nd, 2019. The sort order seems to be incorrect regardless of which field I base sort ordering on (start date or end date), so I'm not sure what's going on here. I don't have the option to specify a granularity, so I'm not sure which value the dates are actually being ordered by. The ordering seems to disregard the ordering of months and individual dates, (e.g. ordering March before February in descending order, then ordering September 16th, 2016 before September 5th, 2016 in ascending order), so I'm not sure which value in the date the view is actually being sorted by. Any advice on how to approach this would be greatly appreciated.

Here is the export of the view:

$view = new view();
$view->name = 'upcoming_training_events';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Upcoming Training Events';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Upcoming Training Events';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
  'field_date_of_training' => 'field_date_of_training',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'field_date_of_training' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['text'] = '[title]';
$handler->display->display_options['fields']['title']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['path'] = '[field_link_to_training]';
$handler->display->display_options['fields']['title']['alter']['absolute'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['link_to_node'] = FALSE;
$handler->display->display_options['fields']['title']['node_in_colorbox_width'] = '600';
$handler->display->display_options['fields']['title']['node_in_colorbox_height'] = '600';
$handler->display->display_options['fields']['title']['node_in_colorbox_rel'] = '';
/* Field: Content: Training Description */
$handler->display->display_options['fields']['field_training_description']['id'] = 'field_training_description';
$handler->display->display_options['fields']['field_training_description']['table'] = 'field_data_field_training_description';
$handler->display->display_options['fields']['field_training_description']['field'] = 'field_training_description';
/* Field: Content: Date of Training */
$handler->display->display_options['fields']['field_date_of_training']['id'] = 'field_date_of_training';
$handler->display->display_options['fields']['field_date_of_training']['table'] = 'field_data_field_date_of_training';
$handler->display->display_options['fields']['field_date_of_training']['field'] = 'field_date_of_training';
$handler->display->display_options['fields']['field_date_of_training']['settings'] = array(
  'format_type' => 'long',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
  'show_remaining_days' => 0,
);
/* Field: Content: Link to Training */
$handler->display->display_options['fields']['field_link_to_training']['id'] = 'field_link_to_training';
$handler->display->display_options['fields']['field_link_to_training']['table'] = 'field_data_field_link_to_training';
$handler->display->display_options['fields']['field_link_to_training']['field'] = 'field_link_to_training';
$handler->display->display_options['fields']['field_link_to_training']['label'] = '';
$handler->display->display_options['fields']['field_link_to_training']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_link_to_training']['click_sort_column'] = 'url';
$handler->display->display_options['fields']['field_link_to_training']['delta_offset'] = '0';
$handler->display->display_options['fields']['field_link_to_training']['multi_type'] = 'ul';
/* Sort criterion: Content: Date of Training -  start date (field_date_of_training) */
$handler->display->display_options['sorts']['field_date_of_training_value']['id'] = 'field_date_of_training_value';
$handler->display->display_options['sorts']['field_date_of_training_value']['table'] = 'field_data_field_date_of_training';
$handler->display->display_options['sorts']['field_date_of_training_value']['field'] = 'field_date_of_training_value';
$handler->display->display_options['sorts']['field_date_of_training_value']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'upcoming_training' => 'upcoming_training',
);

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');

UPDATE

Per comment request here are the results from drush pml grep|date Seems to be a conflict between date and commerce_cart

PHP Fatal error:  Only variables can be passed by reference in /var/www/html/phisigmarho.org/sites/all/modules/commerce/modules/cart/commerce_cart.module on line 1344
PHP Stack trace:
PHP   1. {main}() /home/nizzok/.composer/vendor/drush/drush/drush.php:0
PHP   2. drush_main() /home/nizzok/.composer/vendor/drush/drush/drush.php:11
PHP   3. Drush\Boot\BaseBoot->bootstrap_and_dispatch() /home/nizzok/.composer/vendor/drush/drush/drush.php:70
PHP   4. drush_bootstrap_to_phase() /home/nizzok/.composer/vendor/drush/drush/lib/Drush/Boot/BaseBoot.php:56
PHP   5. drush_bootstrap() /home/nizzok/.composer/vendor/drush/drush/includes/bootstrap.inc:429
PHP   6. Drush\Boot\DrupalBoot7->bootstrap_drupal_full() /home/nizzok/.composer/vendor/drush/drush/includes/bootstrap.inc:313
PHP   7. drupal_bootstrap() /home/nizzok/.composer/vendor/drush/drush/lib/Drush/Boot/DrupalBoot7.php:74
PHP   8. _drupal_bootstrap_full() /var/www/html/phisigmarho.org/includes/bootstrap.inc:2523
PHP   9. module_load_all() /var/www/html/phisigmarho.org/includes/common.inc:5267
PHP  10. drupal_load() /var/www/html/phisigmarho.org/includes/module.inc:24
Drush command terminated abnormally due to an unrecoverable error.   [error]
Error: Only variables can be passed by reference in
/var/www/html/phisigmarho.org/sites/all/modules/commerce/modules/cart/commerce_cart.module,
line 1344
  • Could you post and export of your view? – undersound Jan 15 '17 at 22:02
  • update text with the view export. – nizz0k Jan 16 '17 at 6:23
  • Could you show the output of: drush pml | grep date – undersound Jan 16 '17 at 20:43
0

Could you try this view.

$view = new view();
$view->name = 'upcoming_training_events';
$view->description = '';
$view->tag = 'default';
$view->base_table = 'node';
$view->human_name = 'Upcoming Training Events';
$view->core = 7;
$view->api_version = '3.0';
$view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */

/* Display: Master */
$handler = $view->new_display('default', 'Master', 'default');
$handler->display->display_options['title'] = 'Upcoming Training Events';
$handler->display->display_options['use_more_always'] = FALSE;
$handler->display->display_options['access']['type'] = 'perm';
$handler->display->display_options['cache']['type'] = 'none';
$handler->display->display_options['query']['type'] = 'views_query';
$handler->display->display_options['exposed_form']['type'] = 'basic';
$handler->display->display_options['pager']['type'] = 'some';
$handler->display->display_options['pager']['options']['items_per_page'] = '5';
$handler->display->display_options['pager']['options']['offset'] = '0';
$handler->display->display_options['style_plugin'] = 'table';
$handler->display->display_options['style_options']['columns'] = array(
  'title' => 'title',
  'field_date_of_training' => 'field_date_of_training',
);
$handler->display->display_options['style_options']['default'] = '-1';
$handler->display->display_options['style_options']['info'] = array(
  'title' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
  'field_date_of_training' => array(
    'sortable' => 0,
    'default_sort_order' => 'asc',
    'align' => '',
    'separator' => '',
    'empty_column' => 0,
  ),
);
/* Field: Content: Title */
$handler->display->display_options['fields']['title']['id'] = 'title';
$handler->display->display_options['fields']['title']['table'] = 'node';
$handler->display->display_options['fields']['title']['field'] = 'title';
$handler->display->display_options['fields']['title']['label'] = '';
$handler->display->display_options['fields']['title']['alter']['text'] = '[title]';
$handler->display->display_options['fields']['title']['alter']['make_link'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['path'] = '[field_link_to_training]';
$handler->display->display_options['fields']['title']['alter']['absolute'] = TRUE;
$handler->display->display_options['fields']['title']['alter']['word_boundary'] = FALSE;
$handler->display->display_options['fields']['title']['alter']['ellipsis'] = FALSE;
$handler->display->display_options['fields']['title']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['title']['link_to_node'] = FALSE;
$handler->display->display_options['fields']['title']['node_in_colorbox_width'] = '600';
$handler->display->display_options['fields']['title']['node_in_colorbox_height'] = '600';
$handler->display->display_options['fields']['title']['node_in_colorbox_rel'] = '';
/* Field: Content: Training Description */
$handler->display->display_options['fields']['field_training_description']['id'] = 'field_training_description';
$handler->display->display_options['fields']['field_training_description']['table'] = 'field_data_field_training_description';
$handler->display->display_options['fields']['field_training_description']['field'] = 'field_training_description';
/* Field: Content: Date of Training */
$handler->display->display_options['fields']['field_date_of_training']['id'] = 'field_date_of_training';
$handler->display->display_options['fields']['field_date_of_training']['table'] = 'field_data_field_date_of_training';
$handler->display->display_options['fields']['field_date_of_training']['field'] = 'field_date_of_training';
$handler->display->display_options['fields']['field_date_of_training']['settings'] = array(
  'format_type' => 'long',
  'fromto' => 'both',
  'multiple_number' => '',
  'multiple_from' => '',
  'multiple_to' => '',
  'show_remaining_days' => 0,
);
/* Field: Content: Link to Training */
$handler->display->display_options['fields']['field_link_to_training']['id'] = 'field_link_to_training';
$handler->display->display_options['fields']['field_link_to_training']['table'] = 'field_data_field_link_to_training';
$handler->display->display_options['fields']['field_link_to_training']['field'] = 'field_link_to_training';
$handler->display->display_options['fields']['field_link_to_training']['label'] = '';
$handler->display->display_options['fields']['field_link_to_training']['element_label_colon'] = FALSE;
$handler->display->display_options['fields']['field_link_to_training']['click_sort_column'] = 'url';
$handler->display->display_options['fields']['field_link_to_training']['delta_offset'] = '0';
$handler->display->display_options['fields']['field_link_to_training']['multi_type'] = 'ul';
/* Sort criterion: Content: Date of Training -  start date (field_date_of_training) */
$handler->display->display_options['sorts']['field_date_of_training_value']['id'] = 'field_date_of_training_value';
$handler->display->display_options['sorts']['field_date_of_training_value']['table'] = 'field_data_field_date_of_training';
$handler->display->display_options['sorts']['field_date_of_training_value']['field'] = 'field_date_of_training_value';
$handler->display->display_options['sorts']['field_date_of_training_value']['order'] = 'DESC';
/* Filter criterion: Content: Published */
$handler->display->display_options['filters']['status']['id'] = 'status';
$handler->display->display_options['filters']['status']['table'] = 'node';
$handler->display->display_options['filters']['status']['field'] = 'status';
$handler->display->display_options['filters']['status']['value'] = 1;
$handler->display->display_options['filters']['status']['group'] = 1;
$handler->display->display_options['filters']['status']['expose']['operator'] = FALSE;
/* Filter criterion: Content: Type */
$handler->display->display_options['filters']['type']['id'] = 'type';
$handler->display->display_options['filters']['type']['table'] = 'node';
$handler->display->display_options['filters']['type']['field'] = 'type';
$handler->display->display_options['filters']['type']['value'] = array(
  'upcoming_training' => 'upcoming_training',
);
$handler->display->display_options['filters']['type']['group'] = 1;
/* Filter criterion: Content: Date of training (field_date_of_training) */
$handler->display->display_options['filters']['field_date_of_training_value']['id'] = 'field_date_of_training_value';
$handler->display->display_options['filters']['field_date_of_training_value']['table'] = 'field_data_field_date_of_training';
$handler->display->display_options['filters']['field_date_of_training_value']['field'] = 'field_date_of_training_value';
$handler->display->display_options['filters']['field_date_of_training_value']['operator'] = '>';
$handler->display->display_options['filters']['field_date_of_training_value']['group'] = 1;
$handler->display->display_options['filters']['field_date_of_training_value']['default_date'] = 'now';

/* Display: Block */
$handler = $view->new_display('block', 'Block', 'block');
  • is this possible to configure through the UI? or should I throw together a module for this fix? It does seems to be related to a problem with the drupal_alter function. I haven't had time to look at this in depth yet. – nizz0k Jan 18 '17 at 8:40
  • You can import this code at example.com/admin/structure/views/import. Please make sure to backup your original view – undersound Jan 18 '17 at 9:01
  • Sorry, got reprioritized. I tried the view import and it failed without telling me why. I will have to look at the view in an editor and see if I can figure out what's wrong – nizz0k Feb 3 '17 at 11:56
  • Nothing in your apache/watchdog logs? – undersound Feb 3 '17 at 12:03
  • I'm going to poke around now. – nizz0k Feb 3 '17 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.