You are here

function opigno_calendar_preprocess_calendar_month_col in Opigno calendar 3.x

Same name and namespace in other branches
  1. 8 opigno_calendar.module \opigno_calendar_preprocess_calendar_month_col()

Implements hook_preprocess_HOOK().

File

./opigno_calendar.module, line 49
Contains opigno_calendar.module.

Code

function opigno_calendar_preprocess_calendar_month_col(&$variables) {
  if (empty($variables['item']['entry'])) {
    return;
  }
  $entry =& $variables['item']['entry'];
  if ($variables['item']['date'] === date('Y-m-d')) {
    $variables['item']['entry']['#selected'] = TRUE;
  }
  if (!is_array($entry) || isset($entry['#theme'])) {
    return;
  }
  $attached = [
    'library' => [
      'opigno_calendar/month_block',
    ],
  ];
  if (isset($entry[0]['#theme']) && $entry[0]['#theme'] === 'calendar_empty_day') {
    $entry['#attached'] = $attached;
    return;
  }

  /** @var \Drupal\views\ViewExecutable $view */
  $view = $entry[0]['#view'];
  if (!$view || $view
    ->getDisplay()
    ->getOption('css_class') !== 'opigno-calendar-views' && $view
    ->getDisplay()
    ->getOption('css_class') !== 'view-opigno-calendar' || $view->current_display !== 'month_block' && $view->current_display !== 'page_month') {
    return;
  }

  // Add see more link for month_block.
  if ($view->current_display === 'month_block') {

    // display only 2 events.
    if (count($entry) > 2) {
      $entry = array_slice($entry, 0, 2);
    }
    $month = $view->args[0];
    $entry[] = [
      '#title' => t('See more'),
      '#type' => 'link',
      '#url' => URL::fromUri('internal:/opigno/calendar/' . $month, [
        'query' => [
          'day' => $variables['item']['day_of_month'],
        ],
      ]),
    ];
  }
  $entry = opigno_calendar_generate_entry($variables, $entry, $attached);
}