Kraftbit / nova-tinymce5-editor

Nova TinyMCE 5 Editor is Laravel Nova field that integrates TinyMCE5 WYSIWYG editor.
https://kraftbit.com
5 stars 8 forks source link

Incompatible with translatable fields #3

Open RomkaLTU opened 3 years ago

RomkaLTU commented 3 years ago

Incompatible with translatable fields (when trying to use with media library) because of ID instead of class usage. The translatable fields usually using 2 or more fields, and obviously, these fields cant have the same ID. I think this is not only this package issue but https://github.com/classic-o/nova-media-library too.

Apatrid commented 3 years ago

I haven't really tested it with all translatable packages and I don't know which translation package you are using. However, I have used this package along with Astronomic Laravel Translatable and I made it work.

Here's an example: NovaTinymce5Editor::make('Body', 'body:en') ->id('body_en') ->placeholder('Enter content here') ->withMeta(['mediaLibrary' => true]) ->hideFromIndex(),

MediaLibrary::make('Insert image', 'js_callback_media_library_body_en') ->jsCallback('mediaLibrarySelectFiles', ['editor' => 'body_en']) ->types(['Image']),

RomkaLTU commented 3 years ago

This is actually translations for models, there is another type of translation packages group, like https://github.com/spatie/laravel-translatable they storing translations into JSON columns. Here how it looks:

CleanShot 2021-02-12 at 13 19 20@2x

When switching between languages, we switching editors. They are all rendered simultaneously, so obviously, we can't use the same ID for all.

Apatrid commented 3 years ago

Sure, I am familiar with Spatie's translatable package, but like I said - I haven't tested it with. I will try to find some time to upgrade my package and make it compatible with Spatie's translatable or feel free to fork this repo and fix it. PR's welcome.

RomkaLTU commented 3 years ago

Thanks for the follow-up. Just update: this is not actually spatie/laravel-translatable problem because Nova Media Library jsCallback is targeting ID, not a class. My current workaround is very inconvenient, use TinyMCE integrated Image field and paste image source from Media library resource.