Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
we make several base fields to use just Entity field formatters and not special purpose field handlers in views. However, we have a lot of other field handlers in views that have more functionality than the corresponding field formatters.
Proposed resolution
Replace user_name with new field formatter
Remaining tasks
create patch
User interface changes
Entity fields will have more formatting options available, and they'll be consistent with what is available in Views.
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#64 | name-formatter-before.png | 154.24 KB | rteijeiro |
#64 | name-formatter-after.png | 126.71 KB | rteijeiro |
#64 | interdiff.txt | 863 bytes | rteijeiro |
#64 | 2454145-64.patch | 33.09 KB | rteijeiro |
#60 | interdiff.txt | 1.51 KB | dawehner |
Comments
Comment #1
kgoel CreditAttribution: kgoel commentedComment #2
wwhurley CreditAttribution: wwhurley commentedReplaced user_name views handler with field handler.
Comment #4
adamwhite CreditAttribution: adamwhite commentedI've tested the patch myself and while it appears ok in the UI, it's failing the tests with a "missing schema" error in ConfigSchemaChecker.php.
If you don't patch the /core/modules/user/config/install/views*.yml files
(so you don't swap plugin_id: user_name for plugin_id: field) and re-run the tests it doesn't seem to throw the same errors, but looking at how the other child issues from the parent have implemented this change it does appear that we should be making that change. I'm looking to see if there's elsewhere in the tests we need to change to reflect this.
Comment #7
adamwhite CreditAttribution: adamwhite commentedI removed the portions of the install/views*.yml files which made reference to the following default display options. I believe they're related to the options provided by the user_name handler that we're taking out of play.
Afterwards the tests seemed better on my end. Here's a patch.
Comment #8
adamwhite CreditAttribution: adamwhite commentedComment #10
adamwhite CreditAttribution: adamwhite at JMR Logics commentedThat patch failed as per issue #2090115 which moved the physical location of the yml files from where they were when I rolled the patch. I'll re-roll and re-submit.
Comment #11
adamwhite CreditAttribution: adamwhite at JMR Logics commentedSame patch as before reflecting the move of those yml files to the optional subdirectory in issue #2090115.
Comment #12
adamwhite CreditAttribution: adamwhite at JMR Logics commentedComment #14
kgoel CreditAttribution: kgoel commentedI think link_to_user: true, overwrite_anonymous, anonymous_text and format_username aren't supported by field formatters. They are associated with plugin_id: user_name and since plugin_id is replaced with field, display options can't find any relation to field formatter.
Comment #15
dawehnerYeah, at least the link_to_user feature is needed as we can't bypass the #theme => 'username' API.
So we need a new formatter just for the user name. For that formatter you can use
isApplicable
to limit on which fields this formatter applies to.Comment #16
kgoel CreditAttribution: kgoel commentedComment #17
kgoel CreditAttribution: kgoel commentedI tried to wrap my head around creating new formatter and adding link_to_user in the schema but I am not sure about my approach. Is there any example that I can follow?
Comment #18
kgoel CreditAttribution: kgoel commentedComment #20
kgoel CreditAttribution: kgoel commentedComment #22
kgoel CreditAttribution: kgoel commentedComment #24
kgoel CreditAttribution: kgoel commentedComment #26
kgoel CreditAttribution: kgoel commentedComment #28
dawehnerTalked with kgoel on IRC so we came up with that new patch.
Comment #30
kgoel CreditAttribution: kgoel commentedComment #32
andypostNot sure this formatter needed, and if so it needs to accept settings to do link to user page.
It's serious regression if we loose this ability, otoh ER can do that for us
it needs settings: link_to_entity:true
like we stop trying in #2456691: User email field need to use Field-Entity-aware formatters in Views
Comment #33
dawehner#theme => 'username' already links to the user ... but bypassing the API would be a regression compared to what views offered before.
Comment #34
dawehnerA schema fix a day, keeps the failures away.
Comment #36
dawehnerWorked on one of the test failures ... thank you @kgoel for pointing it out
Note: This is related a lot with the issue #2457999: Cannot use relationship for rendered entity on Views
Comment #38
effulgentsia CreditAttribution: effulgentsia commentedUnless I'm reading the patch wrong, seems like this is doing the same kind of formatter replacement that makes the other similar sibling issues critical.
Comment #39
dawehner@kgoel
If you have time, please continue your great work on this issue ...
Don't remove the filter ... this thing still exists and is useful. Btw. this should cause the failures
Drupal\tracker\Tests\Views\TrackerUserUidTest
andDrupal\views\Tests\TestViewsTest
as well asDrupal\user\Tests\Views\HandlerFilterPermissionTest
Regarding the GlossaryTest failure ... please add user:0 to the listing
in
core/modules/views/src/Tests/GlossaryTest.php:95
For the last remaining fail we should get http://privatepaste.com/fe0e1d738b in here, which adapted the tests, given that we have changed the handler itself.
Comment #40
kgoel CreditAttribution: kgoel commented@dawehner thanks for the detailed review of test fails! I am working on new patch.
Comment #41
kgoel CreditAttribution: kgoel commentedComment #43
dawehner@kgoel
The previous code looked like the following:
but you added back
Note: field vs. filter. It has to be filter.
Regarding the change in GlossaryTest, let me quote myself :)
, it needs the :0
Comment #44
kgoel CreditAttribution: kgoel commentedMy bad. I didn't read your comment properly.
Comment #45
kgoel CreditAttribution: kgoel commentedComment #47
kgoel CreditAttribution: kgoel commentedNeed to look into verbose for last fail in HandlerFieldUserNameTest.php and exception in HandlerFilterPermissionTest.php
Executed view: SELECT users_field_data.uid AS uid
FROM
{users_field_data} users_field_data
LIMIT 10 OFFSET 0
Arguments: Array
(
)
Comment #48
dawehnerLet's quickly fix the remaining failures.
Comment #51
dawehnerSets back to needs review.
Comment #52
larowlanIsn't 'field' the default? If so does that mean this can go?
This sentence doesn't make sense
This is still tagged needs tests, but I see test changes in the patch - does that mean there are tests in HEAD?
Comment #53
damiankloip CreditAttribution: damiankloip commented'field' will get inherited as the plugin ID from EntityViewsData?Fail - didn't see Larowlan's comment above :)Also, what happens with the 'overwrite_anonymous' feature?
Comment #54
jibranNW cuz of #52.
Comment #55
dawehnerDo you really think its a feature, which is not pure featurits? I considered this as something really special.
Expanded the test coverage.
Comment #56
larowlanI agree that overwrite anonymous isn't core-worthy feature.
Manual testing
However, with the current plugin (HEAD) you can opt-out of linking to the entity (user). With the current patch, that option isn't available.
I note that this option is available for the plain-text formatter so perhaps we should inherit from that formatter?
I note however that we're using theme_username which doesn't have a no-link option (head uses user_format_name)
Comment #57
dawehnerWell, that option is encoded as part of the formatter ... but fair, we want to call out to
$user->getUsername()
and so also not ignore the API.Added the setting to the username formatter.
I also enabled the access test coverage ...
Comment #59
aspilicious CreditAttribution: aspilicious commentedI think you're missing the cache tags when rendering only the name. Else it won't update when changing the user name.
Comment #60
dawehnerGood point!!
We have already a dedicated test for the new formatter, so we don't need that issue tag anymore.
Comment #61
webchickWhile this looks close enough that it probably doesn't matter too much, @alexpott, @effulgentsia, @xjm and I discussed this on a D8 critical triage call today. Since we expose user names publicly practically everywhere (user profile, node author, comment author, etc.) it's hard to envision a situation where failing to fix this would result in an SA, unlike a lot of the other issues in this suite. Therefore, downgrading to major, though we'd all still love to see it fixed along with the rest of them.
Comment #62
jhodgdonIs this issue also going to handle this line in NodeViewsData, or do we need another issue for that? This issue was spun off another issue that was supposed to cover this, as well as a similar line in CommentViewsData:
The current patch doesn't seem to change NodeViewsData or CommentViewsData, and it doesn't get rid of the 'user' formatter in User module. ???
Comment #63
jhodgdonTalked to xjm about this... filing a separate issue for the 'user' plugin.
Filed:
#2470093: Views plugin 'user' needs to be replaced with entity-aware 'field' plugin
and I'll add this to the parent Meta issue.
Comment #64
rteijeiro CreditAttribution: rteijeiro commentedLooks good to me. Just fixed a small nitpick.
Author Formatter BEFORE
Author Formatter AFTER
Comment #65
alexpottThis issue is a major task that makes views consistently use field formatters. Whilst this is disruptive for existing views, consistency is a win. Per https://www.drupal.org/core/beta-changes, this is a good change to complete during the Drupal 8 beta phase. Committed 1893614 and pushed to 8.0.x. Thanks!