Problem/Motivation

On #2393339: [META] Make sure Views base fields are using Field API for formatting, and do not lose functionality, we are updating all base entity fields in entity views data so that they are using Field API for formatting rather than using generic Views handlers.

This issue is about the comment_field_data.field_name field, which is currently using the 'standard' Views handler.

Proposed resolution

Change comment_field_data.field_name to use the Field API formatter 'field' instead of 'standard'.

Remaining tasks

Make a patch.

User interface changes

None.

API changes

Not really.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

jhodgdon’s picture

Priority: Normal » Critical

As per parent issue, this issue needs to be elevated to Critical. The base entity fields using Views formatters currently need to be updated to use Entity-aware field formatters instead, to respect entity access.

larowlan’s picture

Assigned: Unassigned » larowlan

ding ding

larowlan’s picture

Assigned: larowlan » Unassigned
Status: Active » Needs review
FileSize
5.48 KB
jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

Wow, that was fast! Even with a test, which even passes. Thanks! I can't see anything wrong with this simple patch.

I also checked all of the core-provided views configs that listed comment_field_data as the base table in Views, and none of them were using the 'field_name' field. (I guess that might exclude ones with relationships, but that seems like a long shot.) That probably explains why you decided it was a good idea to create such a test view and a test.

Anyway, thanks! I think this is ready to go.

andypost’s picture

are we sure there's no more usage?

+++ b/core/modules/comment/tests/modules/comment_test_views/test_views/views.view.test_comment_field_name.yml
@@ -0,0 +1,140 @@
+uuid: 8170fc88-d583-473e-8d00-d55e17710652

Suppose to be removed

larowlan’s picture

dawehner’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/comment/src/Tests/Views/CommentFieldNameTest.php
@@ -0,0 +1,36 @@
+class CommentFieldNameTest extends CommentTestBase {

Meh, can't we avoid adding web tests

+++ b/core/modules/comment/src/CommentViewsData.php
@@ -162,7 +162,8 @@ public function getViewsData() {
       'title' => t('Comment field name'),
       'help' => t('The Field name from which the comment originated.'),
       'field' => array(
-        'id' => 'standard',
+        'id' => 'field',
+        'field_name' => 'field_name',
       ),
       'filter' => array(
         'id' => 'string',

You should be able to get rid of the entire code block. Also 'field_name' here is afaik not needed. ... The entire field should be autogenerated

jhodgdon’s picture

Guess I was too quick to RTBC. I woke up this morning realizing the entire override of the 'field' section for this should be removed too.

RE #5, I did check that there is no usage of this field in any configured views. It shouldn't be too commonly used -- this is the field that says "What is the name of the comment field this comment is from?" I'm actually not sure why we even have views integration for it, but whatever.

larowlan’s picture

Status: Needs work » Needs review
FileSize
1.01 KB
5.83 KB

Fixes #7.2
For 7.1 do you have an example you could point me at?
Note this is Drupal\comment\Tests\View\CommentTestBase not Drupal\comment\Tests\CommentTestBase, but yeah still eventually winds back to WebTestBase via ViewsTestBase.

dawehner’s picture

Well, there is ViewUnitTestBase you can use

andypost’s picture

FileSize
7.7 KB
8.59 KB

@dawehner we can't use ViewUnitTestBase because we need comment module installed.

I found no way to test render of the field because $view->field is empty

dawehner’s picture

+++ b/core/modules/comment/src/Tests/Views/CommentFieldNameTest.php
@@ -0,0 +1,68 @@
+    $this->assertEqual($this->customComment->id(), $view->result[1]->cid, 'Result contains the comment cid.');
+    $this->assertEqual($this->fieldName, $view->result[1]->comment_field_data_field_name, 'Result contains the comment field name.');

You could use assertIdenticalResultSet here.

andypost’s picture

here it is

jhodgdon’s picture

Looks good to me (but I'm shy about RTBC because of earlier). Thanks!

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

This looks alright now.

andypost’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
1.41 KB
9.48 KB

Discussed with @dawehner at IRC and discovered that better to extend a test with render to check access, so extended the test

xjm’s picture

Issue tags: +VDC
andypost’s picture

FileSize
807 bytes
9.48 KB

The right service to use is account switcher

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

This is looking great!

There are no usecases for that field yet.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed c7fd064 and pushed to 8.0.x. Thanks!

  • alexpott committed c7fd064 on 8.0.x
    Issue #2455131 by andypost, larowlan: Field comment_field_data....

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.