I've started a new module I've dubbed (for lack of a better name) flag_text.module.

The purpose of this module is to simply allow a user to save a text message along with the flag by adding a new field (text) to the {flag_content} table.

So far I've been using examples from flag_action.module to learn how to utilize the flag.module's hooks along with hook_form_alter (for a setting to enable this feature per (fid, content_id, account) - no primary key in {flag_content} - might add one) and then attempting (see:#328383: Provide hook_preprocess_link() to Drupal 5) to redirect a user (!$js) or present them with a small textarea ($js) and then update the table's field upon submission.

I'll post issues here related to this as they develop and my code as I get things fleshed out.

However, I'd love to have the module maintainers feedback if they think this a worthwhile feature request instead of using a whole new module to do this. I also would love any feedback if you think I'm going about this the wrong way.

The following is beyond the scope of this add-on:
I envision this being a small add-on for even other modules to be able to utilize in order to do things like send a message along with a friend request that is implemented using flag.module, or when a user requests to join a private group (the request itself being a flag) to be able to send some application to the group's supervisor.

Any feedback is welcome and would be greatly appreciated!

I've attached what I have thus far. DO NOT install on a site. Reading purposes ONLY! /disclaimer

CommentFileSizeAuthor
#5 flag_form.zip6.33 KBsirkitree
#4 flag_text.zip9.7 KBsirkitree
flag_text.zip3.47 KBsirkitree

Comments

quicksketch’s picture

Hey sirkitree. I'm also very interested in this particular use-case. I had intended to ultimately create a module I was going to name "flag_history", that does this exact same task. My hope has been that #160519: Allow admin to select Ajax or non-ajax behaviour per Bookmark type would serve as a starting point for this functionality, and that the new module would implement a new "link type" for "Form with message", or something similar. Then clicking the link would prompt the user with a form requiring a message to be submitted along with the (un)flagging.

Note that we'd definitely want a new database table for this information, rather than modifying the existing one. The reason for this being that we'd need to maintain a "history" of the messages being sent. Otherwise if a node were flagged, unflagged, then flagged again (think global flags especially), only the last message would ever be displayed and the previous two messages would be destroyed.

sirkitree’s picture

I thought about having a separate table, but decided against it for three reasons.
1) flag_content table has no primary key
2) the message in my use case only needs to be persistent while the flag is active (flags are deleted on unflag)
C) I didn't take global flags into consideration :P

mooffie’s picture

1) flag_content table has no primary key

Perhaps it's off-topic, but here I mentioned two reasons to have a primary key on that table.

sirkitree’s picture

StatusFileSize
new9.7 KB

Here's the working module.

Depends on this patch #328383: Provide hook_preprocess_link() to Drupal 5 being applied to flag.module

Still just ALTERs the flag_content table. Will gladly move it out into it's own table if we get a primary key on the flag_content table.

For now, it completely negates the AJAX call on flag links in favor of a separate page for entering text. I'd like to throw this into a jQmodal or something similar. Unflagging takes you to a confirmation page.

Most of this is a pretty large functionality change to how Flag works, and so should most likely be an addon module with it's own project I suppose, but I'm not in any hurry. I'd love to see if anyone else wants this sort of functionality first and then we can take it from there.

The next part of my project will be a friends module that utilizes the Flag API and will use this module as well in order to send a message to a friend when you flag them as such.

I'd love to know if there is a better way to go about the manipulation of the flag settings forms. For now I'm using hook_form_alter, but it looks like there maybe a way to do this through OOP?

sirkitree’s picture

Title: Flag text: dependent module or feature request? » Flag forms: dependent module or feature request?
StatusFileSize
new6.33 KB

After going over a couple more use cases today for out platform, I've changed direction quite a bit for this module. I was implementing much of this in a way that kept my next task in mind, that being a way to save a text message with a flag. However, the more general use that is really needed is the ability to redirect the user to a form. The part where extra data is saved to the table should be implemented by the module providing the form.

So I present a slimmer version now called flag_form. This basically adds a checkbox to the flag creation form to enable flag_form on any given flag. However there must be a module that implements a form for that flag, hook_{flagname}_form() in order for it to do anything.

So a use case then would be, enable flag_form, enable flag_friend. flag_friend on install creates a flag and has a function called flag_friend_{flagname}_form(). flag_form will see if flag_form is enabled for a flag and detect if there is a module that implements the hook. If both conditions are true it will change the href of the flag. This new link is handled by flag_form instead of flag and presents the user with a page that displays the appropriate form before actually saving the flag. On submission of that form, a flag is created and the data for the form is handled by the respective module (flag_friend in this case).

This negates the need to alter the flag_content table, but then flag_friend might do this unless we get the singular primary key on the flag_content table.

quicksketch’s picture

Status: Active » Fixed

Hopefully with #160519: Allow admin to select Ajax or non-ajax behaviour per Bookmark type, this module is not longer necessary.

sirkitree’s picture

Note that this is now obsolete as nate suggested in #6

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.