Newer
Older
<?php
/**
* @file
* Installation and update functionality for the recurring_events module.
*/

Owen Bush
committed
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Config\FileStorage;

Andy Fowlston
committed
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\views\Views;
/**
* Set up the config to allow field inheritance for event instances.
*/
function recurring_events_install() {
// Enable the eventinstance bundles to allow inheritance.
$config = \Drupal::configFactory()->getEditable('field_inheritance.config');
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('eventseries');
$data = $config->getRawData();
$included_entities = $data['included_entities'];
$included_entities = explode(',', $included_entities);
$included_entities[] = 'eventinstance';
sort($included_entities);
$data['included_entities'] = implode(',', $included_entities);
$included_bundles = $data['included_bundles'];
$included_bundles = explode(',', $included_bundles);
foreach ($bundles as $bundle_key => $bundle) {
$included_bundles[] = 'eventinstance:' . $bundle_key;
}
sort($included_bundles);
$data['included_bundles'] = implode(',', $included_bundles);
$config->setData($data)->save();
}
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/**
* Install the excluded and included date fields.
*/
function recurring_events_update_8001() {
/*
* @see https://www.drupal.org/node/3068262
*/
$excluded_dates = BaseFieldDefinition::create('daterange')
->setLabel(new TranslatableMarkup('Excluded Dates'))
->setDescription('Dates on which to not create any eventinstances.')
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', FALSE)
->setRevisionable(TRUE)
->setTranslatable(FALSE)
->setCardinality(-1)
->setRequired(FALSE)
->setSetting('datetime_type', 'date')
->setDisplayOptions('form', [
'type' => 'daterange_default',
'weight' => 6,
'settings' => [
'format_type' => 'html_date',
'datetime_type' => 'date',
],
]);
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('excluded_dates', 'eventseries', 'eventseries', $excluded_dates);
$included_dates = BaseFieldDefinition::create('daterange')
->setLabel(new TranslatableMarkup('Included Dates'))
->setDescription('Only create eventinstances if they occur on these dates.')
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', FALSE)
->setRevisionable(TRUE)
->setTranslatable(FALSE)
->setCardinality(-1)
->setRequired(FALSE)
->setSetting('datetime_type', 'date')
->setDisplayOptions('form', [
'type' => 'daterange_default',
'weight' => 6,
'settings' => [
'format_type' => 'html_date',
'datetime_type' => 'date',
],
]);
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('included_dates', 'eventseries', 'eventseries', $included_dates);
}
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/**
* Update existing series to use the new recur type values.
*/
function recurring_events_update_8002(&$sandbox) {
// This is a multipass update.
// Grab all the weekly or monthly eventseries.
if (empty($sandbox['events'])) {
$event_series = \Drupal::database()->query('
SELECT
eventseries_field_data.id
FROM
eventseries_field_data
WHERE
recur_type = \'weekly\'
OR recur_type = \'monthly\''
)->fetchCol(0);
$sandbox['events'] = $event_series;
$sandbox['max'] = count($event_series);
$sandbox['limit'] = 20;
$sandbox['progress'] = 0;
}
if (count($sandbox['events']) > 0) {
// Loop through chunks of 20 events at a time.
$events = array_splice($sandbox['events'], 0, $sandbox['limit'], []);
if (!empty($events)) {
foreach ($events as $event_id) {
// Fully load this event so we can update and save it.
$event = \Drupal::entityTypeManager()->getStorage('eventseries')->load($event_id);
if (!empty($event)) {
// If the event was weekly it needs to be weekly_recurring_date.
if ($event->getRecurType() == 'weekly') {
$event->recur_type = 'weekly_recurring_date';
$event->save();
}
// If the event was monthly it needs to be monthly_recurring_date.
elseif ($event->getRecurType() == 'monthly') {
$event->recur_type = 'monthly_recurring_date';
$event->save();
}
}
$sandbox['progress']++;
}
echo 'Updated: ' . count($events) . ' eventseries. Total: ' . $sandbox['progress'] . ' of ' . $sandbox['max'] . "\r\n";
$sandbox['#finished'] = ($sandbox['progress'] / $sandbox['max']);
}
}
else {
$sandbox['#finished'] = 1;
}
}
/**
* Configure the event series to have the new recur types and settings config.
*/
function recurring_events_update_8003() {
// Add the consecutive recurring date type.
$consecutive_recurring_date = BaseFieldDefinition::create('consecutive_recurring_date')
->setLabel(t('Consecutive Event'))
->setDescription('The consecutive recurring date configuration.')
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRevisionable(TRUE)
->setTranslatable(FALSE)
->setCardinality(1)
->setRequired(FALSE)
->setDisplayOptions('form', [
'type' => 'consecutive_recurring_date',
'weight' => 1,
]);
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('consecutive_recurring_date', 'eventseries', 'eventseries', $consecutive_recurring_date);
// Add the daily recurring date type.
$daily_recurring_date = BaseFieldDefinition::create('daily_recurring_date')
->setLabel(t('Daily Event'))
->setDescription('The daily recurring date configuration.')
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRevisionable(TRUE)
->setTranslatable(FALSE)
->setCardinality(1)
->setRequired(FALSE)
->setDisplayOptions('form', [
'type' => 'daily_recurring_date',
'weight' => 2,
]);
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('daily_recurring_date', 'eventseries', 'eventseries', $daily_recurring_date);
// Enable all the recur types.
$config = \Drupal::configFactory()->getEditable('recurring_events.eventseries.config');
$config->set('enabled_fields', 'consecutive_recurring_date,daily_recurring_date,weekly_recurring_date,monthly_recurring_date,custom');
$config->save(TRUE);
}
/**
* Install new threshold warning config.
*/
function recurring_events_update_8004() {
$config = \Drupal::configFactory()->getEditable('recurring_events.eventseries.config');
$config->set('threshold_warning', 1);
$config->set('threshold_count', 200);
$config->set('threshold_message', 'Saving this series will create up to @total event instances. This could result in memory exhaustion or site instability.');
$config->set('threshold_prevent_save', 0);
$config->save(TRUE);
}

