I have the realname module installed on my site to display authors by their realname instead of username. But this is not working for the feed I created in views. The XML generated has the username for the creator for each article. For example:
<dc:creator>daviser</dc:creator>
The creator is set in modules/node/views_plugin_row_node_rss.inc
I found that if I change this
'key' => 'dc:creator',
'value' => $node->name,
to
'key' => 'dc:creator',
'value' => format_username($node),
then the realname is used for the creator.
<dc:creator>Ellen Davis</dc:creator>
Comments
Comment #1
dawehnerWell views follows the drupal way:
see node_feed(), maybe it should be changed in core as well.
Comment #2
merlinofchaos commentedYes it absolutely should be fixed. We should always be using format_username where a username is visible. We should fix this and a bug can be filed against core.
Comment #3
ellen.davis commentedSo... what is needed here to get this fixed in views?
Does the core bug need to be fixed first? Do I need to file a bug against core? (I have never done that before, so unsure of process)
Do I need to supply a patch for views?
Comment #4
dawehnerYou would have to probably fix this in both places, so it would make sense to create an issue against core, and provide a patch against views.
Comment #5
ellen.davis commentedI've submitted an issue against core.
Here is the patch for views.
Comment #6
Lloyd commentedWill the patch fix this issue prior to the core issue being resolved?
Comment #7
ellen.davis commentedYes. The patch simply makes the change that I posted in this issue summary. It is not dependent on the core issue being patched.
Comment #8
dawehnerAdded format_username to row_comment as well.
Set to needs review to let the testbot look at the patch.
Comment #9
dave reidSince the output of format_username is untrusted and should be escaped before output, do we need to add a check_plain() here or it it escaped later in the RSS render?
Comment #10
dawehnerYes it's runned through check_plain:
template_preprocess_views_view_row_rss -> empty($item->elements) ? '' : format_xml_elements($item->elements); -> runs check plain on the values.
Comment #11
damiankloip commentedThis looks good, and handy to me.
Comment #12
dave reidThis should be format_username($comment)
Comment #13
ellen.davis commentedUpdated patch to use format_username($comment)
Comment #14
ultimikeJust tested this patch, looks great!
Thank you!
-mike
Comment #15
ellen.davis commentedComment #16
Lostboy22 commented#13: views-format-username-1460506-13.patch queued for re-testing.
Comment #17
Lostboy22 commentedTired of having to look this up for each new release!
Comment #17.0
Lostboy22 commentedputting code in code tags
Comment #18
hass commentedAdded related core issue
Comment #19
hass commented2 years RTBC? Why is this not commited?
Comment #20
nmillin commentedPatch views-format-username-1460506-13.patch works for me.
Comment #22
dawehnerSeems legit.
You know the answer, don't you?
Comment #23
jibranForm
\Drupal\node\Plugin\views\row\RssSo only
\Drupal\comment\Plugin\views\row\Rssneeds fix.Comment #24
dawehnerLooks alright for me!
Comment #25
alexpottThis looks testable.
Comment #26
catchComment #27
andypostsuppose
getDisplayName()should be used hereAnd extend
\Drupal\comment\Tests\Views\RowRssTestComment #28
andypostAlso anonymous comments mostly use user-entered name!
So better use
getDisplayName()only for comment that has anonymous author and name field is emptyComment #29
jibranReroll.
Comment #30
andypostgetUsername deprecated
Comment #31
oleksiyUpdated using
getDisplayName()+ tests.Comment #32
oleksiyComment #33
dawehner+1, we have tests and the bugfix is basically confirmed by @andypost.
I don't really see why this issue is major, but well, let's just keep that :)
Comment #34
andypostyep, +1 on that
Comment #35
andypostSorry, but I need to ask extend tests because of #2614504: Values of 'name' & 'email' fields should be NULL when comment has author (uid > 0)
We need to another test to make sure that comment author of anonymous user is displayed (author name for anonymous should use own name base-field)
@dawehner that's interesting case when author name should be loaded from denormalized field, so probably require to extend views plugin to load extra data or use comment method properly
Comment #36
dawehnerWell, this sounds like a general problem of comments itself.
$comment->getOwner()should return an object which has the right username for the appropriate context, shouldn't it?Comment #38
dawehner@alexpott, @timplunkett, @xjm, and I discussed this issue awhile back at DrupalCon New Orleans.
We agreed that this is a clear bug we should fix, but we don't think this is a major bug, according to our issue priorities.
As @andypost explained, we could do a preload, so we don't load each one individually. On the other hand, we store those entries in cache so it is less of a problem. Note: Normal formatters do the preloading on their own
Comment #49
quietone commentedLooks like this is still relevant.
I found a related issue.
Comment #50
andregp commentedJust a crude reroll. I tried to address the remaining problems, but couldn't. One concern that raised though is about the current test. I tested locally and it passed even without the fix on
Rss.php.Still needs work to address #35, #36, and #38.
Comment #53
acbramley commentedNeeds a reroll on 11.x on an MR.
Comment #56
xjmAdding credits from triage review posted by @dawehner in #38.