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(&$vars) {
$view = $vars['view'];
if(isset($vars['view']) && ($vars['view']->id() == 'evenementen') && ($vars['view']->current_display == 'accreditaties_overzicht')) {
if($vars['field']->options['id'] ==='nothing_1') {
// Getting the values
$accreditaties = $vars['row']->_entity->get('field_accreditaties');
$accreditaties = $accreditaties->getValue('list');
$amount = count($accreditaties);
$vars['field']->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