Newer
Older
<?php
/**
* @file
* Contains recurring_events.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;

Owen Bush
committed
use Drupal\Core\Form\FormStateInterface;
use Drupal\recurring_events\Entity\EventSeries;
use Drupal\recurring_events\EventInterface;
use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\datetime\Plugin\Field\FieldType\DateTimeItemInterface;
use Drupal\Core\Entity\FieldableEntityInterface;
use Drupal\Core\Field\FieldStorageDefinitionInterface;

Owen Bush
committed
use Drupal\Core\Url;
use Drupal\Core\Link;

Owen Bush
committed
use Drupal\Core\Entity\EntityForm;
/**
* Implements hook_help().
*/
function recurring_events_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the recurring_events_views module.
$text = file_get_contents(__DIR__ . '/README.md');
if (!\Drupal::moduleHandler()->moduleExists('markdown')) {
return '<pre>' . Html::escape($text) . '</pre>';
}
else {
// Use the Markdown filter to render the README.
$filter_manager = \Drupal::service('plugin.manager.filter');
$settings = \Drupal::configFactory()->get('markdown.settings')->getRawData();
$config = ['settings' => $settings];
$filter = $filter_manager->createInstance('markdown', $config);
return $filter->process($text, 'en');
}
break;
/**
* Implements hook_entity_operation().
*/
function recurring_events_entity_operation(EntityInterface $entity) {
$operations = [];
if ($entity->getEntityTypeId() == 'eventseries' || $entity->getEntityTypeId() == 'eventinstance') {
$operations['clone'] = [
'title' => t('Clone'),
'weight' => 50,
'url' => $entity->toUrl('clone-form'),
];
}
return $operations;
}
/**
* Implements hook_theme().
*/
function recurring_events_theme() {
$theme = [];
$theme['eventinstance'] = [
'render element' => 'elements',
'template' => 'eventinstance',
];
$theme['eventseries'] = [
'render element' => 'elements',
'template' => 'eventseries',
];

Owen Bush
committed
$theme['eventseries_add_list'] = [
'variables' => ['content' => NULL],
];
82
83
84
85
86
87
88
89
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
return $theme;
}
/**
* Implements template_preprocess_entity().
*/
function template_preprocess_eventinstance(array &$variables) {
// Set the eventinstance object to be accessible in the template.
$variables['eventinstance'] = $variables['elements']['#eventinstance'];
// Set a class on the eventinstance to differentiate between viewmodes.
$variables['view_mode'] = $variables['elements']['#view_mode'];
$variables['attributes']['class'][] = 'eventinstance-' . $variables['view_mode'];
// Allow field groups to be rendered too.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}
/**
* Implements template_preprocess_entity().
*/
function template_preprocess_eventseries(array &$variables) {
// Set the eventseries object to be accessible in the template.
$variables['eventseries'] = $variables['elements']['#eventseries'];
// Set a class on the eventseries to differentiate between viewmodes.
$variables['view_mode'] = $variables['elements']['#view_mode'];
$variables['attributes']['class'][] = 'eventseries-' . $variables['view_mode'];
// Allow field groups to be rendered too.
foreach (Element::children($variables['elements']) as $key) {
$variables['content'][$key] = $variables['elements'][$key];
}
}

Owen Bush
committed

Owen Bush
committed
/**
* Prepares variables for list of available eventseries type templates.
*
* Default template: eventseries-add-list.html.twig.
*
* @param array $variables
* An associative array containing:
* - content: An array of eventseries types.
*/
function template_preprocess_eventseries_add_list(array &$variables) {
$variables['types'] = [];
if (!empty($variables['content'])) {
foreach ($variables['content'] as $type) {
$variables['types'][$type->id()] = [
'type' => $type->id(),
'add_link' => Link::fromTextAndUrl($type->label(), new Url('entity.eventseries.add_form', ['eventseries_type' => $type->id()])),
'description' => [
'#markup' => $type->getDescription(),
],
];
}
}
}

Owen Bush
committed
/**
* Implements hook_ENTITY_TYPE_presave().
*/
function recurring_events_eventseries_presave(EntityInterface $entity) {
$original = $entity->original;
$creation_service = \Drupal::service('recurring_events.event_creation_service');
$moderated = $entity->hasField('moderation_state');

Owen Bush
committed
// If the eventseries is being published, or created for the first time then
// there may be date recurrence changes that need to be converted into new
// eventinstance entities.
if ($entity->isPublished() || $entity->isNew() || !$moderated) {

Owen Bush
committed
if ($entity->isDefaultTranslation()) {
$creation_service->saveEvent($entity, $original);
}
}
}
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function recurring_events_eventseries_insert(EntityInterface $entity) {
// When we initially create the eventseries we actually create the instances
// before the eventseries gets saved for the first time, so we have no ID for
// the series at that point. Now that the eventseries is properly saved we can
// go and set the eventseries_id on the eventinstances.
$instances = $entity->event_instances->referencedEntities();
$creation_service = \Drupal::service('recurring_events.event_creation_service');

Owen Bush
committed
if (!empty($instances)) {
foreach ($instances as $instance) {
if (empty($instance->eventseries_id->target_id)) {

Owen Bush
committed
$instance->set('eventseries_id', $entity->id());
$instance->setNewRevision(FALSE);

Owen Bush
committed
$creation_service->configureDefaultInheritances($instance, $entity->id());

Owen Bush
committed
$creation_service->updateInstanceStatus($instance, $entity);
$instance->save();
}
}
}
}

Owen Bush
committed
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function recurring_events_field_inheritance_insert(EntityInterface $entity) {
if ($entity->sourceEntityType() === 'eventseries' && $entity->destinationEntityType() === 'eventinstance') {
$creation_service = \Drupal::service('recurring_events.event_creation_service');
$bundle = $entity->destinationEntityBundle();
$instances = \Drupal::entityTypeManager()->getStorage('eventinstance')->loadByProperties(['type' => $bundle]);
if (!empty($instances)) {
foreach ($instances as $instance) {
$creation_service->addNewDefaultInheritance($instance, $entity);
}
}
}
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
function recurring_events_field_inheritance_update(EntityInterface $entity) {
if ($entity->sourceEntityType() === 'eventseries' && $entity->destinationEntityType() === 'eventinstance') {
$creation_service = \Drupal::service('recurring_events.event_creation_service');
$bundle = $entity->destinationEntityBundle();
$instances = \Drupal::entityTypeManager()->getStorage('eventinstance')->loadByProperties(['type' => $bundle]);
if (!empty($instances)) {
foreach ($instances as $instance) {
$creation_service->addNewDefaultInheritance($instance, $entity);

Owen Bush
committed
}
}
}
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
function recurring_events_eventseries_update(EntityInterface $entity) {
$creation_service = \Drupal::service('recurring_events.event_creation_service');
$instances = $entity->event_instances->referencedEntities();

Owen Bush
committed
$updated_statuses = $skipped_statuses = 0;
if (!empty($instances)) {
foreach ($instances as $instance) {
$creation_service->configureDefaultInheritances($instance, $entity->id());

Owen Bush
committed
$status_updated = $creation_service->updateInstanceStatus($instance, $entity);
if ($status_updated) {
$updated_statuses++;
$instance->save();
}
else {
$skipped_statuses++;
}
}

Owen Bush
committed
\Drupal::messenger()->addMessage(t('Successfully updated @success instance statuses. Skipped @skipped instances due to status or workflow mismatch with series.', [
'@success' => $updated_statuses,
'@skipped' => $skipped_statuses,
]));
}
}

Owen Bush
committed
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function recurring_events_eventseries_type_insert(EntityInterface $entity) {
// Event series types are tied to event instance types, and optionally
// registrant types. Therefore, we need to create equivalent instance and
// registrant types every time an event series type is created.
$series_type_label = $entity->label();
$series_type_description = $entity->getDescription();
$series_type_id = $entity->id();
$instance_types = \Drupal::entityTypeManager()->getStorage('eventinstance_type')->load($series_type_id);
if (empty($instance_types)) {
$instance_type = \Drupal::entityTypeManager()->getStorage('eventinstance_type')->create([
'id' => $series_type_id,
'label' => $series_type_label,
'description' => $series_type_description,
]);
$instance_type->save();

Owen Bush
committed
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
$instance_title = \Drupal::entityTypeManager()->getStorage('field_inheritance')->create([
'id' => 'title',
'label' => 'Title',
'type' => 'inherit',
'sourceEntityType' => 'eventseries',
'sourceEntityBundle' => $series_type_id,
'sourceField' => 'title',
'destinationEntityType' => 'eventinstance',
'destinationEntityBundle' => $series_type_id,
'plugin' => 'default_inheritance',
]);
$instance_title->save();
$instance_description = \Drupal::entityTypeManager()->getStorage('field_inheritance')->create([
'id' => 'description',
'label' => 'Description',
'type' => 'append',
'sourceEntityType' => 'eventseries',
'sourceEntityBundle' => $series_type_id,
'sourceField' => 'body',
'destinationEntityType' => 'eventinstance',
'destinationEntityBundle' => $series_type_id,
'destinationField' => 'body',
'plugin' => 'default_inheritance',
]);
$instance_description->save();

Owen Bush
committed
}
// Ensure that field_inheritance is enabled for the new instance bundle.
$config = \Drupal::configFactory()->getEditable('field_inheritance.config');
$data = $config->getRawData();
$included_bundles = $data['included_bundles'];
$included_bundles = explode(',', $included_bundles);
$included_bundles[] = 'eventinstance:' . $series_type_id;
sort($included_bundles);
$data['included_bundles'] = implode(',', $included_bundles);
$config->setData($data)->save();

Owen Bush
committed
if (\Drupal::moduleHandler()->moduleExists('recurring_events_registration')) {
$registrant_types = \Drupal::entityTypeManager()->getStorage('registrant_type')->load($series_type_id);
if (empty($registrant_types)) {
$registrant_type = \Drupal::entityTypeManager()->getStorage('registrant_type')->create([
'id' => $series_type_id,
'label' => $series_type_label,
'description' => $series_type_description,
]);
$registrant_type->save();
}
}
\Drupal::cache('menu')->invalidateAll();
\Drupal::service('plugin.manager.menu.link')->rebuild();
}
/**
* Implements hook_ENTITY_TYPE_delete().
*/
function recurring_events_eventseries_type_delete(EntityInterface $entity) {
// Event series types are tied to event instance types, and optionally
// registrant types. Therefore, we need to delete equivalent instance and

Owen Bush
committed
// registrant types every time an event series type is deleted. We also must
// delete all inheritances that use these types as either the source or the
// destination.
$query = \Drupal::entityQuery('field_inheritance');
$and_destination = $query->andConditionGroup()
->condition('destinationEntityType', 'eventseries')
->condition('destinationEntityBundle', $entity->id());
$and_source = $query->andConditionGroup()
->condition('sourceEntityType', 'eventseries')
->condition('sourceEntityBundle', $entity->id());
$or = $query->orConditionGroup()
->condition($and_destination)
->condition($and_source);
$query->condition($or);
$inherited_field_ids = $query->execute();
if (!empty($inherited_field_ids)) {
$inherited_fields = \Drupal::entityTypeManager()->getStorage('field_inheritance')->loadMultiple($inherited_field_ids);
foreach ($inherited_fields as $field) {
$field->delete();
}
}

Owen Bush
committed

Owen Bush
committed
$instance_type = \Drupal::entityTypeManager()->getStorage('eventinstance_type')->load($entity->id());

Owen Bush
committed
if (!empty($instance_type)) {

Owen Bush
committed
$query = \Drupal::entityQuery('field_inheritance');
$and_destination = $query->andConditionGroup()
->condition('destinationEntityType', 'eventinstance')
->condition('destinationEntityBundle', $instance_type->id());
$and_source = $query->andConditionGroup()
->condition('sourceEntityType', 'eventinstance')
->condition('sourceEntityBundle', $instance_type->id());
$or = $query->orConditionGroup()
->condition($and_destination)
->condition($and_source);
$query->condition($or);
$inherited_field_ids = $query->execute();
if (!empty($inherited_field_ids)) {
$inherited_fields = \Drupal::entityTypeManager()->getStorage('field_inheritance')->loadMultiple($inherited_field_ids);
foreach ($inherited_fields as $field) {
$field->delete();
}
}

Owen Bush
committed
$instance_type->delete();
}
if (\Drupal::moduleHandler()->moduleExists('recurring_events_registration')) {
$registrant_type = \Drupal::entityTypeManager()->getStorage('registrant_type')->load($entity->id());

Owen Bush
committed
if (!empty($registrant_type)) {

Owen Bush
committed
$query = \Drupal::entityQuery('field_inheritance');
$and_destination = $query->andConditionGroup()
->condition('destinationEntityType', 'registrant')
->condition('destinationEntityBundle', $registrant_type->id());
$and_source = $query->andConditionGroup()
->condition('sourceEntityType', 'registrant')
->condition('sourceEntityBundle', $registrant_type->id());
$or = $query->orConditionGroup()
->condition($and_destination)
->condition($and_source);
$query->condition($or);
$inherited_field_ids = $query->execute();
if (!empty($inherited_field_ids)) {
$inherited_fields = \Drupal::entityTypeManager()->getStorage('field_inheritance')->loadMultiple($inherited_field_ids);
foreach ($inherited_fields as $field) {
$field->delete();
}
}

Owen Bush
committed
$registrant_type->delete();
}
}
}
/**
* Implements hook_entity_operation_alter().
*/
function recurring_events_entity_operation_alter(array &$operations, EntityInterface $entity) {
if ($entity->getEntityTypeId() == 'eventinstance_type') {
if (!empty($operations['delete'])) {
unset($operations['delete']);
}
}
}

Owen Bush
committed
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
437
438
439
440
441
442
443
444
445
446
447
/**
* Implements hook_form_alter().
*/
function recurring_events_form_alter(&$form, FormStateInterface $form_state, $form_id) {
$form_object = $form_state->getFormObject();
if (!empty($form_object) && $form_object instanceof EntityForm) {
$entity = $form_state->getFormObject()->getEntity();
if (!empty($entity) && $entity instanceof FieldableEntityInterface && strpos($form['#id'], 'delete') === FALSE) {
$entity_type = $entity->getEntityTypeId();
$bundle = $entity->bundle();
if ($entity_type == 'eventinstance') {
$series = $entity->getEventSeries();
$inherited_field_ids = \Drupal::entityQuery('field_inheritance')
->condition('destinationEntityType', $entity_type)
->condition('destinationEntityBundle', $bundle)
->execute();
if (!empty($inherited_field_ids)) {
$state_key = $entity->getEntityTypeId() . ':' . $entity->uuid();
$state = \Drupal::keyValue('field_inheritance');
$state_values = $state->get($state_key);
$inherited_fields = \Drupal::entityTypeManager()->getStorage('field_inheritance')->loadMultiple($inherited_field_ids);
if (!isset($state_values['enabled'])) {
$form['field_inheritance']['field_inheritance_enable']['#default_value'] = TRUE;
}
foreach ($inherited_fields as $field) {
if (!isset($state_values[$field->idWithoutTypeAndBundle()]) && !isset($state_values[$field->idWithoutTypeAndBundle()]['skip'])) {
$form['field_inheritance']['fields']['field_inheritance_' . $field->idWithoutTypeAndBundle()]['field_inheritance_field_entity_' . $field->idWithoutTypeAndBundle()]['#default_value'] = $series;
}
}
}
}
}
}
}

Owen Bush
committed
/**
* Implements hook_form_FORM_ID_alter().
*/
function recurring_events_form_content_moderation_entity_moderation_form_alter(&$form, FormStateInterface $form_state) {
$entity = $form_state->get('entity');
if ($entity instanceof EventInterface && $entity->getEntityTypeId() === 'eventseries') {

Owen Bush
committed
$original = \Drupal::entityTypeManager()->getStorage('eventseries')->load($entity->id());
$creation_service = \Drupal::service('recurring_events.event_creation_service');
if ($creation_service->checkForOriginalRecurConfigChanges($entity, $original)) {
// Show a table when viewing a revision displaying any date recurrence
// differences to alert users before they publish the revision.

Owen Bush
committed
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
$diff_array = $creation_service->buildDiffArray($original, NULL, $entity);
if (!empty($diff_array)) {
$form['diff'] = [
'#type' => 'container',
'#weight' => -99,
];
$form['diff']['diff_title'] = [
'#type' => '#markup',
'#prefix' => '<h2>',
'#markup' => t('Revision Date Changes'),
'#suffix' => '</h2>',
];
$form['diff']['diff_message'] = [
'#type' => '#markup',
'#prefix' => '<p>',
'#markup' => t('Recurrence configuration has been changed in this revision, as a result if you choose to publish this revision all instances will be removed and recreated. This action cannot be undone.'),
'#suffix' => '</p>',
];
$form['diff']['table'] = [
'#type' => 'table',
'#header' => [
t('Data'),
t('Stored'),
t('Overridden'),
],
'#rows' => $diff_array,
];
}
}
}
}
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
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
575
576
577
578
579
/**
* Implements hook_recurring_events_event_instances_pre_create_alter().
*/
function recurring_events_recurring_events_event_instances_pre_create_alter(array &$event_instances, EventSeries $event) {
$config = \Drupal::config('recurring_events.eventseries.config');
$messenger = \Drupal::messenger();
$global_exclude = $global_include = [];
$event_exclude = $event_include = [];
$exclude_config = \Drupal::entityTypeManager()->getStorage('excluded_dates')->loadMultiple();
$include_config = \Drupal::entityTypeManager()->getStorage('included_dates')->loadMultiple();
if (!empty($exclude_config)) {
foreach ($exclude_config as $date_config) {
$global_exclude[] = [
'value' => $date_config->start(),
'end_value' => $date_config->end(),
];
}
}
if (!empty($include_config)) {
foreach ($include_config as $date_config) {
$global_include[] = [
'value' => $date_config->start(),
'end_value' => $date_config->end(),
];
}
}
if ($config->get('excludes')) {
if (!empty($event->excluded_dates)) {
$event_exclude = $event->excluded_dates->getValue();
}
}
if ($config->get('includes')) {
if (!empty($event->included_dates)) {
$event_include = $event->included_dates->getValue();
}
}
$exclude = array_merge($global_exclude, $event_exclude);
$include = array_merge($global_include, $event_include);
if (!empty($exclude)) {
foreach ($event_instances as $key => $dates) {
$start = $dates['start_date']->getTimestamp();
$end = $dates['end_date']->getTimestamp();
foreach ($exclude as $date) {
$exclude_start = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $date['value'] . 'T00:00:00');
$exclude_start = $exclude_start->getTimestamp();
$excluded_end = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $date['end_value'] . 'T23:59:59');
$excluded_end = $excluded_end->getTimestamp();
if ($start >= $exclude_start && $start <= $excluded_end) {
$messenger->addMessage(t('Skipping excluded date: @start_date - @end_date', [
'@start_date' => $dates['start_date']->format($config->get('date_format')),
'@end_date' => $dates['end_date']->format($config->get('date_format')),
]));
unset($event_instances[$key]);
break;
}
if ($end >= $exclude_start && $end <= $excluded_end) {
$messenger->addMessage(t('Skipping excluded date: @start_date - @end_date', [
'@start_date' => $dates['start_date']->format($config->get('date_format')),
'@end_date' => $dates['end_date']->format($config->get('date_format')),
]));
unset($event_instances[$key]);
break;
}
}
}
}
if (!empty($include)) {
foreach ($event_instances as $key => $dates) {
$start = $dates['start_date']->getTimestamp();
$end = $dates['end_date']->getTimestamp();
for ($x = 0; $x < (count($include) - 1); $x++) {
$included_start = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $include[$x]['value'] . 'T00:00:00');
$included_start = $included_start->getTimestamp();
$included_end = DrupalDateTime::createFromFormat(DateTimeItemInterface::DATETIME_STORAGE_FORMAT, $include[$x]['end_value'] . 'T23:59:59');
$included_end = $included_end->getTimestamp();
if ($start >= $included_start && $start <= $included_end && $end >= $included_start && $end <= $included_end) {
// This event is in the inclusion range, so move on to the next one.
break;
}
if ($x == (count($include) - 1)) {
$messenger->addMessage(t('Skipping non-included date: @start_date - @end_date', [
'@start_date' => $dates['start_date']->format($config->get('date_format')),
'@end_date' => $dates['end_date']->format($config->get('date_format')),
]));
unset($event_instances[$key]);
}
}
}
}
}
/**
* Implements callback_allowed_values_function().
*/
function recurring_events_allowed_values_function(FieldStorageDefinitionInterface $definition, FieldableEntityInterface $entity = NULL) {
$values = ['custom' => t('Custom Event')];
$fields = \Drupal::service('entity_field.manager')->getBaseFieldDefinitions('eventseries');
foreach ($fields as $field) {
$field_definition = \Drupal::service('plugin.manager.field.field_type')->getDefinition($field->getType());
$class = new \ReflectionClass($field_definition['class']);
if ($class->implementsInterface('\Drupal\recurring_events\RecurringEventsFieldTypeInterface')) {
$values[$field->getName()] = $field->getLabel();
}
}
return $values;
}
/**
* Implements hook_recurring_events_recur_field_types_alter().
*/
function recurring_events_recurring_events_recur_field_types_alter(&$fields) {
// Enable/disable the recur field types based on the eventseries settings.
$config = \Drupal::config('recurring_events.eventseries.config');
$enabled_fields = explode(',', $config->get('enabled_fields'));
foreach ($fields as $field_name => $field_label) {
if (array_search($field_name, $enabled_fields) === FALSE) {
unset($fields[$field_name]);
}
}
}

