mirror of
https://github.com/silverstripe/silverstripe-cms
synced 2024-10-22 08:05:56 +02:00
API CHANGE Replaced CMSMain->LangSelector() with CMSMain->LangForm() to provide more accessible backend and properly wrap existing <select> tag in a form
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@92728 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
2796a37a02
commit
01d06dd47e
@ -1353,22 +1353,50 @@ JS;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all languages with languages already used appearing first.
|
||||
* Called by the SSViewer when rendering the template.
|
||||
*/
|
||||
function LangSelector() {
|
||||
$member = Member::currentUser();
|
||||
$dropdown = new LanguageDropdownField(
|
||||
'LangSelector',
|
||||
'Language',
|
||||
array(),
|
||||
'SiteTree',
|
||||
'Locale-English',
|
||||
singleton('SiteTree')
|
||||
* Returns a form with all languages with languages already used appearing first.
|
||||
*
|
||||
* @return Form
|
||||
*/
|
||||
function LangForm() {
|
||||
$member = Member::currentUser(); //check to see if the current user can switch langs or not
|
||||
if(Permission::checkMember($member, 'VIEW_LANGS')) {
|
||||
$field = new LanguageDropdownField(
|
||||
'Locale',
|
||||
// TODO i18n
|
||||
'Language',
|
||||
array(),
|
||||
'SiteTree',
|
||||
'Locale-English',
|
||||
singleton('SiteTree')
|
||||
);
|
||||
$field->setValue(Translatable::get_current_locale());
|
||||
} else {
|
||||
// user doesn't have permission to switch langs
|
||||
// so just show a string displaying current language
|
||||
$field = new LiteralField(
|
||||
'Locale',
|
||||
i18n::get_locale_name( Translatable::get_current_locale())
|
||||
);
|
||||
}
|
||||
|
||||
$form = new Form(
|
||||
$this,
|
||||
'LangForm',
|
||||
new FieldSet(
|
||||
$field
|
||||
),
|
||||
new FieldSet(
|
||||
new FormAction('selectlang', _t('CMSMain_left.ss.GO','Go'))
|
||||
)
|
||||
);
|
||||
$dropdown->setValue(Translatable::get_current_locale());
|
||||
return $dropdown;
|
||||
}
|
||||
$form->unsetValidator();
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
function selectlang($data, $form) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are more than one languages in our site tree.
|
||||
|
@ -290,9 +290,6 @@ class LeftAndMain extends Controller {
|
||||
'cms/javascript/CMSMain_left.js',
|
||||
'cms/javascript/CMSMain_right.js',
|
||||
'cms/javascript/SideTabs.js',
|
||||
'cms/javascript/SideReports.js',
|
||||
'cms/javascript/LangSelector.js',
|
||||
'cms/javascript/TranslationTab.js',
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -490,3 +490,10 @@ form#SideReportForm label.left {
|
||||
border-top: 1px solid #CCCCCC;
|
||||
padding: 3px 0 3px 7px;
|
||||
}
|
||||
#LangSelector_holder .Actions {
|
||||
display: none;
|
||||
}
|
||||
#LangSelector_holder label.left {
|
||||
margin-left: 0;
|
||||
width: auto;
|
||||
}
|
@ -4,7 +4,7 @@
|
||||
* @class Dropdown with languages above CMS tree, causing a redirect upon translation
|
||||
* @name ss.CMSMain.LangSelector
|
||||
*/
|
||||
$('.CMSMain #LangSelector').concrete('ss', function($){
|
||||
$('.CMSMain #Form_LangForm').concrete('ss', function($){
|
||||
return/** @lends ss.CMSMain.LangSelector */{
|
||||
onmatch: function() {
|
||||
var self = this;
|
||||
@ -16,7 +16,7 @@
|
||||
});
|
||||
|
||||
// whenever a new value is selected, reload the whole CMS in the new locale
|
||||
this.bind('change', function(e) {
|
||||
this.find(':input[name=Locale]').bind('change', function(e) {
|
||||
document.location = 'admin/?locale=' + $(e.target).val();
|
||||
return false;
|
||||
});
|
||||
|
@ -42,6 +42,6 @@
|
||||
|
||||
<% if IsTranslatableEnabled %>
|
||||
<div id="LangSelector_holder">
|
||||
Language: $LangSelector
|
||||
$LangForm
|
||||
</div>
|
||||
<% end_if %>
|
Loading…
Reference in New Issue
Block a user