On the node create/edit form, is it possible to relocate the checkbox for a flag from out of its normal "Flags" fieldset, and into a different fieldset on the node form where it would be most applicable?
For instance, I have a custom fieldset/group in my content type called "Slideshow" where a variety of fields can be filled in if the user wants to show the node in the front page slideshow on the site. In order to get into the slideshow in the first place though, a node also has to have its "Slideshow" flag checked. However, right now the Slideshow flag is in a separate fieldset from the rest of my related settings, and therefore very easy for content editors to overlook or get confused.
From within my module, I see I can access the Flag checkbox with hook_form_alter and $form['flag']['slideshow'];. I can unset it here, or change it in various ways, though I'm not sure if or how to relocate it into a different fieldset in the form.
Any ideas would be greatly appreciated! :) Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | Screen shot 2010-08-05 at 00.28.35.JPEG | 60.08 KB | Gabriel R. |
Comments
Comment #1
quicksketchJust move it to the new location:
However this will assign new parents to the element since it's been moved, you'll probably need to do the above plus adding in the original parents:
Comment #2
dnewkerk commentedWorks like a charm - thanks very much Nathan :)
Comment #3
sheldon rampton commentedI ran into a similar issue when I was asked to combine two checkboxes within a single fieldset. One of those fieldsets was a CCK field, and other was created by the flag module. Initially they didn't want to play together. If I used hook_form_alter to move the CCK field into the flag's existing "flag" fieldset, I got an error message upon form submission. (I think this is because flag_nodeapi() assumes that each element inside $node->flag is going to be a flag, and therefore barfs if the flag fieldset contains anything that isn't a flag.) However, I got a different error if I tried to go the other way -- moving the flag into a fieldset with the CCK field.
After reading this discussion, I was able to combine the CCK field and the flag into a single fieldset using the following implementation of hook_form_alter. My CCK field is named "field_hide_upcoming_events", and my flag is named "feature_on_front_carousel":
Comment #4
Gabriel R. commentedAm I dreaming, or there is a module that listed the Flag like a field in a content type Manage Fields list?
This allows you drag and drop it to relocate it in the list.
I am pretty sure I used this on a previous site.
Comment #5
Gabriel R. commentedI must be crazy ... The Flag field is there in the site I work on, I believe it's a built in feature. I only seen it after I posted the above :-s
Comment #6
rfiertek commentedDoes this also work when you create a forms API field (in this case an item field) and you want to insert it into an existing cck built fieldset?
If so, where would I get the info to populate the parent array that needs to be moved over, if, as far as I know, it has never been assigned to a specific prior parent?
Rob
Comment #7
traviscarden commentedHow would this solution differ for Drupal 7?
Comment #8
mattiasj commentedI am also interested in a Drupal 7 version (got errors using the above mentioned code).
Comment #9
jeni_dc commentedHere's some code that's working for me in Drupal 7. In my case I wanted to alter a blog entry form, to move a front_page_slideshow flag into a group_front_page_slideshow group. Sorry if that's confusing, it just happened to be the way the flag and group were named.
The group_front_page_slideshow group is a vertical tab group from the Field Group module.
A couple of things about this. I'm not sure if adding to the children array of group_front_page_slideshow is entirely necessary. It worked without it but all of the other fields were there so it made sense to me to set it there as well. Also, I've read where unsetting form items in D7 isn't the desired method, but anything else I tried resulted in the flag not being saved.
Jeni
Comment #10
nagy.balint commentedAt the moment according to this issue, and what i found myself the flag module is not compatible with the field group module. If this module provides a field (and it does) it should also act like a field, meaning it should be possible to just drag it and it should appear where i dragged it to. To always put in form alters is not very nice.
I think the issue should be a feature request then.
Comment #11
joachim commentedGosh I didn't know we had this kicking around.
Duplicate of #1892930: Placement of flag links as pseudofields. Which is blocked on #1871426: Ability to add flag links to any view mode, which needs just a few tweaks. Please help if you can.