Hi,

wondering if nobody else has this problem. Run Drupal 8.3.3, but had this problem in previous versions too.

I create a node type "news"
Add a date - field
Set type to multilingual (de, en)

Create various news nodes with different dates
Create translations for all news nodes

Add a new views -> type "news"
Filter Criteria -> Translation Language
Sort Criteria -> Our date field

If you check the sorting of the translation language, its very wild and make no sense at all. You can replace the date field with a number field, the sorting didnt work here too?!

Any Ideas?
Best, Alex

Comments

Alex_schwarz created an issue. See original summary.

Alex_schwarz’s picture

Okay if date field ist set to translatable sorting works... but why should it be necessary to translate the field? A news date doesn't change just because of the translation language. Could be optimized.

Alex_schwarz’s picture

Priority: Major » Normal
mustanggb’s picture

Project: Views (for Drupal 7) » Drupal core
Version: 8.x-3.x-dev » 8.3.x-dev
Component: Miscellaneous » views.module

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dbgilbert’s picture

Can confirm the exact same problem. Have a view filtering by language with a (non-translatable) date field as the only sort parameter. Results in inconsistent (random?) sorting for the translated content. Problem goes away if the date field is translatable but obviously that's not a desirable solution in many cases.

dbgilbert’s picture

The sorting issue goes away if the Rendering Language of the view is set to "Interface text language selected for page" rather than "Content Language of View Row". This then introduces duplicate results (which I believe already has its own issue?), but enabling "Distinct" in the query options resolves that. Not a solution to the underlying issue, but perhaps evidence for what causes problem and a possible way to sidestep it.

julienjoye’s picture

@dbgilbert Actually yes, it does sort the contents the right way with you trick. But untranslated contents are shown, (in their source language), which is not suitable for many cases. As soon as you FILTER the contents on language with the active language (to get only those who are translated), the sorting criteria is missing something, and the results are randomly sorted. I definitely confirm the issue.

Ok Note :
I use @dbgilbert trick, with this custom code that excludes non translated contents :

/**
 * Implements hook_views_pre_render().
 */
function my_module_views_pre_render(ViewExecutable $view) {
  if ($view->id() == 'my_view') {
    $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId();
    $result = $view->result;
    foreach ($result as $i => $row) {
      $entity = $row->_entity;
      if (!$entity->hasTranslation($langcode)) {
        unset($view->result[$i]);
      }
    }
  }
}

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Active » Closed (outdated)
Issue tags: -views sorting, -multilingual +Bug Smash Initiative

@Alex_schwarz, Thank you for reporting this problem. We rely on issue reports like this to improve Drupal core.

I tested this on 9.4.x, standard install and was not able to reproduce this error. I followed the steps given in the Issue Summary although the second language was Italian. The nodes I created had different dates in each language. I filterer on no language, Italian and English, and in all cases the view was filtered correctly and in the correct date order.

If you are experiencing this problem on a supported version of Drupal reopen the issue, by setting the status to 'Active', and provide complete steps to reproduce the issue (starting from "Install Drupal core").

Thanks!