You are here

addtocalendar.module in Add To Calendar Button (AddEvent.com) 8.3

Contains module code.

File

addtocalendar.module
View source
<?php

/**
 * @file
 * Contains module code.
 */
use Drupal\Core\Routing\RouteMatchInterface;
require 'includes/addtocalendar.form.inc';
require 'includes/addtocalendar.build.inc';

/**
 * Implements hook_help().
 */
function addtocalendar_help($route_name, RouteMatchInterface $route_match) {
  switch ($route_name) {
    case 'help.page.addtocalendar':
      $output = file_get_contents(drupal_get_path('module', 'addtocalendar') . '/README.md');
      return $output;
  }
}

/**
 * Implements hook_field_formatter_third_party_settings_form().
 */
function addtocalendar_field_formatter_third_party_settings_form($plugin, $field_definition, $view_mode, $form, $form_state) {
  $element = [];
  if ($plugin
    ->getPluginId() !== 'add_to_calendar') {

    // Make sure to avoid confliction in case add_to_calendar field formatter is
    // used.
    if (count(array_intersect([
      'datetime',
      'daterange',
    ], $plugin
      ->getPluginDefinition()['field_types']))) {
      $settings = $plugin
        ->getThirdPartySettings('addtocalendar');
      $element = _addtocalendar_build_form($settings, $field_definition);

      // Unset the start date to avoid conflicts.
      if (isset($element['addtocalendar_settings']['atc_date_start'])) {
        unset($element['addtocalendar_settings']['atc_date_start']);
      }
    }
  }
  return $element;
}

/**
 * Implements hook_field_formatter_settings_summary_alter().
 */
function addtocalendar_field_formatter_settings_summary_alter(&$summary, $context) {
  if (count(array_intersect([
    'datetime',
    'daterange',
  ], $context['formatter']
    ->getPluginDefinition()['field_types']))) {
    if ($context['formatter']
      ->getThirdPartySetting('addtocalendar', 'addtocalendar_show')) {
      $summary[] = t('Add to calendar enabled');
    }
  }
}

/**
 * Implements hook_preprocess_field().
 */
function addtocalendar_preprocess_field(&$variables) {
  if ($variables['field_type'] == 'datetime' || $variables['field_type'] == 'daterange') {
    _addtocalendar_preprocess_field($variables);
  }
}