Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for silverstripe 5 #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}