diff --git a/simplenews_realname.module b/simplenews_realname.module index 7a4cb60..8f4807d 100644 --- a/simplenews_realname.module +++ b/simplenews_realname.module @@ -82,7 +82,8 @@ function simplenews_realname_form_alter(&$form, $form_state, $form_id) { // Add textfield for real name to subscription forms. if (strpos($form_id, 'simplenews_block_form') !== FALSE || $form_id == 'simplenews_subscription_page_form' - || $form_id == 'simplenews_subscriptions_multi_block_form') { + || $form_id == 'simplenews_subscriptions_multi_block_form' + || $form_id == 'simplenews_subscriptions_admin_form') { $realname_field = array( '#type' => 'textfield', '#title' => t('Name'), @@ -173,6 +174,15 @@ function simplenews_realname_form_alter(&$form, $form_state, $form_id) { // Make sure our submit callback executes first. array_unshift($form['#submit'], 'simplenews_realname_multiblock_form_submit'); break; + // Subscription page (for anonymous users). + case 'simplenews_subscriptions_admin_form': + $form['subscriptions']['realname'] = $realname_field; + $form['subscriptions']['realname']['#default_value'] = _simplenews_realname_get_realname($form['subscriptions']['mail']['#value']); + // Add after_build callback to skip "Name" validation on unsubscription. + $form['#after_build'] = array('simplenews_realname_subscriptions_page_form_after_build'); + // Make sure our submit callback executes first. + array_unshift($form['#submit'], 'simplenews_realname_subscriptions_page_form_submit'); + break; // Subscriptions page. case 'simplenews_subscriptions_page_form': $form['subscriptions']['realname'] = $realname_field; @@ -359,6 +369,12 @@ function simplenews_realname_subscriptions_page_form_after_build($form, &$form_s case t('Unsubscribe'): unset($form['subscriptions']['realname']['#required']); break; + case t('Update'): + $checked_newsletters = array_filter($form_state['values']['newsletters']); + if (!count($checked_newsletters)) { + unset($form['subscriptions']['realname']['#required']); + } + break; } return $form; }