mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fix MemberDatetime helper description, and shifted them to templates (#5766)
* Fix MemberDatetime helper description, and shifted them to templates * added descriptionTemplate for setting the description * Unit test for description with templates
This commit is contained in:
parent
5ba1c477e6
commit
dfe375e87e
@ -17,6 +17,10 @@ class MemberDatetimeOptionsetField extends OptionsetField {
|
|||||||
*/
|
*/
|
||||||
private static $preview_date = '25-12-2011 17:30:00';
|
private static $preview_date = '25-12-2011 17:30:00';
|
||||||
|
|
||||||
|
private static $casting = ['Description' => 'HTMLText'];
|
||||||
|
|
||||||
|
private $descriptionTemplate = '';
|
||||||
|
|
||||||
public function Field($properties = array()) {
|
public function Field($properties = array()) {
|
||||||
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberDatetimeOptionsetField.js');
|
Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/client/dist/js/MemberDatetimeOptionsetField.js');
|
||||||
$options = array();
|
$options = array();
|
||||||
@ -90,52 +94,20 @@ class MemberDatetimeOptionsetField extends OptionsetField {
|
|||||||
return 'optionset memberdatetimeoptionset';
|
return 'optionset memberdatetimeoptionset';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @todo Put this text into a template?
|
|
||||||
*/
|
|
||||||
public function getDescription() {
|
public function getDescription() {
|
||||||
$output =
|
if ($template = $this->getDescriptionTemplate()) {
|
||||||
'<a href="#" class="toggle">'
|
return $this->renderWith($template);
|
||||||
. _t('MemberDatetimeOptionsetField.Toggle', 'Show formatting help')
|
}
|
||||||
. '</a>'
|
return parent::getDescription();
|
||||||
. '<ul class="toggle-content">'
|
|
||||||
. '<li>YYYY = ' . _t('MemberDatetimeOptionsetField.FOURDIGITYEAR', 'Four-digit year',
|
|
||||||
40, 'Help text describing what "YYYY" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>YY = ' . _t('MemberDatetimeOptionsetField.TWODIGITYEAR', 'Two-digit year',
|
|
||||||
40, 'Help text describing what "YY" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>MMMM = ' . _t('MemberDatetimeOptionsetField.FULLNAMEMONTH', 'Full name of month (e.g. June)',
|
|
||||||
40, 'Help text describing what "MMMM" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>MMM = ' . _t('MemberDatetimeOptionsetField.SHORTMONTH', 'Short name of month (e.g. Jun)',
|
|
||||||
40, 'Help text letting describing what "MMM" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>MM = ' . _t('MemberDatetimeOptionsetField.TWODIGITMONTH', 'Two-digit month (01=January, etc.)',
|
|
||||||
40, 'Help text describing what "MM" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>M = ' . _t('MemberDatetimeOptionsetField.MONTHNOLEADING', 'Month digit without leading zero',
|
|
||||||
40, 'Help text describing what "M" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>dd = ' . _t('MemberDatetimeOptionsetField.TWODIGITDAY', 'Two-digit day of month',
|
|
||||||
40, 'Help text describing what "dd" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>d = ' . _t('MemberDatetimeOptionsetField.DAYNOLEADING', 'Day of month without leading zero',
|
|
||||||
40, 'Help text describing what "d" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>hh = ' . _t('MemberDatetimeOptionsetField.TWODIGITHOUR', 'Two digits of hour (00 through 23)',
|
|
||||||
40, 'Help text describing what "hh" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>h = ' . _t('MemberDatetimeOptionsetField.HOURNOLEADING', 'Hour without leading zero',
|
|
||||||
40, 'Help text describing what "h" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>mm = ' . _t('MemberDatetimeOptionsetField.TWODIGITMINUTE',
|
|
||||||
'Two digits of minute (00 through 59)',
|
|
||||||
40, 'Help text describing what "mm" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>m = ' . _t('MemberDatetimeOptionsetField.MINUTENOLEADING', 'Minute without leading zero',
|
|
||||||
40, 'Help text describing what "m" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>ss = ' . _t('MemberDatetimeOptionsetField.TWODIGITSECOND',
|
|
||||||
'Two digits of second (00 through 59)',
|
|
||||||
40, 'Help text describing what "ss" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>s = ' . _t('MemberDatetimeOptionsetField.DIGITSDECFRACTIONSECOND',
|
|
||||||
'One or more digits representing a decimal fraction of a second',
|
|
||||||
40, 'Help text describing what "s" means in ISO date formatting') . '</li>'
|
|
||||||
. '<li>a = ' . _t('MemberDatetimeOptionsetField.AMORPM', 'AM (Ante meridiem) or PM (Post meridiem)',
|
|
||||||
40, 'Help text describing what "a" means in ISO date formatting') . '</li>'
|
|
||||||
. '</ul>';
|
|
||||||
return $output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getDescriptionTemplate() {
|
||||||
|
return $this->descriptionTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDescriptionTemplate($template) {
|
||||||
|
$this->descriptionTemplate = $template;
|
||||||
|
}
|
||||||
|
|
||||||
public function setValue($value) {
|
public function setValue($value) {
|
||||||
// Extract custom option from postback
|
// Extract custom option from postback
|
||||||
|
@ -500,13 +500,15 @@ en:
|
|||||||
DIGITSDECFRACTIONSECOND: 'One or more digits representing a decimal fraction of a second'
|
DIGITSDECFRACTIONSECOND: 'One or more digits representing a decimal fraction of a second'
|
||||||
FOURDIGITYEAR: 'Four-digit year'
|
FOURDIGITYEAR: 'Four-digit year'
|
||||||
FULLNAMEMONTH: 'Full name of month (e.g. June)'
|
FULLNAMEMONTH: 'Full name of month (e.g. June)'
|
||||||
HOURNOLEADING: 'Hour without leading zero'
|
HOURNOLEADING: 'Hour without leading zero, 12 hour format'
|
||||||
|
HOURNOLEADING24: 'Hour without leading zero, 24 hour format'
|
||||||
MINUTENOLEADING: 'Minute without leading zero'
|
MINUTENOLEADING: 'Minute without leading zero'
|
||||||
MONTHNOLEADING: 'Month digit without leading zero'
|
MONTHNOLEADING: 'Month digit without leading zero'
|
||||||
Preview: Preview
|
Preview: Preview
|
||||||
SHORTMONTH: 'Short name of month (e.g. Jun)'
|
SHORTMONTH: 'Short name of month (e.g. Jun)'
|
||||||
TWODIGITDAY: 'Two-digit day of month'
|
TWODIGITDAY: 'Two-digit day of month'
|
||||||
TWODIGITHOUR: 'Two digits of hour (00 through 23)'
|
TWODIGITHOUR: 'Two digits of hour, 12 hour format (00 through 12)'
|
||||||
|
TWODIGITHOUR24: 'Two digits of hour, 24 hour format (00 through 23)'
|
||||||
TWODIGITMINUTE: 'Two digits of minute (00 through 59)'
|
TWODIGITMINUTE: 'Two digits of minute (00 through 59)'
|
||||||
TWODIGITMONTH: 'Two-digit month (01=January, etc.)'
|
TWODIGITMONTH: 'Two-digit month (01=January, etc.)'
|
||||||
TWODIGITSECOND: 'Two digits of second (00 through 59)'
|
TWODIGITSECOND: 'Two digits of second (00 through 59)'
|
||||||
|
@ -1475,6 +1475,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
$dateFormatField->setValue($self->DateFormat);
|
$dateFormatField->setValue($self->DateFormat);
|
||||||
|
$dateFormatField->setDescriptionTemplate('MemberDatetimeOptionsetField_description_date');
|
||||||
|
|
||||||
$defaultTimeFormat = Zend_Locale_Format::getTimeFormat(new Zend_Locale($self->Locale));
|
$defaultTimeFormat = Zend_Locale_Format::getTimeFormat(new Zend_Locale($self->Locale));
|
||||||
$timeFormatMap = array(
|
$timeFormatMap = array(
|
||||||
@ -1491,6 +1492,7 @@ class Member extends DataObject implements TemplateGlobalProvider {
|
|||||||
)
|
)
|
||||||
);
|
);
|
||||||
$timeFormatField->setValue($self->TimeFormat);
|
$timeFormatField->setValue($self->TimeFormat);
|
||||||
|
$timeFormatField->setDescriptionTemplate('MemberDatetimeOptionsetField_description_time');
|
||||||
});
|
});
|
||||||
|
|
||||||
return parent::getCMSFields();
|
return parent::getCMSFields();
|
||||||
|
@ -0,0 +1,21 @@
|
|||||||
|
<a href="#" class="toggle">
|
||||||
|
<% _t('MemberDatetimeOptionsetField.Toggle', 'Show formatting help') %>
|
||||||
|
</a>
|
||||||
|
<ul class="toggle-content">
|
||||||
|
<li>YYYY = <% _t('MemberDatetimeOptionsetField.FOURDIGITYEAR', 'Four-digit year',
|
||||||
|
40, 'Help text describing what "YYYY" means in ISO date formatting') %></li>
|
||||||
|
<li>YY = <% _t('MemberDatetimeOptionsetField.TWODIGITYEAR', 'Two-digit year',
|
||||||
|
40, 'Help text describing what "YY" means in ISO date formatting') %></li>
|
||||||
|
<li>MMMM = <% _t('MemberDatetimeOptionsetField.FULLNAMEMONTH', 'Full name of month (e.g. June)',
|
||||||
|
40, 'Help text describing what "MMMM" means in ISO date formatting') %></li>
|
||||||
|
<li>MMM = <% _t('MemberDatetimeOptionsetField.SHORTMONTH', 'Short name of month (e.g. Jun)',
|
||||||
|
40, 'Help text letting describing what "MMM" means in ISO date formatting') %></li>
|
||||||
|
<li>MM = <% _t('MemberDatetimeOptionsetField.TWODIGITMONTH', 'Two-digit month (01=January, etc.)',
|
||||||
|
40, 'Help text describing what "MM" means in ISO date formatting') %></li>
|
||||||
|
<li>M = <% _t('MemberDatetimeOptionsetField.MONTHNOLEADING', 'Month digit without leading zero',
|
||||||
|
40, 'Help text describing what "M" means in ISO date formatting') %></li>
|
||||||
|
<li>dd = <% _t('MemberDatetimeOptionsetField.TWODIGITDAY', 'Two-digit day of month',
|
||||||
|
40, 'Help text describing what "dd" means in ISO date formatting') %></li>
|
||||||
|
<li>d = <% _t('MemberDatetimeOptionsetField.DAYNOLEADING', 'Day of month without leading zero',
|
||||||
|
40, 'Help text describing what "d" means in ISO date formatting') %></li>
|
||||||
|
</ul>
|
@ -0,0 +1,26 @@
|
|||||||
|
<a href="#" class="toggle">
|
||||||
|
<% _t('MemberDatetimeOptionsetField.Toggle', 'Show formatting help') %>
|
||||||
|
</a>
|
||||||
|
<ul class="toggle-content">
|
||||||
|
<li>HH = <% _t('MemberDatetimeOptionsetField.TWODIGITHOUR24', 'Two digits of hour, 24 hour format (00 through 23)',
|
||||||
|
40, 'Help text describing what "hh" means in ISO date formatting') %></li>
|
||||||
|
<li>H = <% _t('MemberDatetimeOptionsetField.HOURNOLEADING24', 'Hour without leading zero, 24 hour format',
|
||||||
|
40, 'Help text describing what "h" means in ISO date formatting') %></li>
|
||||||
|
<li>hh = <% _t('MemberDatetimeOptionsetField.TWODIGITHOUR', 'Two digits of hour, 12 hour format (00 through 12)',
|
||||||
|
40, 'Help text describing what "hh" means in ISO date formatting') %></li>
|
||||||
|
<li>h = <% _t('MemberDatetimeOptionsetField.HOURNOLEADING', 'Hour without leading zero, 12 hour format',
|
||||||
|
40, 'Help text describing what "h" means in ISO date formatting') %></li>
|
||||||
|
<li>mm = <% _t('MemberDatetimeOptionsetField.TWODIGITMINUTE',
|
||||||
|
'Two digits of minute (00 through 59)',
|
||||||
|
40, 'Help text describing what "mm" means in ISO date formatting') %></li>
|
||||||
|
<li>m = <% _t('MemberDatetimeOptionsetField.MINUTENOLEADING', 'Minute without leading zero',
|
||||||
|
40, 'Help text describing what "m" means in ISO date formatting') %></li>
|
||||||
|
<li>ss = <% _t('MemberDatetimeOptionsetField.TWODIGITSECOND',
|
||||||
|
'Two digits of second (00 through 59)',
|
||||||
|
40, 'Help text describing what "ss" means in ISO date formatting') %></li>
|
||||||
|
<li>s = <% _t('MemberDatetimeOptionsetField.DIGITSDECFRACTIONSECOND',
|
||||||
|
'One or more digits representing a decimal fraction of a second',
|
||||||
|
40, 'Help text describing what "s" means in ISO date formatting') %></li>
|
||||||
|
<li>a = <% _t('MemberDatetimeOptionsetField.AMORPM', 'AM (Ante meridiem) or PM (Post meridiem)',
|
||||||
|
40, 'Help text describing what "a" means in ISO date formatting') %></li>
|
||||||
|
</ul>
|
@ -102,6 +102,19 @@ class MemberDatetimeOptionsetFieldTest extends SapphireTest {
|
|||||||
$this->assertFalse($field->validate($validator));
|
$this->assertFalse($field->validate($validator));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDescriptionTemplate() {
|
||||||
|
$field = new MemberDatetimeOptionsetField('DateFormat', 'DateFormat');
|
||||||
|
|
||||||
|
$this->assertEmpty($field->getDescription());
|
||||||
|
|
||||||
|
$field->setDescription('Test description');
|
||||||
|
$this->assertEquals('Test description', $field->getDescription());
|
||||||
|
|
||||||
|
$field->setDescriptionTemplate('MemberDatetimeOptionsetField_description_time');
|
||||||
|
$this->assertNotEmpty($field->getDescription());
|
||||||
|
$this->assertNotEquals('Test description', $field->getDescription());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
class MemberDatetimeOptionsetFieldTest_Controller extends Controller {
|
class MemberDatetimeOptionsetFieldTest_Controller extends Controller {
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user