Problem/Motivation

The doc header for template_preprocess_user() says that $variables contains $account.

$variables actually contains a render element called 'elements'.

API pages:
https://api.drupal.org/api/drupal/core%21modules%21user%21user.pages.inc... (D8)
http://api.drupal.org/api/drupal/modules--user--user.pages.inc/function/... (D7)

Proposed resolution

Update the documentation in 8.x, then backport to 7.x. template_preprocess_taxonomy_term() has a good example of documenting 'elements'.

Visit /user and debug within template_preprocess_user() to get the important keys of the elements array.

Remaining tasks

Contributor tasks needed
Task Novice task? Contributor instructions Complete?
Create a patch Yes Instructions No

User interface changes

n/a

API changes

n/a

Original report by @jhodgdon

API page: http://api.drupal.org/api/drupal/modules--user--user.pages.inc/function/...

Describe the problem you have found:

The doc header for this function says that $variables contains $account.

That is not correct. I'm not sure what it should say, but not that.

Files: 

Comments

Cottser’s picture

Title: template_preprocess_user_profile lists wrong variables » template_preprocess_user lists wrong variables
Issue summary: View changes
Issue tags: +Novice

template_preprocess_user_profile was moved to template_preprocess_user in 8.x via #1857324: Use default theme name and entity key in $build for user entity. Updating the issue summary.

Cottser’s picture

Issue summary: View changes
Cottser’s picture

Issue summary: View changes

Restoring original summary that I accidentally deleted.

Cottser’s picture

Issue tags: +Twig

Being noisy.

er.pushpinderrana’s picture

Assigned: Unassigned » er.pushpinderrana
Status: Active » Needs work

I would debug this issue and contribute the patch soon.

er.pushpinderrana’s picture

Status: Needs work » Needs review
FileSize
794 bytes
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,565 pass(es). View

Checkout $variables array and updated the documentation accordingly in this patch.

jhodgdon’s picture

Status: Needs review » Needs work

Looks correct to me, thanks!

The only problem is line length. No line of documentation should be longer than 80 characters, including the spaces and * at the front.

er.pushpinderrana’s picture

Status: Needs work » Needs review
FileSize
803 bytes
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,611 pass(es). View

Please review this patch.

Cottser’s picture

Status: Needs review » Needs work
+++ b/core/modules/user/user.pages.inc
@@ -105,7 +105,11 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a
+ *     - #user: A \Drupal\user\Entity\User object.
+ *			 - The user account of the profile being viewed.

It looks like we have some tabs in here which don't match standards: https://drupal.org/coding-standards#indenting. Documentation lines should also be as long as possible within the 80 character limit so some of the "The user account of the profile being viewed" text should be on the same line as the \Drupal\user\Entity\User text. Ref: https://drupal.org/node/1354#drupal

er.pushpinderrana’s picture

Status: Needs work » Needs review
FileSize
804 bytes
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,608 pass(es). View

Thanks @Cottser, its a late night here so did this mistake :)

Removed unwanted tab in this patch, please review once.

Cottser’s picture

Status: Needs review » Needs work

Getting closer!

