Problem/Motivation
We are eliminating the process layer from Drupal 8, since the reasons for it's existence can now be solved in different ways. One of the functions on the chopping block is template_process_username(). Since all this function does is add attributes, now a renderable Attribute object, this variable can safely be moved to the preprocess layer.
function template_process_username(&$variables) {
// Finalize the link_options array for passing to the l() function.
// This is done in the process phase so that attributes may be added by
// modules or the theme during the preprocess phase.
if (isset($variables['link_path'])) {
// $variables['attributes'] contains attributes that should be applied
// regardless of whether a link is being rendered or not.
// $variables['link_attributes'] contains attributes that should only be
// applied if a link is being rendered. Preprocess functions are encouraged
// to use the former unless they want to add attributes on the link only.
// If a link is being rendered, these need to be merged. Some attributes are
// themselves arrays, so the merging needs to be recursive.
$variables['link_options']['attributes'] = array_merge_recursive($variables['link_attributes'], $variables['attributes']);
}
}
Proposed resolution
Move $variables['link_options']['attributes']
or $variables['attributes']
into the preprocess layer.
- remove this function.
Remaining tasks
None.
User interface changes
None.
API changes
None.
Related Issues
#1843650: Remove the process layer (hook_process and hook_process_HOOK)
#1833920: [META] Markup Utility Functions
#1836730: Add a renderable object that is equivalent to l()
#1898468: user.module - Convert PHPTemplate templates to Twig
Comment | File | Size | Author |
---|---|---|---|
#34 | 1843788_34_template_process_username.patch | 716 bytes | Eric_A |
#30 | 1843788_30_template_process_username.patch | 5.58 KB | scor |
#27 | 1843788_27_template_process_username.patch | 5.59 KB | scor |
#22 | 1843788_22_template_process_username.patch | 5.63 KB | scor |
#22 | interdiff.txt | 1.15 KB | scor |
Comments
Comment #1
jenlamptonThis will need to be revisited after #attributes get pulled out of link_options #1836730: Add a renderable object that is equivalent to l()
But for now... patch needs review.
Comment #3
joelpittet#1: core-remove_template_process_username-1843788-1.patch queued for re-testing.
Comment #5
mariagwyn CreditAttribution: mariagwyn commented#1: core-remove_template_process_username-1843788-1.patch queued for re-testing.
Comment #7
tyjamessmith CreditAttribution: tyjamessmith commentedWorking on making a new patch
Comment #8
tyjamessmith CreditAttribution: tyjamessmith commentedPatch needs review
Comment #9
socketwench CreditAttribution: socketwench commentedThere's a whitespace issue, but otherwise it looks fine.
Comment #10
socketwench CreditAttribution: socketwench commentedComment #11
tyjamessmith CreditAttribution: tyjamessmith commented#8: drupal.remove_template_process_username.1843788.08.patch queued for re-testing.
Comment #13
scor CreditAttribution: scor commentedThe reason we have a template_process_username is because we use an intermediary 'link_attributes' to carry around attributes, but these attributes can directly be placed in ['link_options']['attributes']. That's what this patch does.
Comment #15
tim.plunkett#13: 1843788_13_template_process_username.patch queued for re-testing.
Comment #16
scor CreditAttribution: scor commentedkeeping up with HEAD
Comment #18
joelpittet#16: 1843788_16_template_process_username.patch queued for re-testing.
Comment #20
scor CreditAttribution: scor commented#16: 1843788_16_template_process_username.patch queued for re-testing.
git apply --check -p1 1843788_16_template_process_username.patch
works for me on both 0bed623 and the latest HEAD (c4e52bb)Comment #22
scor CreditAttribution: scor commented$variables['attributes']
needed to be initialized.Comment #24
scor CreditAttribution: scor commented#22: 1843788_22_template_process_username.patch queued for re-testing.
HEAD was broken when this patch was first submitted. It has been fixed in the meantime.
Comment #25
joelpittetGreat work, thanks @scor
Comment #26
star-szrNeeds a reroll.
Comment #27
scor CreditAttribution: scor commentedno problem.
Comment #28
star-szrReroll looks good, thanks! Back to RTBC per #25.
Comment #29
alexpottNeeds a reroll
Comment #30
scor CreditAttribution: scor commentedComment #31
scor CreditAttribution: scor commentedback to RTBC per #28.
Comment #32
star-szrYup, looks good. Thanks @scor!
Comment #33
alexpottCommitted fa9c197 and pushed to 8.x. Thanks!
Comment #34
Eric_A CreditAttribution: Eric_A commentedBy initialising attributes in preprocess this broke the ability to pass attributes to the theme layer.
I fear this is something that is all over core. (In fact, there is the 'extra' variable right here in template_preprocess_username().)
Here's a patch to fix the regression at hand. There's hook_theme() to safely initialise theme variables.
Comment #35
joelpittetThank you @Eric_A!
Comment #36
joelpittettagging
Comment #37
alexpottCommitted 757d39e and pushed to 8.x. Thanks!
Comment #38.0
(not verified) CreditAttribution: commentedAdded twig user conversion