Updated: Comment 0

Problem/Motivation

Comment entity statistics view plugins are broken and there's no tests.
They are not properly ported to interact with entities other then nodes.
There's no way to detect the name of the "changed" field for entities that implements EntityChangedInterface

Proposed resolution

Probably needs to check that commented entity type implements \Drupal\Core\Entity\EntityChangedInterface and expose this field only for this entity types

Remaining tasks

Fix views integration with comment statistics and cover with tests.

User interface changes

API changes

CommentFileSizeAuthor
#152 2086125-nr-bot_c7h5g0pn.txt90 bytesneeds-review-queue-bot
#148 2086125-nr-bot_turwhi9b.txt5.26 KBneeds-review-queue-bot
#123 interdiff_115-122.txt555 bytescapysara
#115 2086125-115.patch20.94 KBmrinalini9
#111 interdiff_105-111.txt779 bytescapysara
#111 2086125-111.patch20.96 KBcapysara
#105 interdiff_104-105.txt850 bytesravi.shankar
#105 2086125-105.patch18.62 KBravi.shankar
#104 2086125-97-104-interdiff.txt1.81 KBdarvanen
#104 2086125-104.patch18.51 KBdarvanen
#97 interdiff_93-97.txt1.96 KBravi.shankar
#97 2086125-97.patch18.24 KBravi.shankar
#93 interdiff_92-93.txt661 bytesravi.shankar
#93 2086125-93.patch17.93 KBravi.shankar
#92 interdiff_89-92.txt4.7 KBravi.shankar
#92 2086125-92.patch17.93 KBravi.shankar
#89 interdiff_87-89.txt2.58 KBravi.shankar
#89 2086125-89.patch16.3 KBravi.shankar
#87 interdiff_85_87.txt571 bytesameymudras
#87 2086124-87.patch15.6 KBameymudras
#85 2086124-85.patch15.6 KBanchal_gupta
#85 interdiff_71_84-85.txt2.34 KBanchal_gupta
#84 interdiff_71-84.txt615 bytesravi.shankar
#84 2086125-84.patch15.61 KBravi.shankar
#71 2086125-71.patch15.49 KBandypost
#71 interdiff.txt5.45 KBandypost
#68 2086125-68.patch14.44 KBandypost
#68 interdiff.txt1.05 KBandypost
#67 2086125-67.patch14.42 KBandypost
#67 interdiff.txt8.56 KBandypost
#62 2086125_62.patch16.53 KBvsujeetkumar
#62 interdiff_47-62.txt5.03 KBvsujeetkumar
#60 2086125_60.patch16.52 KBvsujeetkumar
#59 interdiff_47-58.txt4.22 KBvsujeetkumar
#58 2086125_58.patch15.94 KBvsujeetkumar
#56 2086125_56.patch15.93 KBvsujeetkumar
#53 comment1.png10.97 KBshimpy
#53 comment.png23.35 KBshimpy
#53 com.png11.15 KBshimpy
#47 2086125-47.patch16.7 KBwebflo
#45 2086125-45.patch16.63 KBwebflo
#34 2086125-34.patch14.85 KBdinesh18
#34 interdiff-25-34.txt1.29 KBdinesh18
#25 interdiff-2086125-22-25.txt7.69 KBmorenstrat
#25 2086125-25.patch15.58 KBmorenstrat
#22 interdiff-2086125-14-22.txt290 bytesmorenstrat
#22 2086125-comment-views-22.patch15.42 KBmorenstrat
#14 2086125-comment-views-14.patch15.5 KBpcambra
#14 interdiff-2086125-12-14.txt1.66 KBpcambra
#12 2086125-comment-views-12.patch15.46 KBpcambra
#7 2086125-comment-views-7.patch16.24 KBandypost
#7 interdiff.txt1.6 KBandypost
#5 2086125-comment-views-5.patch14.64 KBandypost
#5 interdiff.txt3.1 KBandypost
#4 2086125-comment-views-4.patch13.75 KBandypost
#3 2086125-3.patch2.38 KBandypost
#1 views-last_read_comment-2086125-1.patch3.07 KBtanc

Issue fork drupal-2086125

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

tanc’s picture

Status: Active » Needs review
StatusFileSize
new3.07 KB

Simple patch which replaces the node table with node_field_data table to fix the last updated/commented field. The handler for the filter and sort seems to be broken so I couldn't test, will check if there is a separate issue for that.

Let me know if this covers this issue, maybe there are other things I've missed.

The last submitted patch, views-last_read_comment-2086125-1.patch, failed testing.

andypost’s picture

Issue summary: View changes
Status: Needs work » Needs review
StatusFileSize
new2.38 KB