Owen Bush
committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
/**
* Install the new config entities for event series and instance bundles.
*/
function recurring_events_update_8005() {
/*
* @see https://www.drupal.org/node/3069090
*/
\Drupal::entityDefinitionUpdateManager()->installEntityType(new ConfigEntityType([
'id' => 'eventseries_type',
'label' => new TranslatableMarkup('Event series type'),
'handlers' => [
'view_builder' => 'Drupal\Core\Entity\EntityViewBuilder',
'list_builder' => 'Drupal\recurring_events\EventSeriesTypeListBuilder',
'form' => [
'add' => 'Drupal\recurring_events\Form\EventSeriesTypeForm',
'edit' => 'Drupal\recurring_events\Form\EventSeriesTypeForm',
'delete' => 'Drupal\recurring_events\Form\EventSeriesTypeDeleteForm',
],
'route_provider' => [
'html' => 'Drupal\recurring_events\EventSeriesTypeHtmlRouteProvider',
],
],
'config_prefix' => 'eventseries_type',
'bundle_of' => 'eventseries',
'admin_permission' => 'administer eventseries entity',
'entity_keys' => [
'id' => 'id',
'label' => 'label',
'uuid' => 'uuid',
],
'links' => [
'canonical' => '/admin/structure/events/series/types/eventseries_type/{eventseries_type}',
'add-form' => '/admin/structure/events/series/types/eventseries_type/add',
'edit-form' => '/admin/structure/events/series/types/eventseries_type/{eventseries_type}/edit',
'delete-form' => '/admin/structure/events/series/types/eventseries_type/{eventseries_type}/delete',
'collection' => '/admin/structure/events/series/types/eventseries_type',
],
'config_export' => [
'label',
'id',
'description',
],
]));
\Drupal::entityDefinitionUpdateManager()->installEntityType(new ConfigEntityType([
'id' => 'eventinstance_type',
'label' => new TranslatableMarkup('Event instance type'),
'handlers' => [
'view_builder' => 'Drupal\Core\Entity\EntityViewBuilder',
'list_builder' => 'Drupal\recurring_events\EventSeriesTypeListBuilder',
'form' => [
'add' => 'Drupal\recurring_events\Form\EventSeriesTypeForm',
'edit' => 'Drupal\recurring_events\Form\EventSeriesTypeForm',
'delete' => 'Drupal\recurring_events\Form\EventSeriesTypeDeleteForm',
],
'route_provider' => [
'html' => 'Drupal\recurring_events\EventSeriesTypeHtmlRouteProvider',
],
],
'config_prefix' => 'eventinstance_type',
'bundle_of' => 'eventinstance',
'admin_permission' => 'administer eventinstance entity',
'entity_keys' => [
'id' => 'id',
'label' => 'label',
'uuid' => 'uuid',
],
'links' => [
'canonical' => '/admin/structure/events/instance/types/eventinstance_type/{eventinstance_type}',
'add-form' => '/admin/structure/events/instance/types/eventinstance_type/add',
'edit-form' => '/admin/structure/events/instance/types/eventinstance_type/{eventinstance_type}/edit',
'delete-form' => '/admin/structure/events/instance/types/eventinstance_type/{eventinstance_type}/delete',
'collection' => '/admin/structure/events/instance/types/eventinstance_type',
],
'config_export' => [
'label',
'id',
'description',
],
]));
}
/**
* Install the new type base fields for series and instances.

Owen Bush
committed
*/
function recurring_events_update_8006() {
$series_type = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Type'))
->setDescription(t('The eventseries type.'))
->setSetting('target_type', 'eventseries_type')
->setReadOnly(TRUE);
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('type', 'eventseries', 'eventseries', $series_type);
$instance_type = BaseFieldDefinition::create('entity_reference')
->setLabel(t('Type'))
->setDescription(t('The eventinstance type.'))
->setSetting('target_type', 'eventinstance_type')
->setReadOnly(TRUE);
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('type', 'eventinstance', 'eventinstance', $instance_type);
}