+++ b/core/modules/user/user.pages.inc
@@ -105,7 +105,11 @@ function user_pass_reset($form, &$form_state, $uid, $timestamp, $hashed_pass, $a
+ *     - #user: A \Drupal\user\Entity\User object.
+ *     - The user account of the profile being viewed.

These shouldn't be separate bullets, it should look more like:

- #user: A \Drupal\user\Entity\User object. The user account of the
  profile being viewed.

(totally guessing at what would fit, you'll need to check to make sure the first line fits within 80 characters).

er.pushpinderrana’s picture

Status: Needs work » Needs review
FileSize
804 bytes
PASSED: [[SimpleTest]]: [PHP 5.4 MySQL] 72,607 pass(es). View

@Cottser, thank you for your feedback. here is next patch where #user line not exceeding 80 characters. Please review.

Cottser’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +needs backport to D7

Looks good to me, thanks @er.pushpinderrana :)

  • Commit 675f2dd on 8.x by jhodgdon:
    Issue #1369822 by er.pushpinderrana, Cottser: Fix docs for...
jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for the patches and reviews! Looks good to me too. Committed to 8.x.

jhodgdon’s picture

Version: 8.x-dev » 7.x-dev
Status: Fixed » Patch (to be ported)

Oh wait, looks like this needs a port to D7. I tried the patch, doesn't apply, and we also need to modify it for 7 (the user object is not the same class, for instance, and we need to check and make sure the same components are being used too).

er.pushpinderrana’s picture

Status: Patch (to be ported) » Needs review
FileSize
636 bytes
PASSED: [[SimpleTest]]: [MySQL] 41,198 pass(es). View

sorry for delay.

Checkout $variables array and updated the documentation for D7. Please review.

Cottser’s picture

Title: template_preprocess_user lists wrong variables » template_preprocess_user_profile lists wrong variables
Status: Needs review » Needs work

Thanks @er.pushpinderrana! Needs a couple touch-ups:

  1. +++ b/modules/user/user.pages.inc
    @@ -184,7 +184,10 @@ function user_logout() {
    + * - elements: An associative array containing the user information and any
    + *    fields attached to the user. Properties used:
    + *    - #account: The user account of the profile being viewed.
    

    The line starting with "fields" and the one after it are indented by one space too many, they should line up with "elements:".

  2. +++ b/modules/user/user.pages.inc
    @@ -184,7 +184,10 @@ function user_logout() {
    + * - user: The user object containing the user information.
    

    The 'user' variable is part of _template_preprocess_default_variables() so shouldn't be included here.

er.pushpinderrana’s picture

Assigned: er.pushpinderrana » Unassigned
Status: Needs work » Needs review
FileSize
572 bytes
PASSED: [[SimpleTest]]: [MySQL] 41,218 pass(es). View
688 bytes

Thanks @Cottser, completed #1 and #2.

Please review.

jhodgdon’s picture

Status: Needs review » Needs work

Looking pretty good, thanks!

  * The $variables array contains the following arguments:
- * - $account
+ * - elements: An associative array containing the user information and any
+ *   fields attached to the user. Properties used:
+ *   - #account: The user account of the profile being viewed.
  *
  * @see user-profile.tpl.php
  */

Can we change the first line to say @param $variables instead, and then add a next line like we have in the Drupal 8 version please?

er.pushpinderrana’s picture

Status: Needs work » Needs review
FileSize
757 bytes
649 bytes
PASSED: [[SimpleTest]]: [MySQL] 41,182 pass(es). View

@jhodgdon thanks for your valuable feedback!

Please review this patch, made your suggested changes.

Cottser’s picture

Status: Needs review » Needs work

So close!

+++ b/modules/user/user.pages.inc
@@ -183,8 +183,11 @@ function user_logout() {
+ *   - elements: An associative array containing the user information and any
+ *     fields attached to the user. Properties used:
+ *   - #account: The user account of the profile being viewed.

We need to indent the #account line because #account is a key of the elements array. Compare to the D8 patch to see what I mean.

amitgoyal’s picture

Status: Needs work » Needs review
FileSize
651 bytes
PASSED: [[SimpleTest]]: [MySQL] 41,200 pass(es). View
497 bytes

Please review updated patch for fixes in #22.

jhodgdon’s picture

Status: Needs review » Reviewed & tested by the community

I think that's it, thanks!

Cottser’s picture

+1, looks good.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 23: drupal7-template-preprocess-user-1369822-23.patch, failed testing.

Cottser’s picture

Status: Needs work » Reviewed & tested by the community

Looks like we had a random/unrelated failure, back to RTBC. Thanks for the retest @mgifford :)

mgifford’s picture

There have been a lot of them lately. Glad to help nudge this along.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 23: drupal7-template-preprocess-user-1369822-23.patch, failed testing.

jhodgdon’s picture

Status: Needs work » Reviewed & tested by the community
jhodgdon’s picture

Status: Reviewed & tested by the community » Fixed

Thanks again! Committed to 7.x.

  • jhodgdon committed 338e2d4 on 7.x
    Issue #1369822 by amitgoyal, Cottser, er.pushpinderrana: Fix docs for...

Status: Fixed » Closed (fixed)

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