Hi,
Great module and many thanks for the work on it.
I've been reading here on the complex use case for hook_fb_tab (bottom of the page): http://drupal.org/node/956034
It shows how a facebook page admin can set some options to define what is displayed on the page tab, in the example its custom content from organic groups.
I'm just learning drupal development and know some php so I'm just wondering how I would go about putting code here to display all nodes of a specific content type which are authored by the currently logged in user (the facebook page admin)?
Bearing in mind that this will need to be set somewhere as a permanent option the first time the facebook page admin views the tab, otherwise it would be trying to load nodes authored by anyone who visits the tab which isn't whats required and wont work anyway.
Could anyone give me some code snippets or guidance in how to achieve this?
Comments
Comment #1
Dave Cohen commentedI thought I had responded to this already, then I realized that response was on drupalforfacebook.org. Anyway this is what I wrote there...
First do some research on drupal.org, get your head around how forms work in Drupal.
fb_tab.module helps you build a configuration form for each tab and to save settings. That's why the snippet on http://drupal.org/node/956034 is relatively short. There's a few things happening for you automatically.
This is further complicated by facebook's platform. You don't necessarily know who is visiting a tab when it is first visited. The example sends you to another (canvas) page to actually configure the tab.
The example lets the admin select an organic group. In your case you may detect who the user is automatically, but I still recommend following the same flow. From the tab they will go to a canvas page, then submit a form which saves the settings (even if it is just a submit button, for now).
Comment #2
WildBill commentedIt looks like you can now choose iframes for your Page Tab, so you aren't locked into using FBML. So could you not achieve what the OP is seeking using Views and regular old HTML?
Comment #3
Dave Cohen commentedWhen you serve the tab, you can find out which page the tab is on. thiokol is asking, "how can I configure it shows nodes by user A on page X, and nodes by user B on page Y?" (if I understand correctly). The configuration step associates A with X, B with Y, etc.
Comment #4
problue solutionsHi Dave,
Thanks for the reply, I think you understand what I'm after.
Could you give any snippets on the code to acheive this? I know this maybe isnt really DFF specific as such, but I would really appreciate any help.
We basically need the logged in user to visit the canvas page and somehow register that they are indeed the user who's authored nodes are then displayed when an anonymous visitor views the fb tab.
I hope Im not misunderstanding how this could work though, the use case is as follows...
The website is a restuarant menu directory, a restaurant signs up to the drupal site through DFF and adds some menu nodes, they then add the fb tab to their facebook profile, they visit the fb tab and a setting is set to say that the nodes displayed on their fb tab are only nodes authored by them. So multiple restuarants add the fb tab to their facebook profiles and each of these tabs show only the menu nodes authored by each specific restuarant.
Is this possible?
Comment #5
Dave Cohen commentedThe code on http://drupal.org/node/956034 should be close to the snippet you need. You seem to understand that. You just want to choose a user (instead of organic group) when configuring. To show nodes only by that user, you could embed a View (like the example) or build some custom code.
Drupal.org is full of snippets and examples. You have to pick the right approach for you and fine tune it. I can't do a better job than the d.o forums and documentation pages.
Comment #6
problue solutionsHi Dave,
I'm a bit confused by something, maybe you can clairfy.
if I'm using fb_tab/view as the path and using a custom fb_tab.module, where is there a variable or option permanently set to decide what is displayed on the tab and how is this set independently for each user that adds a tab?
I'm looking at the code at the bottom this page again: http://drupal.org/node/956034.
The following snippet sets the configuration:
I don't understand how this is configuring a page to always display the same thing on subsequent visits. Does FB_TAB_OP_FORM store the results of the form in the fb_tab table?
I'm not using Organic Groups, but If I have some code which just displays nodes authored by a specific user and a visitor on my site configures the fb_tab form and selects a username, then how do other users visit the tab and set it to THEIR own settings? I'm just not grasping how the fb_tab is configured independently for each user that adds it to their facebook profile.
Comment #7
Dave Cohen commentedYes, fb_tab is storing the results. Then it passes the configuration to the same hook, when
$op==FB_TAB_OP_VIEW. The idea is that the FB_TAB_OP_FORM is similar to drupal's settings form helper. But rather than being system-wide, the settings are specific to the app and page.You're not obligated to use fb_tab.module's helpers. You can build your own form the usual drupal way. Just that you'll end up having to manage that app and page stuff yourself.
Notice in the example under FB_TAB_OP_VIEW, if the tab is not yet configured, it presents a link to the configuration page.
Facebook no longer supports tabs added to user profiles. Each tab is associated with a page which is not a user (i.e. a fan page, group, application about page, etc, but not a user).
Comment #8
problue solutionsThanks for the reply. Facebook page and not user profile is fine as it's exactly what we require.
The bit that was confusing me is that a user called, lets say 'Joe', adds the facebook app to his facebook page/group and sets the options for what he wants displayed on the fb tab, then all the people who visit that tab on his facebook page see the content which he set when he first installed the facebook app.
Another user called John comes along and also installs the same facebook app on his page/group and then configures it to display content different to what Joe configured above, so all the visitors to Johns fb tab on his facebook page/group see the content that John configured.
It's the same facebook app served from the same path in both Joe's and John's cases, so like you said earlier in this thread "how can I configure it shows nodes by user A on page X, and nodes by user B on page Y?" - page X (Joe's page) and page Y (John's page) are actually being created and stored somewhere and each are uniquely and permanently associated with the individual installation of the facebook tab? The content displayed on page X (Joe's page) should not be just content that Joe sees, it should be specific content that Joe has configured for visitors to his facebook page to see (the visitors will just be regular facebook users and not registered users on the Drupal site).
Anyway, still not 100% getting it but I'll try a few things and see how I get on :)
Comment #9
Dave Cohen commentedwhat you're describing is exactly what the example does. It displays an organic group not based on the user currently viewing, but based on how the page tab was configured when the administrator first added the tab to the page. Anyone who goes to that page sees the same content. But a tab on another page might show a different organic group.
In my case its an organic group, but it could be a view or any page, really.
Comment #10
problue solutionsGreat, thanks for the replies!
Comment #11
problue solutionsHi Dave,
Below is the code I am trying based on the example, it just has a few changes but I cant get it to work, the configuration is never saved for some reason and the tab is always being asked to be configured, its probably something very simple. Any ideas?
Comment #12
problue solutionsI've got this working but in the very last bit:
elseif ($op == FB_TAB_OP_FORM)The form is submitted ok but there is no confirmation, the page just reloads. How do I display a simple message saying 'Your tab has been configured' ?
Comment #13
problue solutionsAnyone?
Just trying to do something very simple, have the tab content loaded after the user clicks submit, instead of the current behavior which is - user clicks submit and nothing appears to happen, the form just reloads but it does configure the tab properly.
I've read all about from submission and redirection but I've no idea how Im supposed to apply what I've read using this FB_TAB_OP_FORM, as it doesnt appear to work like a normal form.
Here is the code for my form:
Comment #14
problue solutionsDave,
I found the following in fb_tab.module...
I can see the drupal_set_message for the confirmation message in the code above, exactly what I want and what I expected to happen. Any ideas why this isnt working in my case?
edit: I added the following just before drupal_set_message:
print ('The tab settings have been updated');This displays for about a second and then the page just reloads and displays the config form again...any ideas?
Comment #15
mottolini commentedThere's a potential security breach here, I think.
I followed all the steps here, created a tab and its configuration page that allows me to link a page tab to its owner.
The problem I found is that any facebook user can configure the page with his/her own drupal user id. Basically, this scheme allow the first person that goes to the configuration page (being the real owner or not) to "claim" it and display his content instead of that of the legitimate owner.
I'm wondering if something is changed now that you have to through a facebook dialog to add the tab to your page. Is it possible to intercept this action and create a proper fb_tab record with the uid so that only the real owner can configure the tab?