Browse Source

removed newsletters which user doesn't have access to

Bachir Soussi Chiadmi 8 years ago
parent
commit
f4b8bfa249

+ 29 - 4
sites/all/modules/gui/materiobasemod/materio_user.module

@@ -175,6 +175,23 @@ function materio_user_block_view($delta = '') {
   return $block;
 }
 
+/**
+ * Implements hook_module_implements_alter().
+ */
+function materio_user_module_implements_alter(&$implementations, $hook){
+  if ($hook == 'form_alter') {
+    // It is to ensure that hook_form_alter of this module is called
+    // after all other hooks
+    $group = $implementations['materio_user'];
+    if (isset($group)) {
+      unset($implementations['materio_user']);
+      // Then add it back, so it will be at the end of hook array
+      $implementations['materio_user'] = $group;
+    }
+  }
+}
+
+
 /**
  * Implements hook_form_alter().
  */
@@ -218,11 +235,19 @@ function materio_user_form_alter(&$form, &$form_state, $form_id) {
     materio_user_uc_cart_checkout_form_alter($form, $form_state, $form_id);
   }
 
-  // if( $form_id == "user_profile_form" ){
-  //   //dsm($form, '$form');
-  //   $form['account']['pass']['#type'] = "new_password_confirm";
-  // }
+  // remove newsletters category if user doesn't have access to them
+  if( $form_id == "user_profile_form" ){
+    // dsm($form, '$form');
+    $options = array();
+    foreach ($form['subscriptions']['newsletters']['#options'] as $tid => $name) {
+      if(user_access("subscribe to simplenews category $tid")){
+        $options[$tid] = $name;
+      }
+    }
+    $form['subscriptions']['newsletters']['#options'] = $options;
+  }
 
+  // remove newsletters category if user doesn't have access to them
   if ( $form_id == "simplenews_subscriptions_multi_block_form"){
     // dsm($form);
     $options = array();

+ 1 - 1
sites/all/modules/gui/materiobasemod/materio_user.pages.inc

@@ -77,7 +77,7 @@ function materio_user_export(){
     $vals[] = $rec->mail;
   }
   $ret = "Liste des user utilisateur inscrits au daily<br />";
-  $ret .= '<textarea >'.implode($vals, '&#13;&#10;').'</textarea>';
+  $ret .= '<textarea cols="40" rows="30">'.implode($vals, '&#13;&#10;').'</textarea>';
   return $ret;
 }