Owen Bush
committed
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
/**
* Implements hook_theme_suggestions_HOOK().
*/
function recurring_events_theme_suggestions_eventseries(array $variables) {
$suggestions = [];
$entity = $variables['elements']['#eventseries'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
$suggestions[] = 'eventseries__' . $sanitized_view_mode;
$suggestions[] = 'eventseries__' . $entity->bundle();
$suggestions[] = 'eventseries__' . $entity->bundle() . '__' . $sanitized_view_mode;
$suggestions[] = 'eventseries__' . $entity->id();
$suggestions[] = 'eventseries__' . $entity->id() . '__' . $sanitized_view_mode;
return $suggestions;
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function recurring_events_theme_suggestions_eventinstance(array $variables) {
$suggestions = [];
$entity = $variables['elements']['#eventinstance'];
$sanitized_view_mode = strtr($variables['elements']['#view_mode'], '.', '_');
$suggestions[] = 'eventinstance__' . $sanitized_view_mode;
$suggestions[] = 'eventinstance__' . $entity->bundle();
$suggestions[] = 'eventinstance__' . $entity->bundle() . '__' . $sanitized_view_mode;
$suggestions[] = 'eventinstance__' . $entity->id();
$suggestions[] = 'eventinstance__' . $entity->id() . '__' . $sanitized_view_mode;
return $suggestions;