mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Allowing FormHelper::month() to use a $monthNames array as values.
This commit is contained in:
parent
988ab2d29f
commit
034b5c435c
2 changed files with 39 additions and 3 deletions
|
@ -653,7 +653,7 @@ class FormHelper extends AppHelper {
|
|||
$this->_inputDefaults,
|
||||
$options
|
||||
);
|
||||
|
||||
|
||||
$modelKey = $this->model();
|
||||
$fieldKey = $this->field();
|
||||
if (!isset($this->fieldset[$modelKey])) {
|
||||
|
@ -1422,7 +1422,8 @@ class FormHelper extends AppHelper {
|
|||
*
|
||||
* Attributes:
|
||||
*
|
||||
* - `monthNames` is set and false 2 digit numbers will be used instead of text.
|
||||
* - `monthNames` - If false, 2 digit numbers will be used instead of text.
|
||||
* If a array, the given array will be used.
|
||||
* - `empty` - If true, the empty select option is shown. If a string,
|
||||
* that string is displayed as the empty element.
|
||||
*
|
||||
|
@ -1916,7 +1917,7 @@ class FormHelper extends AppHelper {
|
|||
}
|
||||
break;
|
||||
case 'month':
|
||||
if ($options['monthNames']) {
|
||||
if ($options['monthNames'] === true) {
|
||||
$data['01'] = __('January', true);
|
||||
$data['02'] = __('February', true);
|
||||
$data['03'] = __('March', true);
|
||||
|
@ -1929,6 +1930,8 @@ class FormHelper extends AppHelper {
|
|||
$data['10'] = __('October', true);
|
||||
$data['11'] = __('November', true);
|
||||
$data['12'] = __('December', true);
|
||||
} else if (is_array($options['monthNames'])) {
|
||||
$data = $options['monthNames'];
|
||||
} else {
|
||||
for ($m = 1; $m <= 12; $m++) {
|
||||
$data[sprintf("%02s", $m)] = strftime("%m", mktime(1, 1, 1, $m, 1, 1999));
|
||||
|
|
|
@ -4023,6 +4023,39 @@ class FormHelperTest extends CakeTestCase {
|
|||
'*/select',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$result = $this->Form->month('Model.field', null, array('monthNames' => false));
|
||||
$expected = array(
|
||||
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
||||
array('option' => array('value' => '')),
|
||||
'/option',
|
||||
array('option' => array('value' => '01')),
|
||||
'01',
|
||||
'/option',
|
||||
array('option' => array('value' => '02')),
|
||||
'02',
|
||||
'/option',
|
||||
'*/select',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
|
||||
$monthNames = array(
|
||||
'01' => 'Jan', '02' => 'Feb', '03' => 'Mar', '04' => 'Apr', '05' => 'May', '06' => 'Jun',
|
||||
'07' => 'Jul', '08' => 'Aug', '09' => 'Sep', '10' => 'Oct', '11' => 'Nov', '12' => 'Dec');
|
||||
$result = $this->Form->month('Model.field', null, array('monthNames' => $monthNames));
|
||||
$expected = array(
|
||||
array('select' => array('name' => 'data[Model][field][month]', 'id' => 'ModelFieldMonth')),
|
||||
array('option' => array('value' => '')),
|
||||
'/option',
|
||||
array('option' => array('value' => '01')),
|
||||
'Jan',
|
||||
'/option',
|
||||
array('option' => array('value' => '02')),
|
||||
'Feb',
|
||||
'/option',
|
||||
'*/select',
|
||||
);
|
||||
$this->assertTags($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue