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

TranslatableCatalogExtension - LanguageForm action is not allowed #43

Open
sanderha opened this issue Feb 15, 2016 · 7 comments
Open

TranslatableCatalogExtension - LanguageForm action is not allowed #43

sanderha opened this issue Feb 15, 2016 · 7 comments

Comments

@sanderha
Copy link

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.

@stevie-mayhew
Copy link
Contributor

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?

@sanderha
Copy link
Author

Not at the moment, but if I find a fix i'll let you know

@sanderha
Copy link
Author

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';
    }

@stevie-mayhew
Copy link
Contributor

@sanderha can you confirm the work from @Tom-Alexander fixes this issue? If it does, I will tag a new release from master.

@sanderha
Copy link
Author

@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".
<div class="CMSMain"> $LanguageSelectorForm </div>
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!

@stevie-mayhew
Copy link
Contributor

Could you make a change and do a PR for that @sanderha ? I'd be happy to merge it.

@sanderha
Copy link
Author

Cool, I've done the PR. #46

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants