As there's been lots of talk about an alternative for the default collapsiblock UI at the bottom of the node (http://drupal.org/node/189977), I thought I would start the process. In my design it's best to simply have the "Subscribe to post" as a node link that takes you to a separate page.
The following consists of adding two functions to template.php and creating a node with a small php snippet.
On my site, we use "watch" instead of "subscribe", so just substitute the words accordingly.
First, let's create a 'watch page' with PHP input format:
$nid = $_GET['nid'];
if ($nid) {
echo drupal_get_form('subscriptions_ui_node_form', node_load($nid));
} else {
preg_match('/nid\=(\d+)/', $_SERVER['HTTP_REFERER'], $matches);
$redirect = $matches[1];
if ($redirect) {
echo "<h2 class='title'>Watch settings saved.</h2>";
echo "<h4><a href='/node/$redirect'>Go back to the post</a></h4>";
}
}
note: include the php start/end tags
This will take in a node id from the URL variable 'nid' and display the subscriptions form. Take note of the node id of the page.
Now we alter the default subscription form.
* Replace 567 with your 'watch page' nid in both functions.
* Replace 'pages/watch' with your 'watch page' alias (node/567,etc) in both functions (be mindful of regex syntax in first one).
--- template.php ---
function subscriptions_form_alter($form_id, &$form) {
$watch_page_nid = '567';
if ($form_id == 'subscriptions_ui_node_form') {
if (preg_match('/^\/pages\/watch/',$form['#action'])) {
if ($form['#parameters']['1']->nid == $watch_page_nid) {
// unset the "watch" form on the watch page
$unset = 1;
} else {
// modify form
$form['wrapper']['#collapsible'] = FALSE;
$form['wrapper']['#collapsed'] = FALSE;
$form['wrapper']['#description'] = '<h2 style="margin-bottom:0">'.$form['#parameters']['1']->title.'</h2>';
$form['#action'] = '/pages/watch?nid=552&r=1';
}
} else {
// unset all watch forms except on the "watch" page
$unset = 1;
}
if ($unset == 1) {
$form = array();
}
}
}
function node_link_alter(&$node, &$links) {
foreach($links as $module => $link) {
/* only run this when other node links are present (statistics_counter being
* the indicator), otherwise the 'title' gets added to tags.
*/
if (strstr($module, 'statistics_counter')) {
if ($node->nid == '567') {
$links = array(); // no links on the watch page
} else {
$links['subscriptions'] = array(
'title' => t('Subscribe'),
'href' => 'pages/watch',
'query' => 'nid='.$node->nid,
'attributes' => array('title' => 'Get update notifications'),
);
}
}
}
}
This approach uses the already present building blocks with very minimal alterations. I welcome any feedback to improve this.
| Comment | File | Size | Author |
|---|---|---|---|
| #5 | subscriptions_ui.link_.patch | 4.73 KB | salvis |
| #1 | subscriptions_node_links.txt | 2.35 KB | mr.andrey |
Comments
Comment #1
mr.andrey commentedI guess [code] tags didn't really work. Attached is a text version.
Andrey.
P.S. Whoever has the perms, feel free to clean up the above mess - I can't edit it.
Comment #2
mr.andrey commentedOops, please take out the following line to make the above work (testing left over):
$form['#action'] = '/pages/watch?nid=552&r=1';
Comment #3
gustav commentedComment #4
salvisThis is not a patch (it doesn't have patch format), and it's not suitable for inclusion in a module.
Creating a node with some PHP code and mis-using that node as a form is a quick hack that you can do on your own site, but a module has to create a real form when it needs one.
I let this stand for those who want to play with it, but I already have a plan for implementing this, and I'll post a patch in the next few days so that we can discuss it.
@mr.andrey: To avoid creating a mess you can use the
tag (written exactly as it appears here, but do use preview!), if you must post code. However, if you hope to have your code included in a module (and properly attributed to you), then you need to supply it as a patch file. This won't work for interactive hacks, of course, precisely because these can't be integrated into a module.Comment #5
salvisHere's a patch that implements an optional Subscribe link, which
– either makes the node form visible as before, or
– makes it visible in a new block that you should put into the content area.
Look at Display settings under admin/settings/subscriptions.
I believe this is the last major open issue from the thick UI thread. Let me know what you think...
@mr.andrey: I hope you don't mind me tagging on to your issue here.
Comment #6
mr.andrey commentedHi there,
I applied the patch and enabled the option in the settings. The link shows up in the links below the node, it takes me to "node/624/subscribe#subscriptions-ui-node-form" - a page where I still see the node, but no subscription form.
Andrey.
Comment #7
salvisIf you set it to appear in the block, then you must also make the block visible in a separate step (the fine print in Display settings).
Comment #8
mr.andrey commentedThis works great. Thanks, Salvis!
Andrey.
Comment #9
salvisI must admit I'm quite pleased with it now. The setting that I like best is all three options on the other side of the defaults. Unfortunately, this requires enabling the block, so I can't make it the default.
Comment #10
Anonymous (not verified) commentedAutomatically closed -- issue fixed for two weeks with no activity.