Calculate Database Field Value and Send to Views as New Field I have a database field which stores a timestamp. This timestamp is sent to a custom views provider via hook_views_data(). This timestamp field is created as a date field to utilize the date format options from views.

$data['module']['timestamp'] = [
  'title' =&gt; t('Timestamp'),
  'help' =&gt; t('Timestamp from module'),
  'field' =&gt; [
    'id' =&gt; 'date',
  ],
  'sort' =&gt; [
    'id' =&gt; 'date',
  ],
  'filter' =&gt; [
    'id' =&gt; 'date',
  ],
];




In another views field (but with the same DB field), I would like to get the raw field value and run it through something like:

if (field_value &gt; (time() - 800))




This is a custom module and would prefer not to have any more dependencies. Can this be achieved with hook_views_data() or hook_views_pre_render() or such?

I know there is a contributed module https://www.drupal.org/project/computed_field, but again hoping there is a way in those hooks, or in the view...

The DB table is created with hook_install() and the desired timestamp field output after check would be markup. Happy if it is just sent as markup to the views field.



I've figured how to access the field values with hook_views_pre_render() as such:

function hook_views_pre_render(&amp;$view) {
  $result = $view-&gt;result;
  foreach ($result as $key =&gt; $row) {
    kpr($result[$key]-&gt;field_name);
    if ($result[$key]-&gt;timestamp &gt; (time() - 800)) {
      // Can I do anything here?
    }
    else {
      //
    }
  }
}


Unfortunately, that is not the most important piece of the puzzle. And it is not possible to just add $data['module']['key'] to my hook_views_data() as this requires the unique DB field to exist.

In my use case, I'd be happy if I could rewrite the original timestamp field and append this markup to it.
Take a look at this, it shows how you can create custom fields that you can use within views https://www.webomelette.com/creating-custom-views-field-drupal-8

I've followed this recently and seems to work well