How to Output Realtime Computed Field Value I have created a computed field (computed_field module) and I'd like the calculated value of this field to be computed on the fly for each of my views results.
Specifically, I have a start time, and and end time for each &quot;Offer&quot; (content type) in my view. I have created a computed field that determines whether the current time is between the start time, and end time, and then outputs a string value of &quot;now&quot; or &quot;ending_soon&quot; or &quot;starting_soon&quot; or &quot;default&quot; (if it's outside the parameters). I'm doing this all because I need to use the contents of this calculated field as a path variable for custom map markers in a google map (different 'pins' for offers/deals that are happening now, vs ones that are happen earlier or later in the day).
inside my THEMENAME.theme file:
function computed_field_field_now_compute($entity_type_manager, $entity, $fields, $delta)
{
  // from the database:
  $timestamp = $fields['field_business_dates'][0]['value'] ?? &quot;&quot;;
  $endtimestamp = $fields['field_business_dates'][0]['end_value'] ?? &quot;&quot;;

  $now = gmdate('Y-m-d\TH:i:s\Z');
  $utc = new DateTimeZone('UTC');
  $startDate = new DateTime($timestamp, $utc);
  $endDate = new DateTime($endtimestamp, $utc);
  $nowDate = new DateTime($now, $utc);
  $startSwatch = date_format($startDate, 'B');
  $endSwatch = date_format($endDate, 'B');
  $nowSwatch = date_format($nowDate,'B');
  $cutOffSwatch = 22; // Note: 41.6 = 1 hour;
  $endingSoonTime = $endSwatch - $cutOffSwatch;
  $startingSoonTime = $startSwatch - $cutOffSwatch;
  $value = &quot;default&quot;;

  if ($nowSwatch &gt;= $startSwatch &amp;&amp; $nowSwatch &lt;= $endSwatch) {
    if ($nowSwatch &gt;= $endingSoonTime) {
      $value = &quot;ending_soon&quot;;
    } else {
      $value = &quot;now&quot;;
    }
  } else if ($nowSwatch &gt;= $startingSoonTime &amp;&amp; $nowSwatch &lt;= $startSwatch) {
    $value = &quot;starting_soon&quot;;
  } else {
    // return default value
  }
  return $value;
}

As these calculations are time-sensitive, I've turned off caching with the hope that the values are calculated on the fly and displayed in my view. But they are not displayed in views, and don't seem to display at all unless I save each individual node first. As I have over 6500 nodes...I don't see this as feasible. How can I ensure that when a view needs to display the calculated field, that the calculation is executed and rendered?
&quot;How do I output a computed field value in real time?&quot;
The answer is that you cannot.  The Computed Field module updates the value on entity save.  So, to get the most recent value, you have to save the entity.
If you are trying to show a value that you compute in a view, computed field is a bad solution because you will have to re-save all the entities whenever you display the view, which is horrible for performance.
Alternative solution idea
Since you're doing calculations based on time, one option might be to use Views filters.  Make a primary view that shows the default pins, and then embed or attach additional views that have filters that are set to find the pins for ending_soon and starting_soon.
If you need to override the Views filter calculations, you can do that in hook_views_pre_view():
Here's a code example from one of my sites where I override the filter value to use &quot;midnight for the logged-in user's timezone).&quot;
function MYMODULE_views_pre_view(ViewExecutable $view, $display_id, array &amp;$args) {
  if ($view-&gt;id() === 'my_view' &amp;&amp; ($display_id === 'my_display') {
    $filters = $view-&gt;display_handler-&gt;getOption('filters');
    if ($filters['field_datetime_target_value']) {
      $user_timezone = date_default_timezone_get();
      $current_timestamp = \Drupal::time()-&gt;getCurrentTime();
      $midnight_usertimezone_datestring = MYMODULE_get_midnight_datestring(&quot;$current_timestamp&quot;);

      $filters['field_datetime_target_value']['value']['value'] = $midnight_usertimezone_datestring;
    }
    $view-&gt;display_handler-&gt;overrideOption('filters', $filters);
  }
}