1
0
mirror of https://github.com/flextype/flextype.git synced 2025-08-24 13:52:56 +02:00

feat(admin-plugin): add new option date_display_format #186

This commit is contained in:
Awilum
2019-09-11 12:09:55 +03:00
parent debd9e0360
commit 64f173161f
3 changed files with 56 additions and 1 deletions

View File

@@ -91,6 +91,8 @@ class SettingsController extends Controller
'plugins/admin/views/templates/system/settings/index.html',
[
'timezones' => Date::timezones(),
'date_formats' => $this->dateFormats(),
'date_display_format' => $this->displayDateFormats(),
'cache_driver' => $cache_driver,
'locales' => $locales,
'entries' => $entries,
@@ -149,4 +151,44 @@ class SettingsController extends Controller
return $response->withRedirect($this->router->pathFor('admin.settings.index'));
}
/**
* Return date formats allowed
*
* @return array
*/
public function dateFormats()
{
$now = new \DateTime();
$date_formats = [
'd-m-Y H:i' => $now->format('d-m-Y H:i'),
'Y-m-d H:i' => $now->format('Y-m-d H:i'),
'm/d/Y h:i a' => $now->format('m/d/Y h:i a'),
'H:i d-m-Y' => $now->format('H:i d-m-Y'),
'h:i a m/d/Y' => $now->format('h:i a m/d/Y'),
];
return $date_formats;
}
/**
* Return display date formats allowed
*
* @return array
*/
public function displayDateFormats() : array
{
$now = new \DateTime();
$date_formats = [
'F jS \\a\\t g:ia' => $now->format('F jS \\a\\t g:ia'),
'l jS \\of F g:i A' => $now->format('l jS \\of F g:i A'),
'D, d M Y G:i:s' => $now->format('m/d/Y h:i a'),
'd-m-y G:i' => $now->format('d-m-y G:i'),
'jS M Y' => $now->format('jS M Y'),
];
return $date_formats;
}
}

View File

@@ -101,6 +101,7 @@ admin_cache_lifetime: "Cache lifetime"
admin_cache_prefix: "Cache prefix"
admin_charset: "Charset"
admin_date_format: "Date format"
admin_date_display_format: "Display date format"
admin_errors_display: "Display errors"
admin_locale: "Locale"
admin_entry_main: "Main entry"

View File

@@ -83,7 +83,19 @@
</div>
<div class="form-group">
<label for="date_format">{{ tr('admin_date_format') }}</label>
<input type="text" id="systemSettingsSystemDateFormat" name="date_format" value="{{ registry.settings.date_format }}" class="form-control" required="required">
<select id="dateFormat" name="date_format" class="form-control">
{% for key, value in date_formats %}
<option value="{{ key }}" {% if key == registry.settings.date_format %}selected{% endif %}>{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="date_display_format">{{ tr('admin_date_display_format') }}</label>
<select id="dateDisplayFormat" name="date_display_format" class="form-control">
{% for key, value in date_display_format %}
<option value="{{ key }}" {% if key == registry.settings.date_display_format %}selected{% endif %}>{{ value }}</option>
{% endfor %}
</select>
</div>
<div class="form-group">
<label for="locale">{{ tr('admin_locale') }}</label>