Using fullcalandar with JSON Access
- Dominant language
- PHP
- Stars
- 8
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
I was trying to use FullCalendar with this extension. I quickly discovered that fullcalendar was expecting only one level, while JSON Access outputs 2 (one for the content type and one for the content.). Also, the nodes were named wrong. I added a bit to extension.php and jsonaccess.bolt.yml to make it work but I am sure there's a more elegant solution. Any thoughts would be appreciated.
The following will allow you to remap the fields output in JSON and flatten the array.
### Added to response() in extension.php:
```
$path = '/event/'; //slug to content type
if (!empty($this->config['arraydimension']) && ($this->config['arraydimension']['depth'] == 'single')) {
// if arraydimension is in config and set to single
$array = call_user_func_array('array_merge', $array); // remove parent array for FULLCALENDAR
}
if (!empty($this->config['remap']) && is_array($this->config['remap'])) {
// if remap exists in config and it's an array
foreach ($this->config['remap'] as $old => $new) {
// iterate over each remap pair
foreach($array as &$val){
$val[$new] = $val[$old]; // set new key's value to old key's value
unset($val[$old]); // remove the old key
if ($new == 'url') {
// if key is named url
$val[url]=( stripslashes($path) . $val[url]);
// remove any escaping from this url - re-escaped later for JSON
}
}
}
}
```
### Added in jsonaccess.bolt.yml:
# _remap remaps key names in JSON ( 'old': 'new' )_
remap:
'artist': 'title'
'slug': 'url'
'datestart': 'start'
'dateend': 'end'
'caleventcolor': 'color'
'caltxtcolor': 'textColor'
'caldescription': 'description'
# _arraydimension removes "contenttype" from JSON. Default is multi._
arraydimension:
depth: single
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.