function social_event_node_update in Open Social 10.1.x
Same name and namespace in other branches
- 8.9 modules/social_features/social_event/social_event.module \social_event_node_update()
- 10.3.x modules/social_features/social_event/social_event.module \social_event_node_update()
- 10.0.x modules/social_features/social_event/social_event.module \social_event_node_update()
- 10.2.x modules/social_features/social_event/social_event.module \social_event_node_update()
Implements hook_ENTITY_TYPE_update().
Delete the event enrollments request if type is changed to directly.
File
- modules/
social_features/ social_event/ social_event.module, line 909 - The Social event module.
Code
function social_event_node_update(EntityInterface $entity) {
if ($entity instanceof NodeInterface && $entity
->getType() === 'event') {
$enroll_state_original = $entity->original
->get('field_enroll_method')
->getString();
$enroll_new_state = $entity
->get('field_enroll_method')
->getString();
// If the request to enroll was turned off then delete the request.
if ((int) $enroll_state_original === EventEnrollmentInterface::ENROLL_METHOD_REQUEST && (int) $enroll_new_state !== EventEnrollmentInterface::ENROLL_METHOD_REQUEST) {
/** @var \Drupal\social_event\EventEnrollmentStatusHelper $enrollments */
$enrollments = \Drupal::service('social_event.status_helper');
/** @var \Drupal\social_event\Entity\EventEnrollment $enrollment */
foreach ($enrollments
->getAllEventEnrollments($entity
->id(), TRUE) as $enrollment) {
// Check if the field is not empty before getting the value,
// Since (int) will otherwise return 0 and give false positives.
if (!$enrollment
->get('field_request_or_invite_status')
->isEmpty() && (int) $enrollment
->get('field_request_or_invite_status')
->getString() === EventEnrollmentInterface::REQUEST_PENDING) {
$enrollment
->delete();
}
}
}
}
}