I have created a taxonomy-term view. I have added two fields in a view: term-id and custom-text field.
I want to check if term-id has children and depending upon the result, I want to set markup inside custom-text field.
I am able to get term-id in hook_views_pre_render with following code, but I am not able to set the value of custom-text field
function mymodule_views_pre_render(\Drupal\views\ViewExecutable $view) {
if ($view->id() == 'test_view' && $view->current_display == 'block_2') {
foreach($view->result as $value){
$tid = $value->_entity->get('tid')->value;
kint($tid);
//trying to set value for custom text field, with foll. line of code
//'nothing' is the field-name you get for any custom-text field
$value->_entity->set('nothing', '<h1>This is my custom mark-up</h1>');
}
}
}
I referred the code from these following 2 sources, but they are not dealing with custom-text field:
Or should I use template_preprocess_views_view_fields(), if yes then how can I get term-id value to check if it has children terms.
Any help will be appreciated.