diff --git a/recurring_events.api.php b/recurring_events.api.php new file mode 100644 index 0000000000000000000000000000000000000000..1fc99ce39d49737285d7f0b2db0e46916d4860f1 --- /dev/null +++ b/recurring_events.api.php @@ -0,0 +1,50 @@ +<?php + +/** + * @file + * Custom hooks exposed by the recurring_events module. + */ + +/** + * Alter the time options available when creating an event series entity. + * + * @param array $times + * An array of times in the format h:i a. + */ +function hook_recurring_events_times_alter(array &$times = []) { + // Events cannot occur at midnight. + unset($times['00:00 am']); +} + +/** + * Alter the duration options available when creating an event series entity. + * + * @param array $durations + * An array of durations in seconds. + */ +function hook_recurring_events_durations_alter(array &$durations = []) { + // Events can last for 2 days. + $durations[172800] = t('2 days'); +} + +/** + * Alter the days options available when creating an event series entity. + * + * @param array $days + * An array of available days. + */ +function hook_recurring_events_days_alter(array &$days = []) { + // No events can take place on sundays. + unset($days['sunday']); +} + +/** + * Alter the month days options available when creating an event series entity. + * + * @param array $month_days + * An array of available days of the month. + */ +function hook_recurring_events_month_days_alter(array &$month_days = []) { + // No events can take place on the 17th of a month. + unset($month_days[17]); +} diff --git a/src/Plugin/Field/FieldWidget/MonthlyRecurringDateWidget.php b/src/Plugin/Field/FieldWidget/MonthlyRecurringDateWidget.php index 378cfba0204454173b28c36b5047f7b58c33e164..589375881f4f8d43f78d46fa3b5838cbd935f750 100644 --- a/src/Plugin/Field/FieldWidget/MonthlyRecurringDateWidget.php +++ b/src/Plugin/Field/FieldWidget/MonthlyRecurringDateWidget.php @@ -137,7 +137,7 @@ class MonthlyRecurringDateWidget extends WeeklyRecurringDateWidget { $days[-1] = t('Last'); - // TODO: Add hook ability to modify these days. + \Drupal::moduleHandler()->alter('recurring_events_month_days', $days); return $days; } diff --git a/src/Plugin/Field/FieldWidget/WeeklyRecurringDateWidget.php b/src/Plugin/Field/FieldWidget/WeeklyRecurringDateWidget.php index 7dd971225b2fca7e0daf55ec07b952502823cc92..589f401b446c191f78b07db3b49b352ef5120794 100644 --- a/src/Plugin/Field/FieldWidget/WeeklyRecurringDateWidget.php +++ b/src/Plugin/Field/FieldWidget/WeeklyRecurringDateWidget.php @@ -142,7 +142,7 @@ class WeeklyRecurringDateWidget extends DateRangeDefaultWidget { $times[$time_option->format('h:i a')] = $time_option->format($format); } - // TODO: Add hook ability to modify these times. + \Drupal::moduleHandler()->alter('recurring_events_times', $times); return $times; } @@ -189,7 +189,7 @@ class WeeklyRecurringDateWidget extends DateRangeDefaultWidget { '86400' => t('24 hours'), ]; - // TODO: Add hook ability to modify these durations. + \Drupal::moduleHandler()->alter('recurring_events_durations', $durations); return $durations; } @@ -215,7 +215,7 @@ class WeeklyRecurringDateWidget extends DateRangeDefaultWidget { 'sunday' => t('Sunday'), ]; - // TODO: Add hook ability to modify these days. + \Drupal::moduleHandler()->alter('recurring_events_days', $days); return $days; }