uw_ct_event.module 2.64 KB
Newer Older
1
2
3
4
5
6
7
<?php

/**
 * @file
 * Provides configuration and settings for events.
 */

8
use Drupal\node\Entity\Node;
9
10
use Drupal\views\ViewExecutable;

11
12
13
/**
 * Implements hook_views_pre_view().
 */
14
function uw_ct_event_views_pre_view(ViewExecutable $view, $display_id, array &$args) {
15
16
17
18
19
20

  // If we are on an event listing page view,
  // set the default date filter today if no
  // filters are already set.
  if (
    $view->id() == 'uw_view_events' &&
21
    $display_id == 'event_page'
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
  ) {

    // Get the exposed filters from the view.
    $exposed = $view->getExposedInput();

    // If there are no exposed filters set, then set
    // set the default date to today.
    if ($exposed == NULL) {

      // Get todays date in the correct format.
      $exposed['date']['value'] = date('m/d/Y', time());

      // Set the default todays date.
      $view->setExposedInput($exposed);
    }
  }
}

40
/**
Eric Bremner's avatar
Eric Bremner committed
41
 * Implements hook_views_pre_render().
42
 */
43
44
45
46
47
48
function uw_ct_event_views_pre_render(ViewExecutable $view) {

  // Remove exposed filters on block listing view.
  if ($view->id() == 'uw_view_events' &&
    $view->getTitle() == 'Event listing') {
    unset($view->exposed_widgets);
49
50
  }
}
51
52
53
54
55
56
57
58
59
60

/**
 * Implements hook_geofield_map_latlon_element_alter().
 */
function uw_ct_event_geofield_map_latlon_element_alter(array &$map_settings, array &$complete_form, array &$form_state_values) {
  // Library for editing uw_ct_event.
  if ($map_settings['id'] === 'edit-field-uw-event-location-coord-0-value') {
    $complete_form['#attached']['library'][] = 'uw_ct_event/uw_ct_event_edit';
  }
}
61
62
63
64
65
66
67
68
69

/**
 * Implements hook_preprocess_views_view_unformatted().
 */
function uw_ct_event_preprocess_views_view_unformatted(&$variables) {

  // If on an events view, then set the dates.
  if ($variables['view']->id() == 'uw_view_events') {

Eric Bremner's avatar
Eric Bremner committed
70
    $uwService = \Drupal::service('uw_cfg_common.uw_service');
71

72
73
74
75
76
77
78
    // For each row, get the data out and the node data.
    foreach ($variables['rows'] as $row) {

      // Load the node.
      $node = Node::load($row['content']['#row']->nid);

      // Get the node data.
Eric Bremner's avatar
Eric Bremner committed
79
      $node_data = $uwService->uwGetNodeContent($node, 'teaser');
80
81

      // Get the date info.
82
83
84
      $date['value'] = $row['content']['#row']->node__field_uw_event_date_field_uw_event_date_value;
      $date['end_value'] = $row['content']['#row']->node__field_uw_event_date_field_uw_event_date_end_value;
      $date['duration'] = $row['content']['#row']->node__field_uw_event_date_field_uw_event_date_duration;
85
86

      // Set the date on the node data.
Eric Bremner's avatar
Eric Bremner committed
87
      $node_data['date'] = [$uwService->uwGetDate($date, 'event')];
88
89
90
91
92
93

      // Set a variable for the node data.
      $variables['node_data'][] = $node_data;
    }
  }
}