Add new comment

Hi,

I Want to display user block unblock icon based on the user status, but unfortunately I am getting always last row user status, and it's apply to the all row, for example if my last row user status is 1 then remaining rows will keep as same status 1

MY CODE :

  
function MODULENAME_views_pre_render(&$view) {
  if ($view->name == 'MY_user_management') {
    
    foreach ($view->result as $index => &$result) {

      $icon = 'glyphicon-ban-circle';
      $title = 'Block user';

      if($result->_field_data['uid']['entity']->status == 0)  {
        $icon = 'glyphicon-ok-circle';
        $title = 'Unblock user';
      }
     
      $result->_field_data['uid']['entity']->MYFIELD = 
      
      '<a href="#" data-uid="[uid]" data-name="[field_firstname]" title="'. $title. '" class="my-block-user [status]">
      <span class="glyphicon '. $icon. '"></span></a>';

    }
    $view->style_plugin->render_fields($view->result);
    foreach ($view->style_plugin->rendered_fields as $index => &$rendered_result) { 
      
      $rendered_result['MYFIELD'] = $result->_field_data['uid']['entity']->MYFIELD;
    }
  }
  

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.