Skip to content

Commit

Permalink
MDL-46714 Calendar: Properly order Date & Time fields in RTL mode
Browse files Browse the repository at this point in the history
  • Loading branch information
nadavkav authored and Frederic Massart committed Dec 12, 2016
1 parent 5ef81f2 commit bb13339
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 4 additions & 0 deletions lib/form/dateselector.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ function _createElements() {
$this->_elements = array();

$dateformat = $calendartype->get_date_order($this->_options['startyear'], $this->_options['stopyear']);
// Reverse date element (Day, Month, Year), in RTL mode.
if (right_to_left()) {
$dateformat = array_reverse($dateformat);
}
foreach ($dateformat as $key => $value) {
// E_STRICT creating elements without forms is nasty because it internally uses $this
$this->_elements[] = $this->createFormElement('select', $key, get_string($key, 'form'), $value, $this->getAttributes(), true);
Expand Down
19 changes: 13 additions & 6 deletions lib/form/datetimeselector.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,23 @@ function _createElements() {

$this->_elements = array();
$dateformat = $calendartype->get_date_order($this->_options['startyear'], $this->_options['stopyear']);
if (right_to_left()) { // Display time to the right of date, in RTL mode.
$this->_elements[] = $this->createFormElement('select', 'minute', get_string('minute', 'form'),
$minutes, $this->getAttributes(), true);
$this->_elements[] = $this->createFormElement('select', 'hour', get_string('hour', 'form'),
$hours, $this->getAttributes(), true);
// Reverse date element (Should be: Day, Month, Year), in RTL mode.
$dateformat = array_reverse($dateformat);
}
foreach ($dateformat as $key => $date) {
// E_STRICT creating elements without forms is nasty because it internally uses $this
$this->_elements[] = $this->createFormElement('select', $key, get_string($key, 'form'), $date, $this->getAttributes(), true);
}
if (right_to_left()) { // Switch order of elements for Right-to-Left
$this->_elements[] = $this->createFormElement('select', 'minute', get_string('minute', 'form'), $minutes, $this->getAttributes(), true);
$this->_elements[] = $this->createFormElement('select', 'hour', get_string('hour', 'form'), $hours, $this->getAttributes(), true);
} else {
$this->_elements[] = $this->createFormElement('select', 'hour', get_string('hour', 'form'), $hours, $this->getAttributes(), true);
$this->_elements[] = $this->createFormElement('select', 'minute', get_string('minute', 'form'), $minutes, $this->getAttributes(), true);
if (!right_to_left()) { // Display time to the left of date, in LTR mode.
$this->_elements[] = $this->createFormElement('select', 'hour', get_string('hour', 'form'), $hours,
$this->getAttributes(), true);
$this->_elements[] = $this->createFormElement('select', 'minute', get_string('minute', 'form'), $minutes,
$this->getAttributes(), true);
}
// The YUI2 calendar only supports the gregorian calendar type so only display the calendar image if this is being used.
if ($calendartype->get_name() === 'gregorian') {
Expand Down

0 comments on commit bb13339

Please sign in to comment.