From 2ce8191edbdc930b2966937a2bbf71b29a1e739f Mon Sep 17 00:00:00 2001 From: Mohamed Alsharaf Date: Wed, 12 Apr 2023 16:37:55 +1200 Subject: [PATCH] Add support for silverstripe 5 --- composer.json | 15 ++++++++------ src/Extensions/FormFieldExtension.php | 30 +++++++++++++-------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/composer.json b/composer.json index ab66a08..50dce81 100644 --- a/composer.json +++ b/composer.json @@ -22,8 +22,8 @@ } ], "require": { - "php": ">=5.6.0", - "silverstripe/framework": "^4@dev" + "php": "^8.1", + "silverstripe/framework": "^5" }, "autoload": { "psr-4": { @@ -31,14 +31,17 @@ } }, "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - }, "expose": [ "admin/client/dist", "client/dist" ] }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "config": { + "allow-plugins": { + "composer/installers": true, + "silverstripe/vendor-plugin": true + } + } } diff --git a/src/Extensions/FormFieldExtension.php b/src/Extensions/FormFieldExtension.php index d5c2d9b..b87ce1b 100644 --- a/src/Extensions/FormFieldExtension.php +++ b/src/Extensions/FormFieldExtension.php @@ -17,7 +17,6 @@ namespace SilverWare\Calendar\Extensions; -use SilverStripe\Core\Convert; use SilverStripe\Core\Extension; use SilverStripe\Forms\FormField; @@ -38,14 +37,14 @@ class FormFieldExtension extends Extension * @var array */ protected $calendarConfig = []; - + /** * If set to true, disables the calendar picker for the extended object. * * @var boolean */ protected $calendarDisabled = false; - + /** * Defines either the named calendar config value, or the calendar config array. * @@ -61,10 +60,10 @@ public function setCalendarConfig($arg1, $arg2 = null) } else { $this->calendarConfig[$arg1] = $arg2; } - + return $this; } - + /** * Answers either the named calendar config value, or the calendar config array. * @@ -77,10 +76,10 @@ public function getCalendarConfig($name = null) if (!is_null($name)) { return isset($this->calendarConfig[$name]) ? $this->calendarConfig[$name] : null; } - + return $this->calendarConfig; } - + /** * Defines the value of the calendarDisabled attribute. * @@ -91,10 +90,10 @@ public function getCalendarConfig($name = null) public function setCalendarDisabled($calendarDisabled) { $this->calendarDisabled = (boolean) $calendarDisabled; - + return $this; } - + /** * Answers the value of the calendarDisabled attribute. * @@ -104,7 +103,7 @@ public function getCalendarDisabled() { return $this->calendarDisabled; } - + /** * Event method called before the field is rendered. * @@ -118,7 +117,7 @@ public function onBeforeRender(FormField $field) $field->addExtraClass($class); } } - + /** * Updates the given array of HTML attributes from the extended object. * @@ -131,7 +130,7 @@ public function updateAttributes(&$attributes) $attributes['data-calendar-config'] = $this->owner->getCalendarConfigJSON(); $attributes['data-calendar-enabled'] = $this->owner->getCalendarEnabled(); } - + /** * Answers 'true' if the calendar is enabled for the extended object. * @@ -142,17 +141,18 @@ public function getCalendarEnabled() if ($this->owner->isReadonly() || $this->owner->isDisabled()) { return 'false'; } - + return ($this->calendarDisabled || $this->owner->config()->calendar_disabled) ? 'false' : 'true'; } - + /** * Answers a JSON-encoded string containing the config for the calendar. * * @return string + * @throws \JsonException */ public function getCalendarConfigJSON() { - return Convert::array2json($this->owner->getCalendarConfig(), JSON_FORCE_OBJECT); + return json_encode($this->owner->getCalendarConfig(), JSON_THROW_ON_ERROR | JSON_FORCE_OBJECT); } }