Last updated March 27, 2011. Created by pasive on July 20, 2010.
Edited by silverwing. Log in to edit this page.

Ok,

Some weeks ago I,ve installed Simplenews module for one of my Drupal developments, as you may notice there are a lots of discussions going regarding displaying of subscribe/save button in the Simplenews block, most of them - how to change default SAVE when user is not logged in to Subscribe (or whatever).
First I,ve tested well known function themename_simplenews_block () - no results, I went through all .module code and of course I didn,t found any implementation oh the about function, of course there is simplemenys_theme (implementation of hook_theme) on line 2428, but as you can see;

<?php
function simplenews_theme() {
  return array(
   
'simplenews_block' => array(
     
'template' => 'simplenews-block',
     
'arguments' => array('tid' => NULL),
     
'pattern' => 'simplenews_block__',
    ),
   
'simplenews_status' => array(
     
'template' => 'simplenews-status',
     
'file' => 'simplenews.admin.inc',
     
'arguments' => array('status' => NULL, 'source' => NULL),
    ),
   
'simplenews_newsletter_subject' => array(
     
'arguments' => array('name' => NULL, 'title' => NULL, 'language' => NULL),
    ),
   
'simplenews_newsletter_body' => array(
     
'template' => 'simplenews-newsletter-body',
     
'arguments' => array('node' => NULL, 'language' => NULL),
     
'pattern' => 'simplenews_newsletter_body__',
    ),
   
'simplenews_newsletter_footer' => array(
     
'template' => 'simplenews-newsletter-footer',
     
'arguments' => array('node' => NULL, 'key' => NULL, 'language' => NULL),
     
'pattern' => 'simplenews_newsletter_footer__',
    ),
   
'simplenews_subscription_list' => array(
     
'file' => 'simplenews.admin.inc',
     
'arguments' => array('form' => NULL),
    ),
  );
}
?>

It is rendering only main elements - not any specific page or block ones as themselves.
Getting inspired by Documentation of custom modules and http://drupal.org/node/569312,
Here is full process.
First - from (on line 2471) simplenews.module copy this and;
<?php
function template_preprocess_simplenews_block(&$variables) {
  global
$user;
 
$tid = $variables['tid'];
 
// Set default values in case of missing permission.
 
$variables['form'] = '';
 
$variables['subscription_link'] = '';
 
$variables['newsletter_link'] = '';
 
$variables['issue_list'] = '';
 
$variables['rssfeed'] = '';
 
// Block content variables
 
$variables['message'] = check_plain(variable_get('simplenews_block_m_'. $tid, t('Stay informed on our latest news!')));
  if (
user_access('subscribe to newsletters')) {
   
$variables['form'] = drupal_get_form('simplenews_block_form_'. $tid);
   
$variables['subscription_link'] = l(t('Manage my subscriptions'), 'newsletter/subscriptions');
  }
 
$variables['newsletter_link'] = l(t('Previous issues'), 'taxonomy/term/'. $tid);
 
$recent = simplenews_recent_newsletters($tid, variable_get('simplenews_block_i_'. $tid, 5));
 
$variables['issue_list'] = theme('item_list', $recent, t('Previous issues'), 'ul');
 
$term = taxonomy_get_term($tid);
 
$variables['rssfeed'] = theme('feed_icon', url('taxonomy/term/'. $tid .'/0/feed'), t('@newsletter feed', array('@newsletter' => $term->name)));
 
// Block content control variables
 
$variables['use_form'] = variable_get('simplenews_block_f_'. $tid, 1);
 
$variables['use_issue_link'] = variable_get('simplenews_block_l_'. $tid, 1);
 
$variables['use_issue_list'] = variable_get('simplenews_block_i_status_'. $tid, 0);
 
$variables['use_rss'] = variable_get('simplenews_block_r_'. $tid, 1);
 
// Additional variables
 
$variables['subscribed'] = empty($user->uid) ? FALSE : (simplenews_user_is_subscribed($user->mail, $tid) == TRUE);
 
$variables['user'] = !empty($user->uid);
}
?>

paste it to your themes template.php file and rename it to yourtheme__preprocess_simplenews_block.
Then create a custom module and using hook_form_alter do the staff with your subscription form.
My example here - mycoolmodule.module;
<?php
function mycoolmodule_form_alter(&$form, $form_state, $form_id) {
    if(
$form_id == 'simplenews_block_form_1') {
       
$form['submit']['#value'] = t('Subscribe');
    }
?>

Sounds easy, but some suggestions - first this changes both values to "subscribe", but be careful, because this form offers and unsubscribe option too. - anyway this worked fine for me on two different machines.
Second form_id here is simplenews_block_form_1 , this goes out from - $variables['form'] = drupal_get_form('simplenews_block_form_'. $tid);, so at the end you will have a from with id="simplenews-block-form-1-1" for your later CSS works.

Looking for support? Visit the Drupal.org forums, or join #drupal-support in IRC.

Comments

Hi,

nice tutorial at first. My only question is were do you put your new made .module file? Is it just in the root of your theme or in the simplenews module map?

Greetings

Hi Nielskirkels,

As it is new module file and main purpose of this is of this is to solve appearance of simple news block, this work as standalone module.
I hope it helps.

R.

Please clarify the custom module section. In my case the thing is not working.

Hi,

What is not working in your case? Please explain a little more.

P.

Hi All,
I just uploaded a video tutorial on overriding the simplenews block. I didn't have to touch the template.php file and you'll notice in the tutorial, the custom module which overrides the subscription block is only about 10 lines of code.

How to override the simplenews subscription block on torontowebsitedeveloper.com

In summary, you create a custom module calling hook_form_alter in it, use the code from the tutorial, put the module in your sites/all/modules folder (or whatever equivalent you are using), enable it and you have a good looking block.

This is only tutorial 1 of 2 - in the second, i'll be showing how to get rid of the old school button all together, replacing it with an image button AND showing you how to prefill the form field with some javascript so it functions like the drupal search field at the top of this page...

feel free to contact me with any questions.
pete

Hi,

is there a way to hook the simplenews block form (or other block form in general) for example to change label, input, submit button without creating a module? I'm a themer and I try to work only with template.php file to change the HTML output. Or maybe create only one module to change all the module forms that I have on my Website?
Thanks for your answer.

Maxime

Hey Maxime,
I don't think it can be done at the theme layer because you aren't changing parts of the form that pass through the themeing layer. You can create one module to change all module forms - I think you would just need one function that checks the form ID and makes the appropriate changes for that form ID...

Pete

Great news for all themers ;), It can be done in the theme layer.
Just check this great tutorial from Lullabot
-> http://www.lullabot.com/articles/modifying-forms-drupal-5-and-6