Looks like user_user overrides ['History'] of Blog. Also, the blog returns an array of an array instead of an array with a themed form item.

Seems like you should be able to add sections to the fields expected by user_view, as well. Perhaps using something like the following in user_view:

$fields[$category] = array_merge($fields[$category], $content);

or however you would do that. (I'm trying to rush right now, and that is probably way off-base, but hopefully someone can get the idea of what I'm talking about.)

:)

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drewish’s picture

Title: Recent Blog Posts missing from user profile page » user_view() isn't merging view items correctly
Component: blog.module » user.module
Priority: Critical » Normal
Status: Active » Needs review
FileSize
705 bytes

array_merge() won't work because the first time you encounter $category, $fields[$category] isn't an array.

I think you'll have to do something like:

foreach ($data as $category => $content) {
  foreach ($content as $heading => $item) {
    $fields[$category][$heading] = $item;
  }
}

Please see the attached patch.

aaron’s picture

Status: Needs review » Needs work

The issue is when you have enabled Blogs, and go the the User page. The blog module is trying to show a link to the recent blog posts under History. (blog.module's function blog_user) Currently, nothing shows up.

This patch is on the right track. However, after applying the patch, it shows the following when you go to 'user'. It's better than the default, which doesn't show a thing, but it's still not quite what we're looking for.

History
  Array
Member for:
  3 days 20 hours 
drewish’s picture

Well, I think that there are actually two different bugs. My patch addresses the one in the user module. You might want to take a swing at the one for the blog module. Compare its output to that returned by other modules, it's returning form elements not html.

ax’s picture

Status: Needs work » Needs review
FileSize
1.49 KB

the problem is that both blog and user module's _user('view') hooks return wrong structures. former an array(t('History') => $form) with $form being a form array, not a string, latter array(t('History') => array('history'=> drupal_get_form('member', $form))), with the value incorrectly being an array as well.

fix attached. please review, test, apply. this "History: Array" at user/1 looks quite unprofessional :)

ax’s picture

FileSize
1.82 KB

oops - forgot the merging part

drewish’s picture

FileSize
1.38 KB

ax, I don't think it makes sense to remove that array.

Here's an update to my last patch that uses ax's fix for the blog module.

ax’s picture

drewish, you are right. i was confused by the drupaldocs description of hook_user which says

"view": An associative array of *strings* to display, keyed by category name

apparently, this hasn't be updated after the relevant patch. so well - lets go on with your patch.

(note: using

+ $fields[$category][$heading] = $item;

instead of

+ $fields[$category][] = $content;

is still prone to overwriting: who tells me that i cannot use the 'blog' heading in the t('History') category for my custom module?)

drewish’s picture

humm. i think your right about the overwritting... any ideas on what the correct way to do the merge would be?

ax’s picture

FileSize
3.26 KB

don't use user defined, but automatically generated $heading keys a la <module>-<number_of_heading_per_module>, eg. 'user-0', 'user-1', etc. in the end, the "relevant patch" (see last comment) was done to improve theming, ie. making the fields distinguishable - not to provide titles (this can be done when generating the string with the appropiate form functions).

the patch also addresses all of moshes suggestions from the "relevant patch".

TODO: update drupaldocs hook_user("view")

ax’s picture

does anyone care to test and review this? the symptom was "History: Array" instead of "History: member for xxx days; Blog: view recent blog posts" at user/1.

thanks!

brdwor’s picture

+1, the patch worked and fixed the problem with blog.module. I also tested it with a contributed module that was causing the same problem and it works there too.

moshe weitzman’s picture

Status: Needs review » Reviewed & tested by the community
Zen’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
5.54 KB

This is being continued from http://drupal.org/node/45444 . Apologies for the hijack of a RTC thread.

The attached patch is similar to the above patch by Ax, Drewish et al., and my own from the other thread, except:

-The ugly forms are gone. Less processing, cleaner mark-up, and greater styling control.
-The arrays are simpler and more efficient [less nesting].
-Rather than use an auto-numbering for the classes, the patch uses a class key to specify the class. IMO this offers a lot more flexibility [+ reuse] and keeps things tidy. The actual values for the class key are the same as before. This also saves one level of nesting. The $module prefix is still present
-The form mark-up is gone replaced with definition lists. The page looks and behaves the same as before.

AFAIK the only 3 instances in core where hook_user + 'view' are called have been taken care of with this patch.

Please review and update accordingly.
Thanks :)
-K

drumm’s picture

Status: Needs review » Reviewed & tested by the community

Tested and it looks good. +1

ankur’s picture

+1

Tested the patch.

drewish’s picture

+1, zen's patch looks good.

Dries’s picture

Committed to HEAD. Thanks.

Dries’s picture

Status: Reviewed & tested by the community » Fixed
drumm’s picture

This should be documented at http://drupal.org/node/22218

kvarnelis’s picture

Title: user_view() isn't merging view items correctly » change password fails
Priority: Normal » Critical

I was having the problem detailed here: http://drupal.org/node/46759 ever since upgrading to beta 4.

No errors on upgrade. I would get "changes saved" after changing my password, but login results in "Sorry. Unrecognized username or password"

user history for me reads as "array"

The patch at the above node did nothing for me, but another user suggested I go here: http://drupal.org/node/46759

So I upgraded to CVS.

Now the password change still fails, however, I get.

user warning: You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'user,2,3)' at line 1 query: SELECT 
DISTINCT(p.perm) FROM role r INNER JOIN permission p ON p.rid = r.rid WHERE r.rid IN (authenticated user,2,3) in /home/kazys/public_html/varnelis/includes/database.mysql.inc on line 124.
kvarnelis’s picture

Oh crap, sorry. i wish there was an edit button. i thought I was creating a new bug report, i guess not.

kvarnelis’s picture

yet again wishing for the edit button. i meant to say i went to the node drewish suggested: http://drupal.org/node/40200

Zen’s picture

Title: change password fails » user_view() isn't merging view items correctly
Priority: Critical » Normal

@kvarnelis: Your password issue is not related to this. Drewish meant that the "User history just displays Array" bit might be related to this. If that is the case, please disable any contrib modules and test again. Reopen this issue if need be.

Thanks
-K

kvarnelis’s picture

Status: Fixed » Active

thanks for pointing that out. should have done that in the first place. rusty debugging skills, but drupal 4.7 is making sure I re-learn them!

error happens when blog module (from CVS) is enabled and *all* other modules off.

error does not happen when blog module off and a whole host of other modules, including contrib modules on.

magico’s picture

Version: x.y.z » 4.7.3

This seems to be against 4.7
Should be verified.

magico’s picture

Status: Active » Fixed

Wrongly reopened.

Anonymous’s picture

Status: Fixed » Closed (fixed)