Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Substitute Zend_Locale / Zend_Date with php-intl #6607

Merged
merged 5 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
10 changes: 8 additions & 2 deletions _config/i18n.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
Name: basei18n
Before: '/i18n'
---
SilverStripe\i18n\i18n:
SilverStripe\i18n\Data\Sources:
module_priority:
- admin
- framework
- sapphire
---
Name: defaulti18n
---
SilverStripe\i18n\i18n:
SilverStripe\i18n\Data\Sources:
module_priority:
- other_modules
---
Expand Down Expand Up @@ -58,3 +58,9 @@ SilverStripe\Core\Injector\Injector:
properties:
Reader: %$SilverStripe\i18n\Messages\Reader
Writer: %$SilverStripe\i18n\Messages\Writer
---
Name: i18ndata
---
SilverStripe\Core\Injector\Injector:
SilverStripe\i18n\Data\Locales:
class: SilverStripe\i18n\Data\Intl\IntlLocales
631 changes: 315 additions & 316 deletions admin/client/dist/js/bundle.js

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion admin/client/dist/styles/bundle.css
Original file line number Diff line number Diff line change
Expand Up @@ -8859,11 +8859,16 @@ fieldset{
height:18px;
}

.field input.day,.field input.month,.field input.year{
.field input.day,.field input.month{
width:56px;
display:inline;
}

.field input.year{
width:72px;
display:inline;
}

.field input.time{
width:88px;
}
Expand Down
61 changes: 34 additions & 27 deletions admin/client/src/legacy/DateField.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,43 @@ import $ from 'jQuery';
require('../../../thirdparty/jquery-ui/jquery-ui.js');

$.fn.extend({
ssDatepicker: function(opts) {
return $(this).each(function() {
// disabled, readonly or already applied
if($(this).prop('disabled') || $(this).prop('readonly') || $(this).data('datepicker')) return;

$(this).siblings("button").addClass("ui-icon ui-icon-calendar");

var holder = $(this).closest('.field.date'),
config = $.extend(opts || {}, $(this).data(), $(this).data('jqueryuiconfig'), {});
if(!config.showcalendar) return;
ssDatepicker: function(opts) {
return $(this).each(function() {

if(config.locale && $.datepicker.regional[config.locale]) {
config = $.extend(config, $.datepicker.regional[config.locale], {});
}

if(config.min) config.minDate = $.datepicker.parseDate('yy-mm-dd', config.min);
if(config.max) config.maxDate = $.datepicker.parseDate('yy-mm-dd', config.max);

// Initialize and open a datepicker
// live() doesn't have "onmatch", and jQuery.entwine is a bit too heavyweight for this, so we need to do this onclick.
config.dateFormat = config.jquerydateformat;
$(this).datepicker(config);
});
}
// disabled, readonly or already applied
if ($(this).prop('disabled') || $(this).prop('readonly') || $(this).hasClass('hasDatepicker')) {
return;
}

$(this).siblings("button").addClass("ui-icon ui-icon-calendar");

let config = $.extend(
{},
opts || {},
$(this).data(),
$(this).data('jqueryuiconfig')
);
if(!config.showcalendar) {
return;
}

if(config.locale && $.datepicker.regional[config.locale]) {
// Note: custom config overrides regional settings
config = $.extend({}, $.datepicker.regional[config.locale], config);
}

// Initialize and open a datepicker
// live() doesn't have "onmatch", and jQuery.entwine is a bit too heavyweight
// for this, so we need to do this onclick.
$(this).datepicker(config);
});
}
});

$(document).on("click", ".field.date input.text,input.text.date", function() {
$(this).ssDatepicker();
$(this).ssDatepicker();

if($(this).data('datepicker')) {
$(this).datepicker('show');
}
if($(this).data('datepicker')) {
$(this).datepicker('show');
}
});
6 changes: 5 additions & 1 deletion admin/client/src/styles/legacy/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,14 @@ form.small .field, .field.small {
}

/* Date Fields */
input.month, input.day, input.year {
input.month, input.day {
width: ($grid-x * 7);
display: inline;
}
input.year {
width: ($grid-x * 9);
display: inline;
}

input.time {
width: ($grid-x * 11); // smaller time field, since input is restricted
Expand Down
3 changes: 2 additions & 1 deletion admin/code/CMSMenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Core\Convert;
use SilverStripe\Core\Manifest\ClassLoader;
use SilverStripe\Core\Object;
use SilverStripe\Control\Controller;
use SilverStripe\i18n\i18n;
Expand Down Expand Up @@ -427,7 +428,7 @@ public function provideI18nEntities()
$entities = array();
foreach ($cmsClasses as $cmsClass) {
$defaultTitle = LeftAndMain::menu_title($cmsClass, false);
$ownerModule = i18n::get_owner_module($cmsClass);
$ownerModule = ClassLoader::instance()->getManifest()->getOwnerModule($cmsClass);
$entities["{$cmsClass}.MENUTITLE"] = [
'default' => $defaultTitle,
'module' => $ownerModule
Expand Down
3 changes: 2 additions & 1 deletion admin/code/LeftAndMain.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use SilverStripe\Dev\Deprecation;
use SilverStripe\Forms\Form;
use SilverStripe\Forms\HiddenField;
use SilverStripe\Forms\HTMLEditor\TinyMCEConfig;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\FormAction;
use SilverStripe\Forms\FieldList;
Expand Down Expand Up @@ -576,7 +577,7 @@ protected function init()
// Set default values in the config if missing. These things can't be defined in the config
// file because insufficient information exists when that is being processed
$htmlEditorConfig = HTMLEditorConfig::get_active();
$htmlEditorConfig->setOption('language', i18n::get_tinymce_lang());
$htmlEditorConfig->setOption('language', TinyMCEConfig::get_tinymce_lang());

Requirements::customScript("
window.ss = window.ss || {};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$DateField.SmallFieldHolder
$TimeField.SmallFieldHolder
<% if $HasTimezone %>
<% if $TimeZone %>
$TimezoneField.Field
<% end_if %>
7 changes: 1 addition & 6 deletions docs/en/02_Developer_Guides/03_Forms/01_Validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,7 @@ Each individual [api:FormField] instance is responsible for validating the submi

Subclasses of `FormField` can define their own version of `validate` to provide custom validation rules such as the
above example with the `Email` validation. The `validate` method on `FormField` takes a single argument of the current
`Validator` instance.

<div class="notice" markdown="1">
The data value of the `FormField` submitted is not passed into validate. It is stored in the `value` property through
the `setValue` method.
</div>
`Validator` instance.

```php
public function validate($validator)
Expand Down
50 changes: 21 additions & 29 deletions docs/en/02_Developer_Guides/03_Forms/Field_types/02_DateField.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ summary: How to format and use the DateField class.

# DateField

This `FormField` subclass lets you display an editable date, either in a single text input field, or in three separate
fields for day, month and year. It also provides a calendar date picker.
This `FormField` subclass lets you display an editable date, in a single text input field.
It also provides a calendar date picker.

The following example will add a simple DateField to your Page, allowing you to enter a date manually.

Expand Down Expand Up @@ -33,14 +33,14 @@ The following example will add a simple DateField to your Page, allowing you to

## Custom Date Format

A custom date format for a [api:DateField] can be provided through `setConfig`.
A custom date format for a [api:DateField] can be provided through `setDateFormat`.

:::php
// will display a date in the following format: 31-06-2012
DateField::create('MyDate')->setConfig('dateformat', 'dd-MM-yyyy');
DateField::create('MyDate')->setDateFormat('dd-MM-yyyy');

<div class="info" markdown="1">
The formats are based on [Zend_Date constants](http://framework.zend.com/manual/1.12/en/zend.date.constants.html).
The formats are based on [CLDR format](http://userguide.icu-project.org/formatparse/datetime).
</div>


Expand All @@ -51,19 +51,16 @@ strtotime()).

:::php
DateField::create('MyDate')
->setConfig('min', '-7 days')
->setConfig('max', '2012-12-31')
->setMinDate('-7 days')
->setMaxDate'2012-12-31')

## Separate Day / Month / Year Fields

The following setting will display your DateField as three input fields for day, month and year separately. HTML5
placeholders 'day', 'month' and 'year' are enabled by default.
To display separate input fields for day, month and year separately you can use the `SeparatedDateField` subclass`.
HTML5 placeholders 'day', 'month' and 'year' are enabled by default.

:::php
DateField::create('MyDate')
->setConfig('dmyfields', true)
->setConfig('dmyseparator', '/') // set the separator
->setConfig('dmyplaceholders', 'true'); // enable HTML 5 Placeholders
SeparatedDateField::create('MyDate');

<div class="alert" markdown="1">
Any custom date format settings will be ignored.
Expand All @@ -75,10 +72,13 @@ The following setting will add a Calendar to a single DateField, using the jQuer

:::php
DateField::create('MyDate')
->setConfig('showcalendar', true);
->setShowCalendar(true);

The jQuery date picker will support most custom locale formats (if left as default).
If setting an explicit date format via setDateFormat() then the below table of supported
characters should be used.

The jQuery DatePicker doesn't support every constant available for `Zend_Date`. If you choose to use the calendar, the
following constants should at least be safe:
It is recommended to use numeric format, as `MMM` or `MMMM` month names may not always pass validation.

Constant | xxxxx
-------- | -----
Expand All @@ -94,15 +94,6 @@ y | year (4 digits)
yy | year (2 digits)
yyyy | year (4 digits)

Unfortunately the day- and monthname values in Zend Date do not always match those in the existing jQuery UI locale
files, so constants like `EEE` or `MMM`, for day and month names could break validation. To fix this we had to slightly
alter the jQuery locale files, situated in */framework/thirdparty/jquery-ui/datepicker/i18n/*, to match Zend_Date.

<div class="info">
At this moment not all locale files may be present. If a locale file is missing, the DatePicker calendar will fallback
to 'yyyy-MM-dd' whenever day - and/or monthnames are used. After saving, the correct format will be displayed.
</div>

## Formatting Hints

It's often not immediate apparent which format a field accepts, and showing the technical format (e.g. `HH:mm:ss`) is
Expand All @@ -113,13 +104,14 @@ field description as an example.
$dateField = DateField::create('MyDate');

// Show long format as text below the field
$dateField->setDescription(sprintf(
_t('FormField.Example', 'e.g. %s', 'Example format'),
Convert::raw2xml(Zend_Date::now()->toString($dateField->getConfig('dateformat')))
$dateField->setDescription(_t(
'FormField.Example',
'e.g. {format}',
[ 'format' => $dateField->getDateFormat() ]
));

// Alternatively, set short format as a placeholder in the field
$dateField->setAttribute('placeholder', $dateField->getConfig('dateformat'));
$dateField->setAttribute('placeholder', $dateField->getDateFormat());

<div class="notice" markdown="1">
Fields scaffolded through [api:DataObject::scaffoldCMSFields()] automatically have a description attached to them.
Expand Down
Loading