The user_profile theme hook does not seem to have or act on $variables['content'].

Thus, even when $variables['content']['#prefix'] is set correctly by rdf_process using theme_rdf_metadata, the metadata does not show up on the user profile page.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Anonymous’s picture

Issue tags: +RDF

Forgot tag

Anonymous’s picture

Status: Active » Needs review
FileSize
1.47 KB

Checks whether $variables['content'] or or $variables['user_profile'] is set and attaches the #prefix value to the correct variable.

scor’s picture

+++ modules/rdf/rdf.module	2 Feb 2010 19:00:44 -0000
@@ -366,12 +366,14 @@ function rdf_process(&$variables, $hook)
+  // close to that content. The content variable is user_profile in user
+  // profiles, so we check which variable we are processing.
+  $variable_name = !empty($variables['content']) ? 'content' : 'user_profile';

We are hard-coding things. We should check to see if this missing 'content' key is expected or if it's a bug in the user module. What other modules/entity do we need to add to this list? It would be better if we could standardize on 'content', or at least forsee what are the other special cases...

leaving status "needs review" hoping to get feedback on this.

Anonymous’s picture

The offending code is in user.pages.inc

/**
 * Process variables for user-profile.tpl.php.
 *
 * The $variables array contains the following arguments:
 * - $account
 *
 * @see user-profile.tpl.php
 */
function template_preprocess_user_profile(&$variables) {
  $account = $variables['elements']['#account'];

  // Helpful $user_profile variable for templates.
  foreach (element_children($variables['elements']) as $key) {
    $variables['user_profile'][$key] = $variables['elements'][$key];
  }

  // Preprocess fields.
  field_attach_preprocess('user', $account, $variables['elements'], $variables);
}
scor’s picture

Looks like this is a common pattern in HEAD:

./modules/block/block.admin.inc:541:    $variables['block_listing'][$key] = array();
./modules/comment/comment.module:2191:    $variables['content'][$key] = $variables['elements'][$key];
./modules/node/node.module:1383:    $variables['content'][$key] = $variables['elements'][$key];
./modules/search/search.module:975:      $variables['search'][$key] = drupal_render($variables['form'][$key]);
./modules/user/user.pages.inc:175:    $variables['user_profile'][$key] = $variables['elements'][$key];

We should check whether it would make more sense to standardize on $variables['content'] or if there is a valid reason for having a different key name here (which looks like the hook name).

Anonymous’s picture

Standardizing on 'content' would require a lot of changes in the theme layer. Since it seems to be standardized on hook name already, this patch uses that.

Anonymous’s picture

Actually, this breaks it in comment, so nevermind.

Anonymous’s picture

Comment and node are the only ones that use 'content' for their template variable. If all others use the hook name, we may want to see if those could be standardized to use hook name rather than the other way around.

scor’s picture

Title: theme_rdf_metadata doesn't work for MODULE_preprocess_user_profile » theme_rdf_metadata doesn't work for any MODULE_preprocess_HOOK()

making title more generic

Anonymous’s picture

If the variable is either 'content' or the theme hook name, this patch would be an alternate option to standardizing. Same patch as #2, it checks whether 'content' is set and if not, sets the variable name to the theme hook name.

Anonymous’s picture

Title: theme_rdf_metadata doesn't work for any MODULE_preprocess_HOOK() » theme_rdf_metadata doesn't work for most MODULE_preprocess_HOOK()

Changing title because it does work for preprocess_node and preprocess_comment.

effulgentsia’s picture

subscribing for review later.

effulgentsia’s picture

Status: Needs review » Needs work
+++ modules/rdf/rdf.module	3 Feb 2010 12:47:20 -0000
@@ -366,12 +366,15 @@ function rdf_process(&$variables, $hook)
-  // close to that content.
+  // close to that content. The template variable naming scheme varies for
+  // content variables. We check to see whether it is 'content'. If not, we use
+  // the theme hook name.
+  $variable_name = !empty($variables['content']) ? 'content' : $hook;
   if (!empty($variables['rdf_metadata_attributes_array'])) {

This is great. Let's make the test a little more robust by checking that 'content' is both not empty and an array. We should apply the same test to $hook, and if that also fails, then we don't have any render array variable to apply metadata to, so not get into the if block.

Also, what do you think of $content_variable instead of $variable_name?

+++ modules/rdf/rdf.module	3 Feb 2010 12:47:20 -0000
@@ -366,12 +366,15 @@ function rdf_process(&$variables, $hook)
-    if (!isset($variables['content']['#prefix'])) {
-      $variables['content']['#prefix'] = '';
-    }
-    $variables['content']['#prefix'] = theme('rdf_metadata', array('metadata' => $variables['rdf_metadata_attributes_array'])) . $variables['content']['#prefix'];
+      if (!isset($variables[$variable_name]['#prefix'])) {
+        $variables[$variable_name]['#prefix'] = '';
+      }
+      $variables[$variable_name]['#prefix'] = theme('rdf_metadata', array('metadata' => $variables['rdf_metadata_attributes_array'])) . $variables[$variable_name]['#prefix'];

Why different indentation of replacement code?

This review is powered by Dreditor.

effulgentsia’s picture

Also, if there is a real use-case of user_profile needing metadata, please include that in this patch, along with a test for it, so the fix in this patch gets some test coverage. Thanks!

Anonymous’s picture

Thanks for the review, I just noticed that there were new comments on this yesterday.

Great comments, I incorporated them all. We solved the problem in the case of user_profile by just adding the RDF in a meta tag, but I use that as the test case in the tests.

Anonymous’s picture

Status: Needs work » Needs review
Anonymous’s picture

New and improved! (with less whitespace thanks to the new version of Dreditor)

effulgentsia’s picture

Awesome. Thanks! Tiny nit:

+++ modules/rdf/rdf.module	12 Mar 2010 10:19:51 -0000
@@ -424,12 +424,20 @@ function rdf_process(&$variables, $hook)
+  else if (!empty($variables[$hook]) && is_array($variables[$hook])) {

s/else if/elseif/

143 critical left. Go review some!

Anonymous’s picture

Thanks, fixed now.

effulgentsia’s picture

Status: Needs review » Reviewed & tested by the community

Thanks!

realityloop’s picture

Issue tags: -RDF

#19: rdf_process-user_702664_19.patch queued for re-testing.

marcingy’s picture

Issue tags: +RDF

#19: rdf_process-user_702664_19.patch queued for re-testing.

Dries’s picture

Status: Reviewed & tested by the community » Needs work

This patch no longer applies. Needs a reroll so moving to 'needs work'.

marcingy’s picture

Status: Needs work » Needs review
FileSize
4.99 KB

Reroll against head.

marcingy’s picture

hadn't updated head above patch will fail.

Anonymous’s picture

Status: Needs review » Postponed

This should hopefully no longer be an issue once #1778226: [META] Fix RDF module is completed.