private function OpignoDateRangeWidget::dateformatPhpToJqueryUi in Opigno calendar 8
Same name and namespace in other branches
- 3.x src/Plugin/Field/FieldWidget/OpignoDateRangeWidget.php \Drupal\opigno_calendar\Plugin\Field\FieldWidget\OpignoDateRangeWidget::dateformatPhpToJqueryUi()
Matches each symbol of PHP date format standard with jQuery equivalent codeword
1 call to OpignoDateRangeWidget::dateformatPhpToJqueryUi()
- OpignoDateRangeWidget::formElement in src/
Plugin/ Field/ FieldWidget/ OpignoDateRangeWidget.php - Returns the form for a single field widget.
File
- src/
Plugin/ Field/ FieldWidget/ OpignoDateRangeWidget.php, line 36
Class
- OpignoDateRangeWidget
- Plugin implementation of the 'opigno_daterange' widget.
Namespace
Drupal\opigno_calendar\Plugin\Field\FieldWidgetCode
private function dateformatPhpToJqueryUi($php_format) {
$symbols_matching = [
// Day
'd' => 'dd',
'D' => 'D',
'j' => 'd',
'l' => 'DD',
'N' => '',
'S' => '',
'w' => '',
'z' => 'o',
// Week
'W' => '',
// Month
'F' => 'MM',
'm' => 'mm',
'M' => 'M',
'n' => 'm',
't' => '',
// Year
'L' => '',
'o' => '',
'Y' => 'yy',
'y' => 'y',
// Time
'a' => '',
'A' => '',
'B' => '',
'g' => '',
'G' => '',
'h' => '',
'H' => '',
'i' => '',
's' => '',
'u' => '',
];
$jqueryui_format = "";
$escaping = FALSE;
for ($i = 0; $i < strlen($php_format); $i++) {
$char = $php_format[$i];
if ($char === '\\') {
// PHP date format escaping character
$i++;
if ($escaping) {
$jqueryui_format .= $php_format[$i];
}
else {
$jqueryui_format .= '\'' . $php_format[$i];
}
$escaping = TRUE;
}
else {
if ($escaping) {
$jqueryui_format .= "'";
$escaping = FALSE;
}
if (isset($symbols_matching[$char])) {
$jqueryui_format .= $symbols_matching[$char];
}
else {
$jqueryui_format .= $char;
}
}
}
return $jqueryui_format;
}