0

I have set up user comment email notification on my Drupal 7 site. When a comment is posted the author is notified by email. I did it using rules module as described here.

Now the user has the option to get notified or not. For this, I added a new boolean field checkbox on the user's account form page. So currently the user must go to his user account page to change this setting. I would like to make this setting available in a panel.

How can I add a checkbox to a panel in order to control that "notify me setting"? (The panel currently displays content type fields, comment forms etc).

1

One way is to define your own form and add it to a block in the panel.

After that, you save the value to the user account in the form submit handler.

Background:

Form generation summary

Relevant hooks:

and some custom functions you'll need.

  • my_module_user_notify_form ( return form array )
  • my_module_user_notify_form_submit ( save to user )

If you use something like Profile2, you could also just embed the relevant user profile form in the block. It would then handle the form build and processing for you.

  • How would I implement my_module_user_notify_form and my_module_user_notify_form_submit. Any tip, pointers? I am pretty clueless. Shall i use db_query? – Baba May 31 '13 at 19:11
1

Ok, thanks to David's post, Panel now does let me choose my new block as content to add to the panel. I post the code below:

function mymodule_block_info() {
// This example comes from node.module.                                                                                                                                                 
$blocks['testblock'] = array(
                           'info' => t('Test'),
                           'cache' => DRUPAL_NO_CACHE,
                           );
return $blocks;
}

function mymodule_block_view($delta = '') {
// This example is adapted from node.module.                                                                                                                                            
$block = array();

switch ($delta) {
               case 'testblock':
                 //  case 'recent':                                                                                                                                                   
                 $block['subject'] = t('Test');
                 $block['content'] =  drupal_get_form('mymodule_example_form');
                 //krumo($block);
                 break;
              }

//return $block['content'];
  return $block;
}

function mymodule_example_form($form, &$form_state) {

 $form['notify_me'] = array(
                         '#type' => 'checkbox',
                         '#title' => t('Notify me by email when I receive a new message'),
                         '#description' => t("Check this option to be notified by email when you receive a new message"),
                         );

 $form['submit'] = array(
'#type' => 'submit',
'#value' => t('Submit'),
 );
 return $form;
}

function kl_example_form_validate($form, &$form_state) {
// Validation logic.                                                                                                                                                                    
}

function kl_example_form_submit($form, &$form_state) {
// Submission logic.                                                                                                                                                                    

}

  • So the error was that hook_block_view was returning $block['content'] instead of $block. I just did the edit in this post. Now the form displays! – Baba May 30 '13 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.