re-roll, seems needs tests

andypost’s picture

Issue summary: View changes
Issue tags: +Needs tests
StatusFileSize
new13.75 KB

New patch:
- "ces" plugns now detects data table of the entity
- added demo view against User entity, to properly check that plugins work with other entities
- filed issue #2380071: No way to add comment field to any entity - you need to create a new comment type to add comment field to other entity

When commented entity has "changed" field then filter should use addWhereExpression() no idea how proceed with that.

I'm using $this->options['relationship'] to get entity type, is that right?

andypost’s picture

StatusFileSize
new3.1 KB
new14.64 KB

Added test and changed view to use node
PS: test is broken somehow

Status: Needs review » Needs work

The last submitted patch, 5: 2086125-comment-views-5.patch, failed testing.

andypost’s picture

Status: Needs work » Needs review
StatusFileSize
new1.6 KB
new16.24 KB

Status: Needs review » Needs work

The last submitted patch, 7: 2086125-comment-views-7.patch, failed testing.

dawehner’s picture

Just a quick review ...

  1. +++ b/core/modules/comment/src/Plugin/views/field/StatisticsLastUpdated.php
    @@ -18,10 +21,67 @@
    +    $entity_type = $this->entityManager
    +      ->getDefinition($this->options['relationship']);
    +
    +    if ($entity_type->isSubclassOf('\Drupal\Core\Entity\EntityChangedInterface')) {
    +      // @todo Find proper column name.
    

    We don't necessarily have to do that, we could also just add that handler manually to the corresponding field in hook_views_data()

  2. +++ b/core/modules/comment/src/Plugin/views/filter/StatisticsLastUpdated.php
    @@ -18,12 +20,61 @@
    +    if ($entity_type->isSubclassOf('\Drupal\Core\Entity\EntityChangedInterface')) {
    +      // @todo Find proper column name.
    +      $entity_data_table = $this->query->ensureTable($entity_type->getDataTable(), $this->relationship);
    

    WIth the technical from above we could just leverage 'real field' here

  3. +++ b/core/modules/comment/src/Plugin/views/filter/StatisticsLastUpdated.php
    --- a/core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
    +++ b/core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
    
    +++ b/core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
    @@ -18,10 +20,58 @@
    +  /**
    +   * Constructs a PluginBase object.
    

    Nope, it constructs a different kind of object.

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 7: 2086125-comment-views-7.patch, failed testing.

pcambra’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
StatusFileSize
new15.46 KB

Plain reroll

Status: Needs review » Needs work

The last submitted patch, 12: 2086125-comment-views-12.patch, failed testing.

pcambra’s picture

Status: Needs work » Needs review
StatusFileSize
new1.66 KB
new15.5 KB

A couple of small fixes, not sure what's the change proposed in #9. Shall we do something like this in CommentViewsData:

foreach ($entities_types as $type => $entity_type) {
  if ($entity_type->isSubclassOf('\Drupal\Core\Entity\EntityChangedInterface')) {
    $data['comment_entity_statistics'][$entity_type]['last_updated'] =...
  }
}

And get rid of StatisticsLastUpdated?

Status: Needs review » Needs work

The last submitted patch, 14: 2086125-comment-views-14.patch, failed testing.

andypost’s picture

sure, makes sense and simplifies a code.

But I stuck with expression that inherited from date plugin #4 (see debug #7)

When commented entity has "changed" field then filter should use addWhereExpression() no idea how proceed with that.

andypost’s picture

gaydabura’s picture

Assigned: Unassigned » gaydabura

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.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.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

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

just_like_good_vibes’s picture

hello,
any update on that issue?
i have Drupal 8.2.2 and I created a view that simply list the Article content type, ordered by "Updated/commented date".
But unfortunately, i'm unable i got the following error :

Column not found: 1054 Unknown column 'node.changed' in 'field list':

the code that creates this error is probably in the file core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php

the SQL query created includes something like "GREATEST(node.changed, comment_entity_statistics.last_comment_timestamp) AS comment_entity_statistics_last_updated"
instead of "GREATEST(node_field_data.changed, comment_entity_statistics.last_comment_timestamp) AS comment_entity_statistics_last_updated"
which would be correct.

any help/explanation appreciated,

best

morenstrat’s picture

Version: 8.2.x-dev » 8.4.x-dev
Assigned: gaydabura » morenstrat
Issue tags: +SprintWeekend2017, +SprintWeekendBerlin
Related issues: +#2429447: Use data table as views base table, if available.
StatusFileSize
new15.42 KB
new290 bytes

The field handler was fixed in #2429447: Use data table as views base table, if available., though with a different approach. I attached an updated patch that applies against the 8.4.x-dev branch.

andypost’s picture

Status: Needs work » Needs review

Run tests

Status: Needs review » Needs work

The last submitted patch, 22: 2086125-comment-views-22.patch, failed testing.

morenstrat’s picture

Assigned: morenstrat » Unassigned
StatusFileSize
new15.58 KB
new7.69 KB

The handler's entity type is not in $this->options['relationship'] anymore. This patch - instead - uses $this->getEntityType() to find out which entity type it relates to. Additionally, the patch replaces the deprecated EntityManager with EntityTypeManager.

morenstrat’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 25: 2086125-25.patch, failed testing.

@rami’s picture

I am using Drupal 8.2.4
Is there a way to solve this issue temporary?
thanks

jonathanshaw’s picture

andypost’s picture

Closed it because duplicates this issue

  1. +++ b/core/modules/comment/src/Tests/Views/CommentStatisticsNodeTest.php
    @@ -0,0 +1,32 @@
    +    debug($view->result);
    

    remove

  2. +++ b/core/modules/views/src/Plugin/views/query/QueryPluginBase.php
    @@ -283,6 +283,10 @@ public function getEntityTableInfo() {
         foreach ((array) $this->view->relationship as $relationship_id => $relationship) {
    +      if (!isset($relationship->definition['base'])) {
    +        debug($relationship->definition);
    +        continue;
    +      }
    

    should be removed

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

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now 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.

jonathanshaw’s picture

#2879923: Unknown column 'node.changed' on filter by "Updated/commented date" has a one line fix for the node filter part of this, should probably be closed as a duplicate of this.

jonathanshaw’s picture

Issue tags: +Novice

Novice work to address #30

dinesh18’s picture

Status: Needs work » Needs review
StatusFileSize
new1.29 KB
new14.85 KB

Here is an updated patch and interdiff implemented as per #30

Status: Needs review » Needs work

The last submitted patch, 34: 2086125-34.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

jonathanshaw’s picture

This filter has been broken for 2 years, but seems to only need a one line fix to get it working for nodes.

How about we reopen #2879923: Unknown column 'node.changed' on filter by "Updated/commented date" , move across a test from this patch, and retitle this issue as "Refactor Comment entity statistics".

Currently this issue is stuck on firstly
#4 / #16:

When commented entity has "changed" field then filter should use addWhereExpression() no idea how proceed with that.

Can you explain more @andypost what the problem is here?

and secondly
#9 add a handler manually to the corresponding field in hook_views_data(), and then use 'real field' in the filter.

cellar door’s picture

@jonathanshaw - I wholly agree! I ran into this issue and found #2879923 which seems to fix the issue, and a simple one line fix for an issue that's been around for years should make its way out, allowing more work on the re-write to occur but allowing the community to not run into the issue.

Happy to help move out the simple fix in the meantime as I'm sure there are a number of people who could use the filter.

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

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now 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.

dillix’s picture

@jonathanshaw, @Cellar Door I think that this issue should be fixed for all entity types, because any entity type can use comment field.

dillix’s picture

#34 works great for me should we reroll it for 8.6?

jonathanshaw’s picture

Status: Needs work » Needs review

let's see

dillix’s picture

Status: Needs review » Needs work

We should go green with testbot to review.

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

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now 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.

andypost’s picture

It still needs work to place test in phpunit, cos this nase class deprecated

webflo’s picture

Status: Needs work » Needs review
StatusFileSize
new16.63 KB

I wrote a new test based on phpunit, works fine so far. But the filter handler fo the views has some issue with config schema. I was not able to save the view if this filter is present.

Status: Needs review » Needs work

The last submitted patch, 45: 2086125-45.patch, failed testing. View results

webflo’s picture

Status: Needs work » Needs review
StatusFileSize
new16.7 KB
jonathanshaw’s picture

@webflo given the earlier comments on this issue, what work do you think is still needed?

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

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Christie Alcidor’s picture

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

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

johne’s picture

I just tested #47 and it worked well for nodes with comments in D8.8

shimpy’s picture

StatusFileSize
new11.15 KB
new23.35 KB
new10.97 KB

I have tested #47 in drupal8.9
It works well.

img

shimpy’s picture

borisson_’s picture

Status: Needs review » Needs work

@shimpy: Please don't add a screenshot that the patch applies, this does not add any information to the system, if the patch wouldn't apply anymore then the testbot will let us know when it's being retested. in #48 there was a question to @webflo about what extra steps are still needed here.

I don't see any new replies from him - but I don't see what else should be needed.

About the actual patch.

  1. +++ b/core/modules/comment/src/Plugin/views/field/StatisticsLastUpdated.php
    @@ -13,10 +16,67 @@
    +      // @todo Find proper column name.
    +      $entity_data_table = $this->query->ensureTable($entity_type->getDataTable(), $this->relationship);
    +      $this->field_alias = $this->query->addField(NULL, "GREATEST(" . $entity_data_table . ".changed, " . $this->tableAlias . ".last_comment_timestamp)", $this->tableAlias . '_' . $this->field);
    

    The proper column name here is something I'm not sure about. Are we sure that this is always changed?

  2. +++ b/core/modules/comment/src/Plugin/views/filter/StatisticsLastUpdated.php
    @@ -13,12 +15,60 @@
    +      // @todo Find proper column name.
    +      $entity_data_table = $this->query->ensureTable($entity_type->getDataTable(), $this->relationship);
    +      $field = 'GREATEST(' . $entity_data_table . '.changed, ' . $this->tableAlias . '.last_comment_timestamp)';
    

    Same here.

  3. +++ b/core/modules/comment/src/Plugin/views/filter/StatisticsLastUpdated.php
    @@ -13,12 +15,60 @@
    +    // @todo This is broken, to proceed with GREATEST() should use
    +    //    \Drupal\views\Plugin\views\query\Sql::addWhereExpression().
    

    We should fix this as well.

  4. +++ b/core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
    @@ -13,10 +15,58 @@
    +      // @todo Find proper column name.
    +      $entity_data_table = $this->query->ensureTable($entity_type->getDataTable(), $this->relationship);
    +      $this->field_alias = $this->query->addOrderBy(NULL, "GREATEST(" . $entity_data_table . ".changed, " . $this->tableAlias . ".last_comment_timestamp)", $this->options['order'], $this->tableAlias . '_' . $this->field);
    

    ^

  5. +++ b/core/modules/comment/tests/src/Functional/Views/CommentStatisticsTest.php
    @@ -0,0 +1,71 @@
    +  /**
    +   * Modules to install.
    +   *
    +   * @var array
    +   */
    

    Can be {@inheritdoc}

vsujeetkumar’s picture

StatusFileSize
new15.93 KB

I have reviewed the comments given in #55 and According to me column name 'changed' should be fine also sql function 'GREATEST()' is working perfect in this patch.

Patch created, Please review.

andypost’s picture

@vsujeetkumar please provide interdiff from latest patch #47

It will be easy to see what's changed

vsujeetkumar’s picture

StatusFileSize
new15.94 KB

Updated Patch after fixed the PHPLintFailed #56

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new4.22 KB

As I mentioned on the #56, I have just worked on comment given by #55, interdiff added Please reivew.

vsujeetkumar’s picture

StatusFileSize
new16.52 KB

Please review.

Status: Needs review » Needs work

The last submitted patch, 60: 2086125_60.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

vsujeetkumar’s picture

Status: Needs work » Needs review
StatusFileSize
new5.03 KB
new16.53 KB

More Test Fixes, Please reivew.

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

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now 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.

gribnif’s picture

#62 works for me. Please test further so that this can finally be committed.

jonathanshaw’s picture

Nice work @vsujeetkumar!

+++ b/core/modules/comment/src/Plugin/views/sort/StatisticsLastUpdated.php
@@ -13,10 +15,56 @@
+    if ($entity_type->entityClassImplements('\Drupal\Core\Entity\EntityChangedInterface')) {
+      // @todo Find proper column name.

#55.1 is right to be concerned about this, as the @todo suggests.

The fact that an entity implements EntityChangedInterface does not guarantee it has a field called 'changed'. In fact, we can't even be sure that a field called 'changed' is a timestamp indicating when the entity was last updated, even if the entity also implements EntityChangedInterface.

I think the best solution is to require the entity to implement EntityChangedInterface, and also to check that the entity type actually has a 'changed' field. I've no idea how to do that.

jonathanshaw’s picture

#2209971: Automatically provide a changed field definition is the issue where one day EntityChangedTrait will standardise the field to be called 'changed', but even then EntityChangedInterface won't guarantee it.

andypost’s picture

Related issues: +#2209971: Automatically provide a changed field definition
StatusFileSize
new8.56 KB
new14.42 KB

Added link for todo according #67

Cleaned-up constructors but as previous patch did not fail it means we missing test coverage,
that's because \Drupal\comment\Plugin\views\field\StatisticsLastUpdated extends Date plugin which require "date_format" stotage in constructor

+++ b/core/modules/comment/src/Plugin/views/field/StatisticsLastUpdated.php
@@ -13,10 +16,65 @@
+  public function __construct(array $configuration, $plugin_id, $plugin_definition, DateFormatter $date_formatter, EntityTypeManagerInterface $entity_type_manager) {
+    parent::__construct(
+      $configuration,
+      $plugin_id,
+      $plugin_definition,
+      $date_formatter,
+      $entity_type_manager->getStorage('date_format')
+    );

it missing "date_format" storage handler

andypost’s picture

StatusFileSize
new1.05 KB
new14.44 KB

Fix CS

jonathanshaw’s picture

+++ b/core/modules/comment/src/Plugin/views/field/StatisticsLastUpdated.php
@@ -17,57 +16,33 @@
+    if ($entity_type->entityClassImplements(EntityChangedInterface::class)) {
+      // @todo Find proper column name. https://www.drupal.org/node/2209971
       $entity_data_table = $this->query->ensureTable($entity_type->getDataTable(), $this->relationship);
       $this->field_alias = $this->query->addField(NULL, "GREATEST(" . $entity_data_table . ".changed, " . $this->tableAlias . ".last_comment_timestamp)", $this->tableAlias . '_' . $this->field);

@andypost do you know a way we can check for the existence of the changed field before adding it?

andypost’s picture

Assigned: Unassigned » andypost

@jonathanshaw \Drupal\Core\Entity\EntityLastInstalledSchemaRepositoryInterface::getLastInstalljonathanshawedDefinition() could help here, trying

andypost’s picture

Assigned: andypost » Unassigned
StatusFileSize
new5.45 KB
new15.49 KB

Kind of it works for me

jonathanshaw’s picture

Nice, so glad you're working on this.

  1. +++ b/core/modules/comment/src/Plugin/views/field/StatisticsLastUpdated.php
    @@ -2,7 +2,9 @@
      * Field handler to display the newer of last comment / node updated.
    

    Should be 'entity' not 'node'.

  2. +++ b/core/modules/comment/src/Plugin/views/field/StatisticsLastUpdated.php
    @@ -13,10 +15,50 @@
    +    $entity_type = $this->entityTypeManager->getDefinition($this->getEntityType());
    +    $base_fields = $this->entityFieldManager->getBaseFieldDefinitions($this->getEntityType());
    +    if ($entity_type->entityClassImplements(EntityChangedInterface::class) && isset($base_fields['changed'])) {
    +      // @todo Lookup changed field in keys https://www.drupal.org/node/2209971
    +      $entity_data_table = $this->query->ensureTable($entity_type->getDataTable(), $this->relationship);
    +      $this->field_alias = $this->query->addField(NULL, "GREATEST(" . $entity_data_table . ".changed, " . $this->tableAlias . ".last_comment_timestamp)", $this->tableAlias . '_' . $this->field);
    +    }
    +    else {
    +      // No changed field on entity so using own table.
    +      $this->field_alias = $this->query->addField(NULL, $this->tableAlias . ".last_comment_timestamp", $this->tableAlias . '_' . $this->field);
    +    }
    

    This will appear to work like it is supposed to, but actually silently be unaware of the changed time, if the entity does not implement EntityChangedInterface. Is this OK?

  3. In CommentViewsData we have
    $data['comment_entity_statistics']['last_updated'] = [
          'title' => $this->t('Updated/commented date'),
          'help' => $this->t('The most recent of last comment posted or entity updated time.'),
          'field' => [
            'id' => 'comment_ces_last_updated',
            'no group by' => TRUE,
          ],
          'sort' => [
            'id' => 'comment_ces_last_updated',
            'no group by' => TRUE,
          ],
          'filter' => [
            'id' => 'comment_ces_last_updated',
          ],
        ];

    Should we wrap this in a conditional so that this handler is only added if there is a changed field?

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

mrpauldriver’s picture

Thank you for working on this. I am no longer seeing any errors.

Be good to see it wrapped up.

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

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

catch’s picture

Priority: Normal » Major
Issue tags: +Bug Smash Initiative

This is a PHP error via normal site operation, so bumping priority.

dillix’s picture

Status: Needs review » Needs work

#34 work as expected, but with #71 I got errors for custom entity with comment field:

InvalidArgumentException: A valid cache entry key is required. Use getAll() to get all table data. in Drupal\views\ViewsData->get() (line 140 of core/modules/views/src/ViewsData.php).
Drupal\views\Plugin\views\HandlerBase::getTableJoin() (Line: 776)
Drupal\views\Plugin\views\query\Sql->getJoinData() (Line: 610)
Drupal\views\Plugin\views\query\Sql->ensureTable() (Line: 55)
Drupal\comment\Plugin\views\field\StatisticsLastUpdated->query() (Line: 1373)
Drupal\views\ViewExecutable->_build() (Line: 1282)
Drupal\views\ViewExecutable->build() (Line: 395)
Drupal\views\Plugin\views\display\PathPluginBase->execute() (Line: 196)
Drupal\views\Plugin\views\display\Page->execute() (Line: 1630)
Drupal\views\ViewExecutable->executeDisplay() (Line: 81)
Drupal\views\Element\View::preRenderViewElement()
call_user_func_array() (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback() (Line: 772)
Drupal\Core\Render\Renderer->doCallback() (Line: 363)
Drupal\Core\Render\Renderer->doRender() (Line: 201)
Drupal\Core\Render\Renderer->render() (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 564)
Drupal\Core\Render\Renderer->executeInRenderContext() (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare() (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse() (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray()
call_user_func() (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch() (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw() (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle() (Line: 58)
Drupal\Core\StackMiddleware\Session->handle() (Line: 48)
Drupal\Core\StackMiddleware\KernelPreHandle->handle() (Line: 106)
Drupal\page_cache\StackMiddleware\PageCache->pass() (Line: 85)
Drupal\page_cache\StackMiddleware\PageCache->handle() (Line: 48)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle() (Line: 51)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle() (Line: 23)
Stack\StackedHttpKernel->handle() (Line: 708)
Drupal\Core\DrupalKernel->handle() (Line: 19)

larowlan credited otofu.

larowlan’s picture

Marked related issue as duplicate, transferring credit

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

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now 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.

dillix’s picture

Status: Needs work » Reviewed & tested by the community

I applied patch #71 on latest version of Drupal and all worked fine.

catch’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: -Novice

Tests are failing and this hasn't been tested against 10.1.x, there are also outstanding review issues from #72, so not RTBC.

ravi.shankar’s picture

StatusFileSize
new15.61 KB
new615 bytes

Addressed point 1 of comment #72.

anchal_gupta’s picture

StatusFileSize
new2.34 KB
new15.6 KB

Rerolled patched against #84. please review it

jonathanshaw’s picture

The test fail is simple: $modules needs to be protected in CommentStatisticsTest.

#72.3 is not fixable in any way I know.

#72.2 is I think OK as is; #72.3 would solve it nicely if that were possible.

Therefore this is RTBC once tests pass on 9.5 and 10.1.

ameymudras’s picture

Status: Needs work » Needs review
StatusFileSize
new15.6 KB
new571 bytes

Small change to fix the tests

lendude’s picture

Nitpicks, if others think it is fine like this, don't care too strongly. Just wanted to queue up the other databases since this is doing a little more than plain queries.

  1. +++ b/core/modules/comment/src/Plugin/views/filter/StatisticsLastUpdated.php
    @@ -13,11 +15,47 @@
    +  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
    +    $instance = new static(
    +      $configuration,
    +      $plugin_id,
    +      $plugin_definition
    +    );
    +    $instance->entityTypeManager = $container->get('entity_type.manager');
    +    $instance->entityFieldManager = $container->get('entity_field.manager');
    +    return $instance;
    

    Not a fan of this pattern inside Drupal core. It's great for using outside core to avoid breaks, but don't think we should do that inside core, just use Dependency Injection properly. Also, if you do this, it should add a setter so you could actually unit test this properly (which isn't possible now)

  2. +++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_ces_entity_test_mul_changed.yml
    @@ -0,0 +1,157 @@
    +uuid: 92c9bbbd-3a1f-4f5c-813c-21869412041d
    

    I think we try to avoid adding uuid's even in test config

ravi.shankar’s picture

StatusFileSize
new16.3 KB
new2.58 KB

I've tried to address point number 1 and 2 of comment #88.

lendude’s picture

+++ b/core/modules/comment/src/Plugin/views/field/StatisticsLastUpdated.php
@@ -13,10 +15,50 @@
+  public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition) {
+    $instance = new static(
+      $configuration,
+      $plugin_id,
+      $plugin_definition,
+      $container->get('date.formatter'),
+      $container->get('entity_type.manager')->getStorage('date_format')
+    );
+    $instance->entityTypeManager = $container->get('entity_type.manager');
+    $instance->entityFieldManager = $container->get('entity_field.manager');
+    return $instance;

Thanks @ravi.shankar, same goes for the other create method being modified here, I think that should use normal DI too.

The fails on PostGres and SQLite seem unrelated.

Status: Needs review » Needs work

The last submitted patch, 89: 2086125-89.patch, failed testing. View results

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new17.93 KB
new4.7 KB

Used proper dependency injection in remaining classes as well.

ravi.shankar’s picture

StatusFileSize
new17.93 KB
new661 bytes

Forgot to fix the failed test of patch 89 in patch #92 so added a new patch with test fix.

The last submitted patch, 92: 2086125-92.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 93: 2086125-93.patch, failed testing. View results

jonathanshaw’s picture

The test fail is caused by a missing use statement.

ravi.shankar’s picture

Status: Needs work » Needs review
StatusFileSize
new18.24 KB
new1.96 KB

Fixing failed tests of patch #93.

Status: Needs review » Needs work

The last submitted patch, 97: 2086125-97.patch, failed testing. View results

sachbearbeiter’s picture

Will there be a solution in the 9.5.x version? We urgently need this functionality. Or is there a solid workaround?

klemendev’s picture

Don't think there is a solid workaround there

sachbearbeiter’s picture

@klemendev - thanks!

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

darvanen’s picture

The __construct method on the parent object (\Drupal\views\Plugin\views\field\Date) is expecting two more injected services:

      $container->get('date.formatter'),
      $container->get('entity_type.manager')->getStorage('date_format')
darvanen’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Needs work » Needs review
StatusFileSize
new18.51 KB
new1.81 KB

As a bugfix I'm pretty sure this should still be targetting 9.5.x.

ravi.shankar’s picture

StatusFileSize
new18.62 KB
new850 bytes

Added description for $date_formatter parameter.

darvanen’s picture

Issue tags: +DrupalSouth

Ah rats, thanks Ravi :)

Status: Needs review » Needs work

The last submitted patch, 105: 2086125-105.patch, failed testing. View results

dillix’s picture

@ravi.shankar I reviewed you patch, you need to fix translated text in views:

            previous: ‹‹
            next: ››
jonathanshaw’s picture

Otherwise RTBC I think

sachbearbeiter’s picture

@darvanen @ravi.shankar Thanks a lot!

capysara’s picture

StatusFileSize
new20.96 KB
new779 bytes

Removed translated text per comment in #108

capysara’s picture

Status: Needs work » Needs review
smustgrave’s picture

Version: 9.5.x-dev » 11.x-dev
Status: Needs review » Needs work

This will have to be committed to 11.x first.

sachbearbeiter’s picture

dawehner already has a long beard ... 10 years ...

mrinalini9’s picture

Status: Needs work » Needs review
StatusFileSize
new20.94 KB

Rerolled patch #111 for 11.x branch, please review it.

Thanks!

Status: Needs review » Needs work

The last submitted patch, 115: 2086125-115.patch, failed testing. View results

sachbearbeiter’s picture

Can we pay someone to finally commit the thing?

jonathanshaw’s picture

You could RTBC it ...

capysara’s picture

Assigned: Unassigned » capysara

capysara changed the visibility of the branch 11.x to hidden.

capysara changed the visibility of the branch 2086125-last-read-comment to hidden.

capysara’s picture

Assigned: capysara » Unassigned
Status: Needs work » Needs review
StatusFileSize
new555 bytes

I moved this into a MR instead of a patch. I'm attaching an interdiff, but I only changed the $field_alias property to allow it to be nullable to address the failed test.

Update note: I also the deleted the orig file that I unintentionally introduced in my previous patch.

jonathanshaw’s picture

#115 introduced a schema.orig file I'm not familiar with. Is that correct? Otherwise I'd RTBC it.

capysara’s picture

Ooops. That was unintentional. Thanks for catching!

I updated the MR to remove it.

smustgrave’s picture

Status: Needs review » Needs work

Few nitpicky stuff.

capysara’s picture

Updated per MR comments. Thanks Stephen!

capysara’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Hiding all patches for clarity.

Ran the test-only feature

1) Drupal\Tests\comment\Functional\Views\CommentStatisticsTest::testEntityMulChanged
Drupal\Core\Config\Schema\SchemaIncompleteException: Schema errors for views.view.test_ces_entity_test_mul_changed with the following errors: views.view.test_ces_entity_test_mul_changed:display.default.display_options.fields.last_updated.date_format missing schema, views.view.test_ces_entity_test_mul_changed:display.default.display_options.fields.last_updated.custom_date_format missing schema, views.view.test_ces_entity_test_mul_changed:display.default.display_options.fields.last_updated.timezone missing schema, 0 [display.default.display_options.fields.last_updated.date_format] 'date_format' is not a supported key., 1 [display.default.display_options.fields.last_updated.custom_date_format] 'custom_date_format' is not a supported key., 2 [display.default.display_options.fields.last_updated.timezone] 'timezone' is not a supported key.
/builds/issue/drupal-2086125/core/lib/Drupal/Core/Config/Development/ConfigSchemaChecker.php:98
/builds/issue/drupal-2086125/core/lib/Drupal/Component/EventDispatcher/ContainerAwareEventDispatcher.php:111
/builds/issue/drupal-2086125/core/lib/Drupal/Core/Config/Config.php:230
/builds/issue/drupal-2086125/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php:278
/builds/issue/drupal-2086125/core/lib/Drupal/Core/Entity/EntityStorageBase.php:486
/builds/issue/drupal-2086125/core/lib/Drupal/Core/Config/Entity/ConfigEntityStorage.php:257
/builds/issue/drupal-2086125/core/lib/Drupal/Core/Entity/EntityBase.php:352
/builds/issue/drupal-2086125/core/lib/Drupal/Core/Config/Entity/ConfigEntityBase.php:609
/builds/issue/drupal-2086125/core/modules/views/src/Tests/ViewTestData.php:49
/builds/issue/drupal-2086125/core/modules/comment/tests/src/Functional/Views/CommentStatisticsTest.php:42
/builds/issue/drupal-2086125/vendor/phpunit/phpunit/src/Framework/TestResult.php:728
ERRORS!
Tests: 1, Assertions: 2, Errors: 1.

Applying locally on a standard install and doesn't appear to have issues.
Created a test view with the Comment Statistics: Updated/commented date field added, no issues
Created some test Articles adding comments as I went.
Date seems correct to me.

larowlan’s picture

Issue credits

larowlan’s picture

Status: Reviewed & tested by the community » Needs work

Left some comments on the MR

Some regarding new coding standards, but also some about making sure the field-type is what we expect and some missing test coverage.

I'm keeping a close eye on this one as I'm keen to see it resolved too.

capysara’s picture

Assigned: Unassigned » capysara
jonathanshaw’s picture

For anyone following, this is still NW for the test coverage.

capysara’s picture

Still needs tests, but I'm un-assigning myself for now.

dwb17 changed the visibility of the branch 2086125-last-read-comment-11x to hidden.

capysara’s picture

Assigned: capysara » Unassigned

loze made their first commit to this issue’s fork.

loze changed the visibility of the branch 2086125-last-read-comment-11x to active.

beunerd changed the visibility of the branch 2086125-last-read-comment to active.

kasey_mk’s picture

I'm having trouble parsing the status of this issue and getting a working patch out of it. Unknown column 'node.changed' on filter by 'Updated/commented date' has been closed as a duplicate in favor of this issue, but it did have a patch that (with a little tweak as I commented) seems to get my 10.3.7 site back to working without errors. Sharing here in case it helps others.

pandepoulus’s picture

Hello, not sure if i should comment here or create a new issue. None of the patches work for me, (i'm using the sort StatisticsLastUpdated handler).
blame is on the field_alias parameter, which is non nullable, and $this->query->addOrderBy(.....) is being called.
That function does return null, so the non nullable parameter raises an exception.

For me the solution was as easy as just call the orderBy without assigning it to a field_alias parameter, which i think is unnecesary in a sort filter.

alexpott made their first commit to this issue’s fork.

alexpott’s picture

Status: Needs work » Needs review

@pandepoulus yep assigning the return $this->query->orderBy() to a property is pointless. I've updated the MR to fix this for 11.x.

We still need to add test coverage for the comments on entity types that do not implement EntityChangedInterface

alexpott’s picture

So I think we only need the StatisticsLastUpdated field, filter and sort to entity types which implement EntityChangedInterface and have a changed field. That way we avoid quite a few issues. If you want to filter on the last_updated time in comment_entity_statistics then you can use the last comment timestamp field, filter and sort... you do not need this special implementation.

joelpittet’s picture

Issue tags: +Needs tests

This is looking good. Due to the changes not applying in D10, it’s trickier for me to test manually right now.

I’ve postponed #3540867: Views 'last updated/commented' field fails to sort entities without comment statistics on this, it’s related but not the same issue, just commenting for awareness. It's related to the stats not being populated in D8+

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new5.26 KB

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

joelpittet’s picture

Issue tags: -Needs tests

Got the tests for entity_test which doesn't implement EntityChangedInterface. I hope that gets this further. Removing the tag I added earlier.

joelpittet’s picture

Status: Needs work » Needs review

Forgot to change to needs review after adding the tests and attempt to shore this up by moving the logic onto the plugins.

joelpittet’s picture

Caught up the commits, tests were passing a few weeks ago... 🤞

Any brave souls up for reviewing this so we can get this major out the door?

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new90 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

eelkeblok made their first commit to this issue’s fork.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.