Skip to content
Snippets Groups Projects
Commit ac15ba6c authored by Eric Bremner's avatar Eric Bremner
Browse files

ISTWCMS-5551: updating the update hook to include adding closed to comments for exception days

parent 64fd166b
No related branches found
No related tags found
2 merge requests!60ISTWCMS-6095 Update maxlength settings for title, text fields and link fields...,!33ISTWCMS-5551 update office hours
......@@ -10,10 +10,53 @@
*/
function uw_ct_service_update_9101(&$sandbox) {
// Uninstall the office hours exceptions module.
\Drupal::service('module_installer')->uninstall(['office_hours_exceptions']);
// Unset the core extension, so that we remove the warning
// about this module still being enabled.
\Drupal::configFactory()
->getEditable('core.extension')
->clear('module.office_hours_exceptions')
->save(TRUE);
// Get all the service nodes.
$services = \Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties(['type' => 'uw_ct_service']);
// Step through all service nodes and add the Closed
// to the exception days if an all day service.
foreach ($services as $service) {
// Get the hours field.
$hours = $service->field_uw_service_hours->getValue();
// If there are hours, check if we have to add closed
// to the exception days.
if ($hours) {
// Step through each of the hours and check exception
// days and see if we have to add closed.
foreach ($hours as $index => $hour) {
// If this an exception day (day > 6) and it is an
// all day service (start and end hours -1), then
// add Closed to the comments.
if (
$hour['day'] > 6 &&
$hour['starthours'] == '-1' &&
$hour['endhours'] == '-1'
) {
// Add closed to the comments.
$hours[$index]['comment'] = 'Closed';
}
}
// Set the service hours and save the node.
$service->set('field_uw_service_hours', $hours);
$service->save();
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment