Download & Extend

Block Submit class & wrapper API function for subscriptions

Project:Simplenews
Version:6.x-2.x-dev
Component:Code
Category:feature request
Priority:minor
Assigned:Unassigned
Status:closed (fixed)

Issue Summary

Hi just a couple trivial feature requests.

1) Adding a class to the block submission to help themers

<?php
  $class
= 'simplenews';
  if (isset(
$submit_text)) {
   
$class .= ($submit_text == t('Subscribe')) ? '-subscribe' : '-unsubscribe');
  }
 
$form['submit'] = array(
   
'#type' => 'submit',
   
'#value' => isset($submit_text) ? $submit_text : t('Save'),
   
'#attributes' => array('class' => $class)
  );
?>

In case other people need a similar thing and this is not pushed into the module, a simple form alter can add the class:

<?php
 
function MYMODULE_form_alter(&$form, $form_state, $form_id) {
    if (
strpos($form_id, 'simplenews_block_form_') === 0) { // Must be === and not ==
     
$form_id = 'simplenews_block_form';
    }
    switch (
$form_id) {
      case
'simplenews_block_form':
       
$class = ' simplenews-'. (($form['submit']['#value'] == t('Subscribe')) ? ' subscribe' : 'unsubscribe');
       
$form['submit'] += array('#attributes' => array()); // E_ALL error prevention
       
$form['submit']['#attributes'] += array('class' => ''); // And another
       
$form['submit']['#attributes']['class'] .= $class;
        break;
    }
  }
?>

2) Is it possible to create a new function simplenews_get_subscriptions()? I need to get the subscription list and was forced to duplicate a lot of the internal logic to get the list of names / tids. This should be statically cached if used multiple times per request (like if it becomes a storage mechanisum for translated names).

<?php
function simplenews_get_subscriptions() {
  if (
module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_TRANSLATE) {
   
// Per language terms.
   
$tterms = i18ntaxonomy_vocabulary_get_terms(variable_get('simplenews_vid', ''), $language->language);
    foreach (
$tterms as $tid => $name) {
     
$options[$tid] = check_plain($name);
    }
  }
  else {
    foreach (
taxonomy_get_tree(variable_get('simplenews_vid', '')) as $newsletter) {
      if (
module_exists('i18ntaxonomy') && i18ntaxonomy_vocabulary(variable_get('simplenews_vid', '')) == I18N_TAXONOMY_LOCALIZE) {
       
// Localize terms.
       
$options[$newsletter->tid] = check_plain(tt('taxonomy:term:'. $newsletter->tid .':name', $newsletter->name, $language->language));;
      }
      else {
       
// Untranslated.
       
$options[$newsletter->tid] = check_plain($newsletter->name);
      }
    }
  }
  return
$options;
}
// and in _simplenews_subscription_manager_form (maybe other places)
 
$form['subscriptions']['newsletters'] = array(
   
'#type' => 'checkboxes',
   
'#options' => simplenews_get_subscriptions(),
   
'#default_value' => ((array) $subscription->tids), // I do not think you need to initiate all defaults to zero (I have not tested this)
 
);
?>

Thanks

Comments

#1

Version:6.x-1.x-dev» 6.x-2.x-dev
Status:active» fixed

I've added the class to the block form (attached patch). The function is already available in the 2.x branch as simplenews_get_newsletters()

AttachmentSizeStatusTest resultOperations
simplenews.590736.patch1.25 KBIgnored: Check issue status.NoneNone

#2

Status:fixed» closed (fixed)

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

nobody click here