Owen Bush
committed
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
/**
* Transition existing field inheritance entities over to new module.
*/
function recurring_events_update_8007() {
\Drupal::service('module_installer')->install(['field_inheritance']);
$database = \Drupal::database();
$inherited_fields = $database->select('config', 'c')
->fields('c', ['name'])
->condition('name', 'recurring_events.field_inheritance.%', 'LIKE')
->execute()
->fetchCol();
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('eventseries');
if (!empty($inherited_fields)) {
foreach ($inherited_fields as $inherited_field) {
$field = \Drupal::configFactory()->getEditable($inherited_field);
foreach ($bundles as $bundle_key => $bundle) {
$data = $field->getRawData();
$id_parts = [
'eventinstance',
$bundle_key,
$data['id'],
];
$name = 'field_inheritance.field_inheritance.' . implode('_', $id_parts);
$data['id'] = implode('_', $id_parts);
$data['sourceEntityType'] = 'eventseries';
$data['sourceEntityBundle'] = $bundle_key;
$data['destinationEntityType'] = 'eventinstance';
$data['destinationEntityBundle'] = $bundle_key;
$data['plugin'] = 'default_inheritance';
if (!empty($data['entityField'])) {
$data['destinationField'] = $data['entityField'];
unset($data['entityField']);
}
$field->setName($name)->setData($data)->save();
}
}
$database->delete('config')
->condition('name', 'recurring_events.field_inheritance.%', 'LIKE')
->execute();
}
drupal_flush_all_caches();
}
/**
* Enable the eventinstance bundles to allow inheritance.
*/
function recurring_events_update_8008() {
// Enable the eventinstance bundles to allow inheritance.
$config = \Drupal::configFactory()->getEditable('field_inheritance.config');
$bundles = \Drupal::service('entity_type.bundle.info')->getBundleInfo('eventseries');
$data = $config->getRawData();
$included_entities = $data['included_entities'];
$included_entities = explode(',', $included_entities);
$included_entities[] = 'eventinstance';
sort($included_entities);
$data['included_entities'] = implode(',', $included_entities);
$included_bundles = $data['included_bundles'];
$included_bundles = explode(',', $included_bundles);
foreach ($bundles as $bundle_key => $bundle) {
$included_bundles[] = 'eventinstance:' . $bundle_key;
}
sort($included_bundles);
$data['included_bundles'] = implode(',', $included_bundles);
$config->setData($data)->save();
drupal_flush_all_caches();
}
/**
* Update all existing event instances.
*/
function recurring_events_update_8009(&$sandbox) {
// This is a multipass update.
if (empty($sandbox['events'])) {
$events = \Drupal::entityQuery('eventinstance')->accessCheck(FALSE)->execute();

Owen Bush
committed
$sandbox['events'] = $events;
$sandbox['max'] = count($events);
$sandbox['limit'] = 50;
$sandbox['progress'] = 0;
}
if (count($sandbox['events']) > 0) {
// Loop through chunks of 20 events at a time.
$events = array_splice($sandbox['events'], 0, $sandbox['limit'], []);
if (!empty($events)) {
$loaded_events = \Drupal::entityTypeManager()->getStorage('eventinstance')->loadMultiple($events);
$state = \Drupal::keyValue('field_inheritance');
foreach ($loaded_events as $event) {
$entity_type = $event->getEntityTypeId();
$bundle = $event->bundle();
$state_key = $event->getEntityTypeId() . ':' . $event->uuid();
$state_values = $state->get($state_key);
$inherited_field_ids = \Drupal::entityQuery('field_inheritance')
->condition('sourceEntityType', 'eventseries')
->condition('destinationEntityType', $entity_type)
->condition('destinationEntityBundle', $bundle)
->accessCheck(FALSE)

Owen Bush
committed
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
->execute();
if (!empty($inherited_field_ids)) {
$inherited_fields = \Drupal::entityTypeManager()->getStorage('field_inheritance')->loadMultiple($inherited_field_ids);
$state_values = [
'enabled' => TRUE,
];
if (!empty($inherited_fields)) {
foreach ($inherited_fields as $inherited_field) {
$name = $inherited_field->idWithoutTypeAndBundle();
$state_values[$name] = [
'entity' => $event->getEventSeries()->id(),
];
}
}
}
$state->set($state_key, $state_values);
$sandbox['progress']++;
}
echo 'Updated: ' . count($events) . ' event instances. Total: ' . $sandbox['progress'] . ' of ' . $sandbox['max'] . "\r\n";
$sandbox['#finished'] = ($sandbox['progress'] / $sandbox['max']);
}
}
else {
$sandbox['#finished'] = 1;
drupal_flush_all_caches();
}
}
/**
* Import new default config added for views submodule support.
*/
function recurring_events_update_8010() {
$configs = [
'core.entity_view_display.eventinstance.default.list',
'core.entity_view_mode.eventinstance.list',
'core.entity_view_display.eventseries.default.list',
'core.entity_view_mode.eventseries.list',
];
foreach ($configs as $config) {
$path_resolver = \Drupal::service('extension.path.resolver');
$path = $path_resolver->getPath('module', 'recurring_events') . '/config/install';
$source = new FileStorage($path);
/** @var \Drupal\Core\Config\StorageInterface $active_storage */
$active_storage = \Drupal::service('config.storage');
$active_storage->write($config, $source->read($config));
}
}

