Preprocess views view to concat two dates and add variable I've been trying to get a custom format placed upon a date range with particular rules (Explained in code comments) within Drupal 8 views.

What I currently have worked with regard to me being able to get the original two dates and to customize them but what I can't seem to do is pass the result ($display_date_range) forward to the fields view TWIG file (views-view-field--group-travel.html.twig)

What I have so far

/*****************************************************************************
 * VIEWS VIEW PRE-PROCESS
 * @param $variables
 *****************************************************************************/
function cazloyd_preprocess_views_view(&amp;$variables) {
  $view = $variables['view'];
  $id = $view-&gt;storage-&gt;id();

  // Handle the Group Travel Listing view
  if($id == 'group_travel_listing'){
    foreach ($view-&gt;result as $key =&gt; $result){
      // Get start date from view
      $date_start = $result-&gt;_entity-&gt;get('field_start_date')-&gt;getValue();

      // Get end date from view
      $date_end = $result-&gt;_entity-&gt;get('field_end_date')-&gt;getValue();

      $months_are_same = (date('n', strtotime($date_start[0]['value']))==date('n', strtotime($date_end[0]['value'])))?TRUE:FALSE;

      if($months_are_same){
        // Month of start and end date are same, show only the day part of the start date
        // e.g. 11 - 23 July 2017
        $formatted_date_start = date('j', strtotime($date_start[0]['value']));
      }else{
        // Event crosses over into new month, therefore show day and month part of start date
        // e.g. 11 July - 5 August 2017
        $formatted_date_start = date('j F', strtotime($date_start[0]['value']));
      }

      $formatted_date_end = date('j F Y', strtotime($date_end[0]['value']));

      // Build final date range
      $display_date_range = $formatted_date_start . ' - ' . $formatted_date_end;

      echo '&lt;pre&gt;';
      print_r($display_date_range);
      echo '&lt;/pre&gt;';
    }
  }
}
hook_preprocess_views_view() is used to alter the variables that are passed to a views-view[...].html.twig template file which is for the entire View, not just for the fields. It might make more sense for you to use hook_preprocess_views_view_fields() or hook_preprocess_views_view_field() since you are trying to alter the variables that are used in a views-view-field[...].html.twig template file (specific to the individual field, not the whole view).

See:

https://api.drupal.org/api/views/theme%21theme.inc/function/template_preprocess_views_view_fields/7.x-3.x

https://api.drupal.org/api/views/theme%21theme.inc/function/template_preprocess_views_view_field/7.x-3.x