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

CommentFileSizeAuthor
#1 simplenews.590736.patch1.25 KBsutharsan

Comments

sutharsan’s picture

Version: 6.x-1.x-dev » 6.x-2.x-dev
Status: Active » Fixed
StatusFileSize
new1.25 KB

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()

Status: Fixed » Closed (fixed)

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