Yes, I see there are many answers already posted here and elsewhere for this; but sadly they are all wrong. These answers include any of the following:
$view->style_plugin->getFieldValue($rid, 'field_myfield');
foreach ($view->result as $rid => $row) {
foreach ($view->field as $fid => $field ) {
$values[$rid][$fid . '-value'] = $field->getValue($row);
$values[$rid][$fid . '-render'] = $field->render($row);
}
}
$views->_entity->...
or a few others. These are all returning the field of the base entity returned by the view. These are entity field values. These are not the "fields of the view".
I know how to access these in a twig template (views-view-fields--[viewname]--[displayname].html.twig) but haven't been able to find out how to do this in a custom module.
Answer:
From @4k4's tip below:
This works:
foreach ($view->result as $rid => $row) {
$type[$row->nid] = $view->field['my_views_field']->advancedRender($row)->__toString();
}
$view->field
contains the fields you have configured in the FIELDS section of the View. Each field is a field handler plugin and if you want to render a field exactly like it is configured in the View then use the plugin method advancedRender($row).