Closed (duplicate)
Project:
Bio
Version:
5.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
25 Jul 2007 at 22:16 UTC
Updated:
19 Jan 2008 at 14:53 UTC
Jump to comment: Most recent file
I have attached a patch that adds the option to force users to create a bio before continuing through the site. It only applies to uid > 1, and drops a 303 (see also) redirect to node/add/bio (or whatever content type is chosen).
P.S. Sorry if the patch is a little janky. I've never really patched anything for contrib.
| Comment | File | Size | Author |
|---|---|---|---|
| #18 | user_tab.txt | 7.44 KB | designwork |
| #17 | bio.module.required_0.patch | 2.71 KB | Caleb G2 |
| #8 | bio.module.required.patch | 1.98 KB | robloach |
| #5 | bio.module.biorequired.patch | 1.41 KB | robloach |
| #2 | bio_module_enforcer2.patch | 1.97 KB | jscheel |
Comments
Comment #1
marcp commentedIn bio_init() you're duplicating a good chunk of what the function bio_for_user() does. You can just call that and see if it returns FALSE to check if the user hasn't yet created their bio.
This is a great idea, by the way.
Comment #2
jscheel commentedGood catch! I need to look through the code a little better, eh? I've made the change. I've also wrapped the message string in t() for proper text handling.
Comment #3
marcp commentedIt looks like you're using $may_cache without having intialized it. It would also be great to run your code through the Coder module, which will help you get the code better "Drupalized."
I haven't thought too much about it, but is hook_init() the best place to do this?
Comment #4
dldege commentedThis might be easier - its what I do in my own code at the moment and doesn't require any menu hooking. It simply keeps redirecting the user to user/N/bio until they have submitted it once (ie. bio node exists for the user). The only valid url until this point is q=logout.
Comment #5
robloachHere's a re-work using dldege's solution. It gives you an option in admin/user/bio to turn on Required, which will make the user have to create a Bio node before using the rest of the site.
Comment #6
robloachNow that I look at it, this is pretty much the same as jscheel's solution. I think it would be good to move it to hook_menu, using !$may_cache in there.
Comment #7
dldege commentedYeah, they are very similiar and it looks like either version will work. hook_init happens a lot earlier in the page request lifecycle which might be the only advantage of doing it there - no need to deserialize and build the menus, etc. I just offered it as another approach - I do think its a feature worth adding though.
Thanks for adding the settings form handling.
Comment #8
robloachRe-factored with all the above provided solutions, and in hook_menu instead of hook_init. It also displays the Biography node type name instead of just "bio" when asking the user to create a bio node.
Comment #9
Rob_Feature commentedInstalled and works perfectly as advertised. I'd suggest this is ready to commit...and it's a beautiful feature as well.
Comment #10
SamStealth commentedi tried out your latest patch and it works like a charm! great work!
Comment #11
SamStealth commentedit took me ages to get moofie's locationfields to work with 'enforce bio creation'.
somehow dependent dropdowns want to fetch data from 'locationfields/ajax/bio' ... and drupal_goto bio node broke it.
finally i found a one-line solution:
maybe it's good to place a 'do not redirect on following pages...' option on config screen.
Comment #12
SamStealth commentedFYI
i noticed, that - if clicking around on my ajax empowered form - more and more error messages are accumulated,
so here is a slight improvement to my previous post:
Comment #13
jcruz commentedsubscribing
Comment #14
robloachSamStealth: Might be better to have it do something similar to the wildcard solution in admin/content/block where you type in what pages are exceptions. In this case, these would be pages where users would be allowed to visit without requiring the Bio node.
Comment #15
jjeff commentedRe: Wildcard solution: Good idea!
I'm working up a new version of the module right now and I'll try to roll this in. However, if anyone else has any interest/time for this, please post here..
Comment #16
jscheel commentedSorry, I've been kindof awol on this issue. I can write up something to integrate wildcards. Just let me know.
Comment #17
Caleb G2 commentedAfter applying this patch the following message was always returned when I went to actually submit the bio-node form:
After a little tinkering around I figure out that just pulling bio_nodeapi() seemed to have no obvious adverse affects. The problem is gone, and I don't get the message anymore, so I guess it was left over cruft??
In any case here is a new patch with bio_nodeapi() taken out.
Comment #18
designwork commentedHi all,
I did a version of the biomodule automatically created for each user, were you can rename the Tab via admin settings etc.
someone want to test it? More explainantions you will find here http://drupal.org/node/184868.
I think this could be nice to have in bio as standart. But you have to see the code first. It works only for 5.x
Dirk
Comment #19
Caleb G2 commentedDesignWork, it's great that you're trying to get involved with Drupal and making contributions back to the project, but please realize that you are spamming an active, and unrelated, thread. I've seen your comments about this on another thread somewhere on the site, and I can't remember if anyone there suggested it or not (I believe someone did) -- you should file a new issue to engage the bio maintainers about the possibility of integrating your changes, and/or get your own cvs account and make a separate project. Those are generally the only ways new code gets notice or accepted.
Comment #20
Michael Hofmockel commentedIn order to enforce Bio node creation I did the following:
Created a block that is only visible to authenticated user.
Show the block only at:
node/add
node/add/book*
node/add/page*
...
Caution! Dont show on "node/add/bio or node/add/*" as that will cause an endless loop.
This way you can use the entire site but you can not create content until you have created a Bio node.
I feel we do need a module based solution but this is an easy and effective solution in the mean time.
Comment #21
amcc commentedI applied this patch: bio.module.required.patch from comment 8 and when i enabled the module i got this error:
warning: array_keys() [function.array-keys]: The first argument should be an array in /Users/macintosh/Sites/monkey/sites/all/modules/bio/bio_views.inc on line 39.
is this something i need to worry about? Thanks for all the hard work guys - and also to jjeff for a great module and amazing and entertaining podcast.
Comment #22
kufeiko commentedSomeone having problems with Imagefield when this patch is applied?
I use bio 1.0 and the latest patch from this thread. My bio content type holds an image. If an user is forced to create bio, he/she is unable to upload a picture. Seems the upload itself passes, but after that the image is not in the needed directory.
I have the feeling that when you press 'Upload' button to insert image, the enforcement is redirecting you again, preventing the processing of the image.
If an image is added to already existing bio node, no problems are found.
Comment #23
robloachvanko: Be sure to be using ImageField 5.x-2.x-dev. I was experiencing this, updated to ImageField 2.x, and the problem seemed to magically go away. Not quite sure what was happening here, but 2.x fixed it. It also comes with some nice AJAX/AHAH magic which will make you very happy.
Comment #24
robloachI believe we'll be moving to this solution as opposed to the
drupal_gotosolution suggested in this issue. Much cleaner, and most definitely looks nicer.Comment #25
Zoologico commentedThis works well.
I feel we do need a module based solution but this is an easy and effective solution in the mean time.
Thanks, mhofmockel.
Comment #26
kufeiko commentedThanks for both of answers!
Unfortunately, imagefield 2.x didn't do any good to me - the upload broke. I got the HTML of altered web page in an error message. I didn't investigate further.
Bio fields on creation sounds nice, very nice! But i got again this problem with images upload :-(. Furthermore, the users are able to delete their own module and after that stay without bio node. Sad.
Will continiue to look for another solution, if you have any ideas - are welcome ;-)
regards,
Vanko
Comment #27
amcc commentedI've used the solution below - it works perfectly. What i'm worried about is the overheads of the code. Whenever a user logs in i want to enforce them to create a bio before they move on if they don't have one already.
Is this going to slow the site down in any significant way for authenticated users as there will be an extra database query on every page (i've included the bio code showing that query below). Or is this so insignificant that i really shouldn't worry about it.
Here is the code that i've put in my block, I'm making the block appear on every page apart from node/add/bio and node/add/*. I'm also only showing the block for authenticated users.
In an effort to make the code as simple as possible i've taken the $user->uid bit out of the block code as that's already in the bio module function anyway...
Comment #28
liliplanet commentedsubscribe