There already exists a nice way to append the status form (textfield, submit button, etc.) to a view (see for example http://drupal.org/node/479306), so that both are displayed together and the view is automatically updated using AHAH. All you have to do is create a node or block, and put a simple php call in it that passes in the view's machine-name to the theme function, like "facebook_status_ur" in this example:
theme('facebook_status_form_display', $user, 190,'facebook_status_ur', FALSE );
This is great, but the current code only works for the default-display of the view. Sometimes, a view can have many displays, and I'd like to be able to apply the input-form to a non-default display (or maybe even several).
It is a very simple fix, and I appended it in the attached file:
In facebook_status.module, the theme function just needs an extra argument for the desired display name: $display_id
function theme_facebook_status_form_display($account = FALSE, $size = FALSE, $view = FALSE, $view_arg = FALSE, $display_id = 'default') {
...
if ($view && module_exists('views')) {
.... // change this in both places where "view_embed_view" is called
$rendered_view = views_embed_view($view, $display_id, $arg, $arg2);
The extra argument is also registered in hook_theme.
You then call the function like this, with an optional machine-name of the display.
theme('facebook_status_form_display', $user, 190, 'facebook_status_ur' );
OR
theme('facebook_status_form_display', $user, 190, 'facebook_status_ur', FALSE, 'book_5' );
BTW, the way to find the machine name of the display is go the the view's edit page, and simply hover the mouse over any of the view's links. It will display a URL, which includes the view's name and the display.
Alternatively, if you don't want to change the function signature, you could overload the 'view' argument to either be a single string (as it is now) OR an array that holds both the view name and the display. But I think the above change is simpler.
Right now, I simply put the fix into my theme's template.php file, but I think it would be generally useful, and should become part of the main-module. I attached the solution in a file.
| Comment | File | Size | Author |
|---|---|---|---|
| theme_facebook_status_form_display.txt | 2.42 KB | hoporr |
Comments
Comment #1
icecreamyou commentedI'm not making any changes to the 2.x branch, API or otherwise, except for critical bug fixes. Since the 3.x code is in CVS but not tagged for release yet, I'm just adding a tag to this post ("FBSS3") to indicate that this is really a 3.x issue.
In the 3.x branch, this is significantly more complicated. The API allows specifying a default view for various contexts ("contexts" being a new idea introduced in 3.x) that users can then change via the interface. So any change that allowed selecting non-default displays would also have to add this ability to the UI.
Comment #2
icecreamyou commentedComment #3
sansui commentedThis was a pretty big help hoporr - I was investigating this myself after creating a facebook style news feed with user relationships, and was staring at the theme function when I decided to see if anyone else had already figured this out - lo' and behold a perfect and simple explanation :)
Thanks a bunch!
Comment #4
salientknight commentedFirst off... I love this module. Thanks Ice. That said, I am having a real issue. I have a long user profile and I really need the wall to be something separate from the profile. I've explored hacks, even going so far as to move the profile information to another page (which of course resulted in all views user links going to the wall not the profile) and I have looked all over good and this site for a solution that works. So I ask. Is there a way to get the Status update form on another page? Code, a link, a module... anything would be greatly appreciated. I'm willing to go to version 3 if that will help me pull this off, but it does not sound like 3 does this either.
I have 6.x-2 and also use Micropublisher
Thank you.
Comment #5
sansui commentedsalient, you can absolutely do this :) The easiest way for me was to create a new page callback in my custom site function that adds a tab to the user account area
You'll notice that my use of facebook_status_form_display is a bit different since I customized my theme function to include argument for a different view to use (in my case, facebook_status_stream), so you could just use theme('facebook_status_form_display',$arg) I think and get the form you want on your brand new page. I'm a bit pinched for time at the moment but try googling that function or check it out in the module files - there may even be an existing block you could just plug in using something like user displays.
Comment #6
salientknight commentedI'll give this a try. Thank you very much!
Comment #7
salientknight commentedHey Sansui,
This is creating an alt link to my profile page. Not a wall page with a Status Form on it. When I change my profile template, it changes this page.
But this did give a good work around. Having created the new link I added the follow code to my user-profile.tpl.php:
Thank you very much!
Comment #8
sansui commentedAre you using hoporr's theme modifications above?
In any case, you can even try this on a normal page, with the PHP input filter, if something this simple is all you need.
global $user; print theme('facebook_status_form_display', $user, 190, 'facebook_status_ur' );This will display the status update form + the default wall for the current user. If you want to use it as a module, which I recommend, you can change the menu item to be a normal menu item instead of a local task, and give it a normal path like "mywall" instead of "user/%user/newsfeed"
You'll need to remove the page argument and user the $user object instead
Comment #9
salientknight commentedThanks again. This worked great as a header on the views. My first attempt was to use it in a block which did not work. Problem is solved now though. Thanks much!.
Comment #10
icecreamyou commentedI just committed an API change to dev that adds a $display parameter to theme('facebook_status_form_display') so that this would be possible. I'm not going to expose it via a UI, however, because it's just too difficult to figure out how to make sure that users can't select a display that is not valid for the selected view. (If someone else wants to write a patch that provides such a UI, I'm open to reviewing it.)
Comment #11
FrankzeTank commentedI'm a bit confused, was there any fix or option for 6.3.0-rc2 as I'm using that and all I want to do is change the page that the wall is is essentially on as explained above? I tried the above solutions with no help. After reading the documentation it seems that for 6.3x the function is
I don't understand how to implement the appropriate $context as explained in the documentation. I played around with facebook_status_determine_context(), and facebook_status_all_contexts(). But there isn't any specific context to the user page i'm on via the user object or something else it seems.
Right now I have a basic hook_menu:
The only thing appended above is the user argument and wall argument was added to the end. And all I want is to render the wall on this page for every specific uid in arg(1), so all users have a consistent wall page @www.example.com/profile/[uid]/wall.
My 3 other functions are
-Wall Template prints the $wall_form
It will print the wall form for the user on the page but it also does it for all the profile pages rather than just their's. I think I understand how the theme() function works for 2.x but I don't understand the context system at all I'm afraid. I hate asking for help, but I've already spent all day 6+ hours trying to figure this out. Any and all help is much appreciated, thanks a lot.
Comment #12
icecreamyou commented@FrankzeTank: Your question is unrelated to this thread -- it would be much better in its own issue -- but you will need to create a View that takes a Recipient ID argument from the URL and then either make that the default view for user streams at admin/settings/facebook_status/contexts or pass it in to your call to theme('facebook_status_form_display') in your code.
Comment #13
Michael3185 commentedEdit: Can be deleted. Don't code tired... :)
Comment #14
liliplanet commentedsubscribe, thx! would love to know how to append a status box on any view :)
Comment #15
icecreamyou commentedYou can already append any view to the status update box. This issue is about using non-default displays on the appended view, and it is fixed.