addtocalendar.module 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. /**
  3. * @file
  4. * Contains module code.
  5. */
  6. use Drupal\Core\Routing\RouteMatchInterface;
  7. require 'includes/addtocalendar.form.inc';
  8. require 'includes/addtocalendar.build.inc';
  9. /**
  10. * Implements hook_help().
  11. */
  12. function addtocalendar_help($route_name, RouteMatchInterface $route_match) {
  13. switch ($route_name) {
  14. case 'help.page.addtocalendar':
  15. $output = file_get_contents(drupal_get_path('module', 'addtocalendar') . '/README.md');
  16. return $output;
  17. }
  18. }
  19. /**
  20. * Implements hook_field_formatter_third_party_settings_form().
  21. */
  22. function addtocalendar_field_formatter_third_party_settings_form($plugin, $field_definition, $view_mode, $form, $form_state) {
  23. $element = [];
  24. if (count(array_intersect(['datetime', 'daterange'], $plugin->getPluginDefinition()['field_types']))) {
  25. $settings = $plugin->getThirdPartySettings('addtocalendar');
  26. $element = _addtocalendar_build_form($settings, $field_definition);
  27. }
  28. return $element;
  29. }
  30. /**
  31. * Implements hook_field_formatter_settings_summary_alter().
  32. */
  33. function addtocalendar_field_formatter_settings_summary_alter(&$summary, $context) {
  34. if (count(array_intersect(['datetime', 'daterange'], $context['formatter']->getPluginDefinition()['field_types']))) {
  35. if ($context['formatter']->getThirdPartySetting('addtocalendar', 'addtocalendar_show')) {
  36. $summary[] = t('Add to calendar enabled');
  37. }
  38. }
  39. }
  40. /**
  41. * Implements hook_preprocess_field().
  42. */
  43. function addtocalendar_preprocess_field(&$variables) {
  44. if ($variables['field_type'] == 'datetime' || $variables['field_type'] == 'daterange') {
  45. _addtocalendar_preprocess_field($variables);
  46. }
  47. }