Views alter changes next row instead of current one I have a view that is showing event content types. Users can apply for these events. I am using a hook to alter the 'view applicants' so I can show how many applications already excist. 

The following code works and shows the values but is somehow skipping the first row and printing all the values one row later.

function frontview_general_preprocess_views_view_field(&amp;$vars) {

  $view = $vars['view'];

  if(isset($vars['view']) &amp;&amp; ($vars['view']-&gt;id() == 'evenementen') &amp;&amp; ($vars['view']-&gt;current_display == 'accreditaties_overzicht')) {

    if($vars['field']-&gt;options['id'] ==='nothing_1') {

      // Getting the values
      $accreditaties = $vars['row']-&gt;_entity-&gt;get('field_accreditaties');
      $accreditaties = $accreditaties-&gt;getValue('list');
      $amount = count($accreditaties);   

      $vars['field']-&gt;options['alter']['text'] = 'View Applicants ('. $amount .')';
    }

  }
}


This is my current output, the first row still shows the normal values without the hook but the first row values are printed on the second row, second row on third row, ... 



This is the output that I need 



I'm not sure why it's doing that, when I dd() my code it looks fine.

Thanks in advance! 

*Drupal 8
Got it to work with the following code. I needed to output the changed value in the $vars['output']. This would override the url in the nothing_1 field so I then had to create a new link and use that to alter the original value.

/**
 * Implements hook_preprocess_views_view_field().
 */
function frontview_general_preprocess_views_view_field(&amp;$vars) {

  $view = $vars['view'];

  if(isset($vars['view']) &amp;&amp; ($vars['view']-&gt;id() == 'evenementen') &amp;&amp; ($vars['view']-&gt;current_display == 'accreditaties_overzicht')) {

    if($vars['field']-&gt;options['id'] ==='nothing_1') {
      $accreditaties = $vars['row']-&gt;_entity-&gt;get('field_accreditaties');
      $accreditaties = $accreditaties-&gt;getValue('list');
      $amount = count($accreditaties);   

      // $vars['field']-&gt;options['alter']['text'] = 'View Applicants ('. $amount .')';

      $nid_value = $vars['row']-&gt;nid;
      $url = Link::fromTextAndUrl(t('View Applicants ('. $amount .')'), Url::fromRoute('view.evenementen.page_2', ['arg_0' =&gt; $nid_value]))-&gt;toString();

      $vars['output'] = $url;
    }
  }
}