diff --git a/CHANGELOG.md b/CHANGELOG.md index ec17bc3..5904d4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Solspace Calendar Changelog +## 2.0.22 - 2019-07-31 +### Fixed +- Fixed a bug where newly created events were not respecting the default site status setting in each calendar. +- Fixed a bug where events that were disabled couldn't be deleted from inside the edit event page. + ## 2.0.21 - 2019-07-26 ### Changed - Updated `carbon` dependency to `^1.22.1|^2.19` for better compatibility with other plugins, and to reduce the chances of seeing deprecation notice. diff --git a/composer.json b/composer.json index c7548c9..d6f3551 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "solspace/craft3-calendar", "description": "The most powerful event management plugin for Craft.", - "version": "2.0.21", + "version": "2.0.22", "type": "craft-plugin", "authors": [ { diff --git a/src/Controllers/EventsController.php b/src/Controllers/EventsController.php index 1cdb628..06bd50b 100644 --- a/src/Controllers/EventsController.php +++ b/src/Controllers/EventsController.php @@ -268,7 +268,9 @@ public function actionSaveEvent() $this->handleRepeatRules($event, $values); - $event->enabledForSite = (bool) \Craft::$app->request->post('enabledForSite', $event->enabledForSite); + $enabledForSite = (bool) \Craft::$app->request->post('enabledForSite', $event->enabledForSite); + + $event->enabledForSite = $enabledForSite ? '1' : '0'; $event->title = \Craft::$app->request->post('title', $event->title); $event->slug = \Craft::$app->request->post('slug', $event->slug); $event->setFieldValuesFromRequest('fields'); diff --git a/src/Elements/Event.php b/src/Elements/Event.php index 12d3c5f..7e2165a 100644 --- a/src/Elements/Event.php +++ b/src/Elements/Event.php @@ -213,6 +213,11 @@ public static function create(int $siteId = null, int $calendarId = null): Event if ($siteId) { $element->siteId = $siteId; + + $siteSettings = $element->getCalendar()->getSiteSettingsForSite($siteId); + if ($siteSettings) { + $element->enabledForSite = $siteSettings->enabledByDefault; + } } return $element; @@ -384,7 +389,10 @@ public function getSupportedSites(): array $supportedSites = []; foreach ($siteSettings as $site) { - $supportedSites[] = $site->siteId; + $supportedSites[] = [ + 'siteId' => $site->siteId, + 'enabledByDefault' => $site->enabledByDefault, + ]; } return $supportedSites; diff --git a/src/Services/EventsService.php b/src/Services/EventsService.php index 329492d..068ebc0 100644 --- a/src/Services/EventsService.php +++ b/src/Services/EventsService.php @@ -246,7 +246,7 @@ public function saveEvent(Event $event, bool $validateContent = true, bool $bypa */ public function deleteEventById(int $eventId): bool { - $event = $this->getEventById($eventId); + $event = $this->getEventById($eventId, null, true); if (!$event) { return false; diff --git a/src/templates/events/_edit.html b/src/templates/events/_edit.html index cd1a0ee..7c3b6a9 100644 --- a/src/templates/events/_edit.html +++ b/src/templates/events/_edit.html @@ -254,7 +254,7 @@ label: "Enabled for site"|t('app'), id: 'enabledForSite', name: 'enabledForSite', - on: event.enabledForSite, + on: event.siteId in enabledSiteIds, }) }} {% endif %}