Open sanderha opened 8 years ago
We haven't used this part of the catalog manager for almost 2 years - is there a fix that you can think of for it?
Not at the moment, but if I find a fix i'll let you know
Update
I got the language switch to work! The solution is weird though, and maybe you can help me figure out why it works.
I had copied LangForm()
from TranslatableCatalogExtension
directly onto my ModelAdmin class. Additionally I had to add LangForm to $allowed_actions
on my ModelAdmin. The dropdown now works!
However I can not remove the TranslatableCatalogExtension
from my ModelAdmin, because then the dropdown wont show up. Therefore I decided just to directly overwrite the ImportForm()
method on the ModelAdmin itself:
function ImportForm(){
return $this->LangForm();
}
And then removing the TranslatableCatalogExtension
as it is no longer needed.
Also it is weird that the language switching works, but it still says ?Locale=en_US in the URL.
Update 2 So I wanted the language dropdown to work just like the standart one does, on the SiteTree. I found out it doesnt because a CSS class is missing ('CMSMain') for the JavaScript to work. I did a little "hack" to add the class in the backend.. Not very clean, but makes it all work as the user is used to.
On my ModelAdmin:
public function BaseCSSClasses() {
// add CMSMain class because otherwise the JavaScript for the language select dropdown wont work
return $this->CSSClasses('Controller') . ' CMSMain';
}
@Sanderha can you confirm the work from @Tom-Alexander fixes this issue? If it does, I will tag a new release from master.
@stevie-mayhew It seems to work nicely. Would be better to change a few lines so that in the ModelAdmin_Tools.ss template we put the $LanguageSelectorForm in a div with the class "CMSMain". `
` And also set the name of the language form to "LangForm" instead of language, like so:
public function getLanguageSelectorForm()
{
$fields = FieldList::create($this->getLanguageField());
return Form::create(
$this->owner,
'LangForm',
$fields,
FieldList::create(FormAction::create(
'language',
'Go'
))
);
}
These changes make sure that the JavaScript form the Translatable module works as it normally does.
Also, would you mind using the "old" array syntax when declaring the $allowed_actions
static variable? This is because unfortunately I have to use a server that runs PHP 5.3 .. :)
Besides these changes, @Tom-Alexander did an amazing job!
Could you make a change and do a PR for that @Sanderha ? I'd be happy to merge it.
Cool, I've done the PR. #46
I've added the TranslatableCatalogExtension to my modeladmin, which then shows a language select dropdown in my modeladmin area. When I try to use it to select a language, it throws the following error:
Action 'LangForm' isn't available on class ProductsAdmin.