Owen Bush
committed
/**
* Add end time option, rather than just duration, to creating event series.
*/
function recurring_events_update_8011() {
$fields_to_create = [
'daily_recurring_date' => [
'label' => t('Daily Event'),
'description' => 'The daily recurring date configuration.',
'weight' => 4,
],
'weekly_recurring_date' => [
'label' => t('Weekly Event'),
'description' => 'The weekly recurring date configuration.',
'weight' => 5,
],
'monthly_recurring_date' => [
'label' => t('Monthly Event'),
'description' => 'The monthly recurring date configuration.',
'weight' => 6,
],
];

Jay Beaton
committed
$updates = [
'tables' => [
'eventseries_field_data',
'eventseries_field_revision',

Jay Beaton
committed
'fields' => [
'daily_recurring_date__value',
'daily_recurring_date__end_value',
'weekly_recurring_date__value',
'weekly_recurring_date__end_value',
'monthly_recurring_date__value',
'monthly_recurring_date__end_value',
],
];

Owen Bush
committed
$entity_type_manager = \Drupal::entityTypeManager();
$storage = $entity_type_manager->getStorage('eventseries');
$bundle_definition = $entity_type_manager->getDefinition('eventseries');
$id_key = $bundle_definition->getKey('id');
$revision_key = $bundle_definition->getKey('revision');
$table_name = $storage->getDataTable() ?: $storage->getBaseTable();
$revision_table_name = $storage->getRevisionDataTable() ?: $storage->getRevisionTable();
$database = \Drupal::database();
$definition_manager = \Drupal::entityDefinitionUpdateManager();

Jay Beaton
committed
foreach ($updates['tables'] as $table) {
foreach ($updates['fields'] as $field) {
$database->update($table)
->fields([$field => ''])
->isNull($field)
->execute();
}
}

Owen Bush
committed
$basefield_definitions = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('eventseries');
foreach ($fields_to_create as $machine_name => $config) {
$field_fields = [];
$schema = $basefield_definitions[$machine_name]->getSchema();
foreach ($schema['columns'] as $column_name => $column_config) {
if (!in_array($column_name, ['end_time', 'duration_or_end_time'])) {
$field_fields[] = $machine_name . '__' . $column_name;
}
}
$database_values = $database->select($table_name)
->fields($table_name, array_merge([$id_key, $revision_key], $field_fields))
->execute()
->fetchAll();
foreach ($database_values as &$value) {
$duration_field = $machine_name . '__duration';
if (property_exists($value, $duration_field)) {
if (empty($value->{$duration_field})) {
$value->{$duration_field} = 0;
}
}
}

Owen Bush
committed
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
// Remove the existing daily/monthly/weekly recurring date field.
$field_storage_definition = $definition_manager->getFieldStorageDefinition($machine_name, 'eventseries');
$definition_manager->uninstallFieldStorageDefinition($field_storage_definition);
// Create a new instance of the field.
$storage_definition = BaseFieldDefinition::create($machine_name)
->setName($machine_name)
->setLabel($config['label'])
->setDescription($config['label'])
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRevisionable(TRUE)
->setTranslatable(FALSE)
->setCardinality(1)
->setRequired(FALSE)
->setDisplayOptions('form', [
'type' => $machine_name,
'weight' => $config['weight'],
]);
\Drupal::entityDefinitionUpdateManager()
->installFieldStorageDefinition($machine_name, 'eventseries', 'eventseries', $storage_definition);
// Restore previously stored values.
if (!empty($database_values)) {
foreach ($database_values as $value) {
$values_to_restore = [
$id_key => $value->{$id_key},
$revision_key => $value->{$revision_key},
];
foreach ($field_fields as $field) {
$values_to_restore[$field] = $value->{$field};

Owen Bush
committed
}
$values_to_restore[$machine_name . '__end_time'] = NULL;
$values_to_restore[$machine_name . '__duration_or_end_time'] = 'duration';
$database->update($table_name)
->fields($values_to_restore)
->condition($id_key, $value->{$id_key})
->execute();
$database->update($revision_table_name)
->fields($values_to_restore)
->condition($id_key, $value->{$id_key})
->condition($revision_key, $value->{$revision_key})
->execute();
}
}
}
}

Owen Bush
committed
/**
* Remove the event_instance entity reference field, now use computed field.
*/
function recurring_events_update_8012() {
$definition_manager = \Drupal::entityDefinitionUpdateManager();
$field_storage_definition = $definition_manager->getFieldStorageDefinition('event_instances', 'eventseries');
$definition_manager->uninstallFieldStorageDefinition($field_storage_definition);
}
/**
* Update any views that use old event instance relationship.
*/
function recurring_events_update_8013() {
$config_factory = \Drupal::configFactory();
if (!$views = Views::getAllViews()) {
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
return [];
}
$messages = [];
foreach ($views as $view_id => $view) {
$config = $config_factory->getEditable('views.view.' . $view_id);
if (!$displays = $config->get('display')) {
continue;
}
$changed = FALSE;
foreach ($displays as $display_id => $display) {
if (empty($display['display_options']['relationships'])) {
continue;
}
foreach ($display['display_options']['relationships'] as $id => $relationship) {
$table = $relationship['table'] ?? NULL;
if ($table != 'eventseries__event_instances') {
continue;
}
$relationship['table'] = 'eventseries_field_data';
if ($relationship['admin_label'] == 'Event Instance entity') {
// Change label if it wasn't customized.
$relationship['admin_label'] = 'Event Series Instances';
}
unset($relationship['entity_field']);
$displays[$display_id]['display_options']['relationships'][$id] = $relationship;
$changed = TRUE;
}
}
if ($changed) {
$config->set('display', $displays);
$config->save(TRUE);
$messages[] = t('Updated view @id.', ['@id' => $view_id]);
}
}
if (!empty($messages)) {
return implode("</br> \n", $messages);
}
return t('No Recurring events views to update.');
}
/**
* Set the default event instance plugin creator.
*/
function recurring_events_update_8014() {
$config = \Drupal::configFactory()->getEditable('recurring_events.eventseries.config');
$config->set('creator_plugin', 'recurring_events_eventinstance_recreator');
$config->save(TRUE);
}

Dan Lobelle
committed
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
/**
* Configure the event series to have the new yearly recur type.
*/
function recurring_events_update_8015() {
$yearly_recurring_date = BaseFieldDefinition::create('yearly_recurring_date')
->setLabel(t('Yearly Event'))
->setDescription('The yearly recurring date configuration.')
->setDisplayConfigurable('form', TRUE)
->setDisplayConfigurable('view', TRUE)
->setRevisionable(TRUE)
->setTranslatable(FALSE)
->setCardinality(1)
->setRequired(FALSE)
->setDisplayOptions('form', [
'type' => 'yearly_recurring_date',
'weight' => 7,
]);
\Drupal::entityDefinitionUpdateManager()->installFieldStorageDefinition('yearly_recurring_date', 'eventseries', 'eventseries', $yearly_recurring_date);
// Enable all the recur types.
$config = \Drupal::configFactory()->getEditable('recurring_events.eventseries.config');
$config->set('enabled_fields', 'consecutive_recurring_date,daily_recurring_date,weekly_recurring_date,monthly_recurring_date,yearly_recurring_date,custom');
$config->save(TRUE);
}
/**
* Set the default event instance plugin creator.
*/
function recurring_events_update_91001() {
recurring_events_update_8014();
}

Andy Fowlston
committed
/**
* Fix entity field mismatches with various fields.
*/
function recurring_events_update_91002() {
$entity_definition_update_manager = \Drupal::entityDefinitionUpdateManager();
foreach (['eventseries', 'eventinstance'] as $entity_type) {
$field_definitions = \Drupal::service('entity_field.manager')
->getFieldDefinitions($entity_type, $entity_type);
if (!empty($field_definitions['uid']) && $field_definitions['uid'] instanceof FieldStorageDefinitionInterface) {
$entity_definition_update_manager
->installFieldStorageDefinition(
'uid',
$entity_type,
'recurring_events',
$field_definitions['uid']
);
}
}
foreach ([
'daily_recurring_date',
'weekly_recurring_date',

Andy Fowlston
committed
] as $field_name) {
$field_definitions = \Drupal::service('entity_field.manager')
->getFieldDefinitions('eventseries', 'eventseries');
if (!empty($field_definitions[$field_name]) && $field_definitions[$field_name] instanceof FieldStorageDefinitionInterface) {
$entity_definition_update_manager
->installFieldStorageDefinition(
$field_name,
'eventseries',
'recurring_events',
$field_definitions[$field_name]
);
}
}
}