How to change view's field (Custom-Text field specifically) value based on other field value using hook_view_pre_render? 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-&gt;id() == 'test_view' &amp;&amp; $view-&gt;current_display == 'block_2') {
    foreach($view-&gt;result as $value){
        $tid = $value-&gt;_entity-&gt;get('tid')-&gt;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-&gt;_entity-&gt;set('nothing', '&lt;h1&gt;This is my custom mark-up&lt;/h1&gt;');
    }
 }
}


I referred the code from these following 2 sources, but they are not dealing with custom-text field:


How to change views field value using a hook
https://api.drupal.org/comment/62573#comment-62573


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.
You can't set a value for "nothing" aka "Global: Custom text" in hook_views_pre_render() because _entity is the entity object. The entity (Taxonomy Term in your case, and Node in my test case) does not contain this field.

Therefore, you need to use template_preprocess_views_view_field

function THENAME_preprocess_views_view_field(&amp;$vars) {
  if(isset($vars['view']) &amp;&amp; ($vars['view']-&gt;id() == 'test_view') &amp;&amp; ($vars['view']-&gt;current_display == 'block_2')) {
    if (isset($vars['view']-&gt;field) &amp;&amp; (count($vars['view']-&gt;field) &gt; 0)) {
      if ($vars['field']-&gt;field == 'nothing') {
        $tid = $vars['row']-&gt;_entity-&gt;get('tid')-&gt;value; // get tid
        if ($vars['field']-&gt;field == 'nothing') {
          $vars['output'] = [
            '#markup' =&gt; "&lt;h1&gt;This is my custom mark-up with term id: $tid&lt;/h1&gt;",
          ];
        }
      }
    }
  }
}