You are here

date_recur.module in Recurring Dates Field 3.1.x

File

date_recur.module
View source
<?php

/**
 * @file
 * Contains hooks for date_recur module.
 */
declare (strict_types=1);
use Drupal\Core\Render\Element;
use Drupal\date_recur\DateRecurCachedHooks;
use Drupal\date_recur\DateRecurViewsHooks;
use Drupal\field\FieldStorageConfigInterface;

/**
 * Implements hook_theme().
 */
function date_recur_theme(array $existing, string $type, string $theme, string $path) : array {

  /** @var \Drupal\date_recur\DateRecurCachedHooks $cachedHooks */
  $cachedHooks = \Drupal::classResolver(DateRecurCachedHooks::class);
  return $cachedHooks
    ->hookTheme($existing, $type, $theme, $path);
}

/**
 * Implements hook_field_info_alter().
 */
function date_recur_field_info_alter(array &$info) : void {

  /** @var \Drupal\date_recur\DateRecurCachedHooks $cachedHooks */
  $cachedHooks = \Drupal::classResolver(DateRecurCachedHooks::class);
  $cachedHooks
    ->fieldInfoAlter($info);
}

/**
 * Implements hook_field_views_data().
 */
function date_recur_field_views_data(FieldStorageConfigInterface $fieldDefinition) : array {

  /** @var \Drupal\date_recur\DateRecurViewsHooks $viewsHooks */
  $viewsHooks = \Drupal::classResolver(DateRecurViewsHooks::class);
  return $viewsHooks
    ->fieldViewsData($fieldDefinition);
}

/**
 * Implements hook_views_data().
 */
function date_recur_views_data() : array {

  /** @var \Drupal\date_recur\DateRecurViewsHooks $viewsHooks */
  $viewsHooks = \Drupal::classResolver(DateRecurViewsHooks::class);
  return $viewsHooks
    ->viewsData();
}

/**
 * Implements hook_views_data_alter().
 */
function date_recur_views_data_alter(array &$data) : void {

  /** @var \Drupal\date_recur\DateRecurViewsHooks $viewsHooks */
  $viewsHooks = \Drupal::classResolver(DateRecurViewsHooks::class);
  $viewsHooks
    ->viewsDataAlter($data);
}

/**
 * Template preprocessor for 'date_recur_settings_frequency_table'.
 *
 * @param array $variables
 *   An associative array containing:
 *   - element: An associative array containing a Form API structure to be
 *     rendered as a table.
 */
function template_preprocess_date_recur_settings_frequency_table(array &$variables) : void {
  $partTitles = [];

  // Transfer elements to 'table' key so they can be iterated on without
  // clashing with '#' elements.
  $variables['table'] = [];
  foreach (Element::children($variables['element']) as $key) {
    $variables['table'][$key] = $variables['element'][$key];
    $row =& $variables['table'][$key];
    foreach (Element::children($row['parts']) as $rowKey) {
      $row['parts']['parts'][$rowKey] = $row['parts'][$rowKey];
      unset($row['parts'][$rowKey]);
      foreach ($row['parts']['parts'] as $part) {
        $partTitles[] = $part['#title'];
      }
    }
    unset($variables['element'][$key]);
  }
  $variables['all_parts'] = array_unique($partTitles);
}