- Issue created by @joelpittet
- 🇨🇦Canada joelpittet Vancouver
I will postpone this on 🐛 Last read comment field/filter/argument uses still the node.changed instead of node_field_data.changed column Needs work because it will likely conflict.
But a workaround in the mean time if anybody else needs this for table click sorting.
modules/custom/CUSTOM_MODULE/CUSTOM_MODULE.views.inc
/** * Implements hook_views_data_alter(). */ function CUSTOM_MODULE_views_data_alter(array &$data):void { // Replace the core comment CES "last updated" sort handler with our NULL-safe version. if (isset($data['comment_entity_statistics']['last_updated']['sort'])) { $data['comment_entity_statistics']['last_updated']['field']['id'] = 'comment_ces_last_updated_nullsafe'; $data['comment_entity_statistics']['last_updated']['sort']['id'] = 'comment_ces_last_updated_nullsafe'; } }
modules/custom/CUSTOM_MODULE/src/Plugin/views/field/NullSafeStatisticsLastUpdated.php
namespace Drupal\CUSTOM_MODULE\Plugin\views\field; use Drupal\views\Attribute\ViewsField; use Drupal\views\Plugin\views\field\Date; /** * NULL‑safe field for newer of last comment / entity updated. */ #[ViewsField('comment_ces_last_updated_nullsafe')] class NullSafeStatisticsLastUpdated extends Date { public function query() { $this->ensureMyTable(); $entity_type = \Drupal::entityTypeManager()->getDefinition($this->getEntityType()); $entity_data_table = $this->query->ensureTable($entity_type->getDataTable(), $this->relationship); $this->field_alias = $this->query->addField( NULL, "GREATEST({$entity_data_table}.changed, COALESCE({$this->tableAlias}.last_comment_timestamp, {$entity_data_table}.changed))", $this->tableAlias . '_' . $this->field ); } }
modules/custom/CUSTOM_MODULE/src/Plugin/views/sort/NullSafeStatisticsLastUpdated.php
namespace Drupal\CUSTOM_MODULE\Plugin\views\sort; use Drupal\views\Attribute\ViewsSort; use Drupal\views\Plugin\views\sort\Date; /** * NULL‑safe sort for newer of last comment / entity updated. */ #[ViewsSort('comment_ces_last_updated_nullsafe')] class NullSafeStatisticsLastUpdated extends Date { public function query() { $this->ensureMyTable(); $entity_type = \Drupal::entityTypeManager()->getDefinition($this->getEntityType()); $entity_data_table = $this->query->ensureTable($entity_type->getDataTable(), $this->relationship); $this->field_alias = $this->query->addOrderBy( NULL, "GREATEST({$entity_data_table}.changed, COALESCE({$this->tableAlias}.last_comment_timestamp, {$entity_data_table}.changed))", $this->options['order'], $this->tableAlias . '_' . $this->field ); } }
- Merge request !12975#3540867 - Add tests for comment statistics sort with and without comment supported node types → (Open) created by joelpittet
- 🇨🇦Canada joelpittet Vancouver
Add regression tests for comment statistics sort with and without comment supported node types, so we don't need to do that later.
- 🇨🇦Canada joelpittet Vancouver
This test failure seems unrelated — it’s complaining about a missing schema definition for click_sort_column, but that property is already used in many places in core. A bit annoying to have to fix this, and I’m not sure whether it should be addressed here or spun off into a separate follow-up, though a quick issue search talks about it here 🌱 Make views consistent in code, schema, tests, and APIs Needs review .
There should be no errors in configuration 'views.view.test_comment_last_updated_click_sort'. Errors:
├ Schema key views.view.test_comment_last_updated_click_sort:display.default.display_options.fields.comment_entity_statistics_last_updated.click_sort_column failed with: missing schema