isobar-nz / silverstripe-catalogmanager

Catalog administration via a LeftAndMain like interface. Lets you create and edit pages outside of the site tree
36 stars 26 forks source link

TranslatableCatalogExtension - LanguageForm action is not allowed #43

Open sanderha opened 8 years ago

sanderha commented 8 years ago

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 commented 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?

sanderha commented 8 years ago

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

sanderha commented 8 years ago

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 commented 8 years ago

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

sanderha commented 8 years ago

@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". `

$LanguageSelectorForm

` 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 commented 8 years ago

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

sanderha commented 8 years ago

Cool, I've done the PR. #46