public function FullCalendar::preView in FullCalendar 8.5
Same name and namespace in other branches
- 8 src/Plugin/fullcalendar/type/FullCalendar.php \Drupal\fullcalendar\Plugin\fullcalendar\type\FullCalendar::preView()
- 8.2 src/Plugin/fullcalendar/type/FullCalendar.php \Drupal\fullcalendar\Plugin\fullcalendar\type\FullCalendar::preView()
- 8.3 src/Plugin/fullcalendar/type/FullCalendar.php \Drupal\fullcalendar\Plugin\fullcalendar\type\FullCalendar::preView()
- 8.4 src/Plugin/fullcalendar/type/FullCalendar.php \Drupal\fullcalendar\Plugin\fullcalendar\type\FullCalendar::preView()
Overrides FullcalendarBase::preView
File
- src/
Plugin/ fullcalendar/ type/ FullCalendar.php, line 977
Class
- FullCalendar
- Plugin annotation @FullcalendarOption( id = "fullcalendar", module = "fullcalendar", js = TRUE, weight = "-20" )
Namespace
Drupal\fullcalendar\Plugin\fullcalendar\typeCode
public function preView(&$settings) {
$options = [];
// Get enabled plugins.
if ($plugins = $this
->getEnabledFullcalendarPlugins($settings)) {
$options['plugins'] = $plugins;
}
// Get updated settings.
$settings = $this
->filterSettings($settings);
$defaultKeys = $this
->getCalendarProperties();
// buttonIcons - true, false or object.
if (isset($settings['buttonIcons'])) {
$_type = in_array($settings['buttonIcons'], [
'true',
'false',
]) ? 'scalar' : 'object';
$defaultKeys[$_type][] = 'buttonIcons';
unset($_type);
}
// Prepare FC view-specific options.
$views = [];
foreach ([
'views_year',
'views_month',
'views_week',
'views_day',
] as $_views) {
if (!empty($settings[$_views])) {
foreach ($settings[$_views] as $key => $value) {
list($_view, $_option) = explode('_', $key);
$array = $this
->convertKeyValuePairsToArray($value);
if ($_option === 'buttonText') {
$views[$_view][$array['key']] = $array['value'];
}
else {
$views[$_view][$_option][$array['key']] = $array['value'];
}
}
}
unset($settings[$_views]);
}
if ($views) {
$options['views'] = $views;
}
// Prepare other FC options.
$settings = $this
->flattenMultidimensionalArray($settings);
$keys = array_keys($settings);
foreach ($defaultKeys as $type => $properties) {
foreach ($properties as $property) {
if (in_array($property, $keys)) {
switch ($type) {
case 'scalar':
switch ($settings[$property]) {
case 'true':
$value = TRUE;
break;
case 'false':
$value = FALSE;
break;
default:
$value = $settings[$property];
break;
}
$options[$property] = $value;
unset($value);
break;
case 'array':
$items = explode(',', $settings[$property]);
$options[$property] = array_map('trim', $items);
break;
case 'object':
$string = $this
->fixCommaSeparatedValues($settings[$property]);
$values = explode(',', $string);
foreach ($values as $value) {
$value = str_replace('_COMMA_', ',', $value);
$array = $this
->convertKeyValuePairsToArray($value);
$options[$property][$array['key']] = $array['value'];
}
break;
}
}
unset($settings[$property]);
}
}
$settings['options'] = $options;
}