Skip to content

Commit

Permalink
Add support for silverstripe 5
Browse files Browse the repository at this point in the history
  • Loading branch information
satrun77 committed Apr 12, 2023
1 parent 71060ec commit 2ce8191
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
15 changes: 9 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,26 @@
}
],
"require": {
"php": ">=5.6.0",
"silverstripe/framework": "^4@dev"
"php": "^8.1",
"silverstripe/framework": "^5"
},
"autoload": {
"psr-4": {
"SilverWare\\Calendar\\": "src/"
}
},
"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
}
}
}
30 changes: 15 additions & 15 deletions src/Extensions/FormFieldExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

namespace SilverWare\Calendar\Extensions;

use SilverStripe\Core\Convert;
use SilverStripe\Core\Extension;
use SilverStripe\Forms\FormField;

Expand All @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -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.
*
Expand All @@ -104,7 +103,7 @@ public function getCalendarDisabled()
{
return $this->calendarDisabled;
}

/**
* Event method called before the field is rendered.
*
Expand All @@ -118,7 +117,7 @@ public function onBeforeRender(FormField $field)
$field->addExtraClass($class);
}
}

/**
* Updates the given array of HTML attributes from the extended object.
*
Expand All @@ -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.
*
Expand All @@ -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);
}
}

0 comments on commit 2ce8191

Please sign in to comment.