diff --git a/config/schema/recurring_events.schema.yml b/config/schema/recurring_events.schema.yml new file mode 100644 index 0000000000000000000000000000000000000000..998d10e8a81ed9c3a78ef0df473c4deb18a4a5f9 --- /dev/null +++ b/config/schema/recurring_events.schema.yml @@ -0,0 +1,16 @@ +recurring_events.config + type: config_object + label: 'Recurring Events' + mapping: + interval: + type: integer + label: 'The interval between times when creating events' + min_time: + type: string + label: 'The earliest an event can start' + max_time: + type: string + label: 'The latest an event can start' + time_format: + type: string + label: 'The formatting of times when creating events' \ No newline at end of file diff --git a/src/Plugin/Field/FieldType/MonthlyRecurringDate.php b/src/Plugin/Field/FieldType/MonthlyRecurringDate.php index a5935393dc4f59aca115681b6d71e571ce06bc53..459335467432c1b04be3057ecd9e47cb2d7b3b90 100644 --- a/src/Plugin/Field/FieldType/MonthlyRecurringDate.php +++ b/src/Plugin/Field/FieldType/MonthlyRecurringDate.php @@ -26,7 +26,6 @@ class MonthlyRecurringDate extends WeeklyRecurringDate { $schema['columns']['type'] = [ 'type' => 'varchar', - 'not null' => TRUE, 'length' => 20, ]; diff --git a/src/Plugin/Field/FieldType/WeeklyRecurringDate.php b/src/Plugin/Field/FieldType/WeeklyRecurringDate.php index 119b7ad93e0250c71ee8914def73dee6a52f4767..02d4ec3fc0342ed97a93c756e3dd8ac9303ec6d1 100644 --- a/src/Plugin/Field/FieldType/WeeklyRecurringDate.php +++ b/src/Plugin/Field/FieldType/WeeklyRecurringDate.php @@ -27,19 +27,16 @@ class WeeklyRecurringDate extends DateRangeItem { $schema['columns']['time'] = [ 'type' => 'varchar', - 'not null' => TRUE, 'length' => 20, ]; $schema['columns']['duration'] = [ 'type' => 'int', - 'not null' => TRUE, 'unsigned' => TRUE, ]; $schema['columns']['days'] = [ 'type' => 'varchar', - 'not null' => TRUE, 'length' => 255, ]; diff --git a/src/Plugin/Field/FieldWidget/MonthlyRecurringDateWidget.php b/src/Plugin/Field/FieldWidget/MonthlyRecurringDateWidget.php index 6a8d33727597fec9c37bd077a829daa11b13ed7c..5c71f46bb4d447e289006e9d2ebea33099663613 100644 --- a/src/Plugin/Field/FieldWidget/MonthlyRecurringDateWidget.php +++ b/src/Plugin/Field/FieldWidget/MonthlyRecurringDateWidget.php @@ -93,6 +93,25 @@ class MonthlyRecurringDateWidget extends WeeklyRecurringDateWidget { return $element; } + /** + * {@inheritdoc} + */ + public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { + $values = parent::massageFormValues($values, $form, $form_state); + + foreach ($values as &$item) { + + $item['day_occurrence'] = array_filter($item['day_occurrence']); + if (!empty($item['day_occurrence'])) { + $item['day_occurrence'] = implode(',', $item['day_occurrence']); + } + else { + $item['day_occurrence'] = ''; + } + } + return $values; + } + /** * Return day of month options for events. * diff --git a/src/Plugin/Field/FieldWidget/WeeklyRecurringDateWidget.php b/src/Plugin/Field/FieldWidget/WeeklyRecurringDateWidget.php index dc1ed4eea37e6c2b6d046ec7eddcbfb48c07928f..1d15457b93290cb24b146eafac4445f0b7ba9097 100644 --- a/src/Plugin/Field/FieldWidget/WeeklyRecurringDateWidget.php +++ b/src/Plugin/Field/FieldWidget/WeeklyRecurringDateWidget.php @@ -76,6 +76,31 @@ class WeeklyRecurringDateWidget extends DateRangeDefaultWidget { return $element; } + /** + * {@inheritdoc} + */ + public function massageFormValues(array $values, array $form, FormStateInterface $form_state) { + $values = parent::massageFormValues($values, $form, $form_state); + + foreach ($values as &$item) { + if (empty($item['value'])) { + $item['value'] = ''; + } + if (empty($item['end_value'])) { + $item['end_value'] = ''; + } + + $item['days'] = array_filter($item['days']); + if (!empty($item['days'])) { + $item['days'] = implode(',', $item['days']); + } + else { + $item['days'] = ''; + } + } + return $values; + } + /** * Generate times based on specific intervals and min/max times. * @@ -91,7 +116,7 @@ class WeeklyRecurringDateWidget extends DateRangeDefaultWidget { $interval = $config->get('interval') * 60; $min_time = $config->get('min_time'); $max_time = $config->get('max_time'); - $format = $config->get('format'); */ + $format = $config->get('time_format'); */ // Take interval in minutes, and multiply it by 60 to convert to seconds. $interval = 15 * 60;