Patch to help compatibility with Advanced Custom Fields

Any suggestions on how to improve qTranslate? Post here!

Patch to help compatibility with Advanced Custom Fields

Postby MarcGuay » Wed Jul 04, 2012 2:49 pm

Hello,

Currently qTranslate and Advanced Custom Fields do not play well together. The problem is specifically that the WYSIWYG field created by ACF does not allow media to be inserted into it. (A larger problem is that the editors it creates cannot be translated in the same way as the main editor, but I've spent several hours looking into it and qTranslate is quite stubbornly designed for one single "content" instance.) So I found that the problem is that qTranslate is prefixing the wpActiveEditor variable with "qtrans_textarea" for every wp-editor-wrap class in qtrans_wpActiveEditorOverload, and because the ACF editors have this class, the media is attempted to be inserted into the object with the ID qtrans_textarea_fields[xxxxxx], and such a thing does not exist. All of that to say, here's a patch which fixes the error by forcing qTranslate to only add the prefix in the case where it is the "content" editor, which is the only one the rest of the code cares about anyways.


Code: Select all
Index: qtranslate_javascript.php
===================================================================
--- qtranslate_javascript.php   (revision 565448)
+++ qtranslate_javascript.php   (working copy)
@@ -236,7 +236,11 @@
   $q_config['js']['qtrans_wpActiveEditorOverload'] = "
      jQuery('.wp-editor-wrap').unbind('mousedown');
      jQuery('.wp-editor-wrap').mousedown(function(e){
-         wpActiveEditor = 'qtrans_textarea_'+this.id.slice(3, -5);
+          var sliced = this.id.slice(3, -5);
+            if (sliced == 'content')
+             wpActiveEditor = 'qtrans_textarea_content';
+            else
+                wpActiveEditor = sliced;
      });
      ";
   
MarcGuay
 
Posts: 2
Joined: Wed Jul 04, 2012 2:38 pm

Re: Patch to help compatibility with Advanced Custom Fields

Postby romaintb » Tue Sep 04, 2012 1:03 pm

Have one myself.


Code: Select all
Index: qtranslate_javascript.php
===================================================================
--- qtranslate_javascript.php   (révision 142)
+++ qtranslate_javascript.php   (copie de travail)
@@ -305,7 +305,9 @@
         tinyMCEPreInit.mceInit[id].setup = function(ed) {
            ed.onSaveContent.add(function(ed, o) {
               if (!ed.isHidden())  {
-                  qtrans_save(switchEditors.pre_wpautop(o.content));
+                        if (ed.editorId.match(/^qtrans_/)) {
+                            qtrans_save(switchEditors.pre_wpautop(o.content));
+                        }
               }
            });
         };
@@ -350,7 +352,7 @@
      switchEditors.go = function(id, lang) {
         id = id || 'content';
         lang = lang || 'toggle';
-         
+           
         if ( 'toggle' == lang ) {
            if ( ed && !ed.isHidden() )
               lang = 'html';
@@ -367,7 +369,11 @@
         
         // update merged content
         if(inst && ! inst.isHidden()) {
-            tinyMCE.triggerSave();
+                jQuery.each(tinyMCE.editors, function(ei, v) {
+                    if (v.editorId.match(/^qtrans_/)) {
+                        v.save();
+                    }
+                });
         } else {
            qtrans_save(vta.value);
         }
@@ -378,11 +384,6 @@
            return;
         }
         
-         if(lang!='tmce' && lang!='html') {
-            document.getElementById('qtrans_select_'+qtrans_get_active_language()).className='wp-switch-editor';
-            document.getElementById('qtrans_select_'+lang).className='wp-switch-editor switch-tmce switch-html';
-         }
-         
         if(lang=='html') {
            if ( inst && inst.isHidden() )
               return false;
@@ -411,6 +412,9 @@
            dom.addClass(wrap_id, 'tmce-active');
            setUserSetting('editor', 'tinymce');
         } else {
+                document.getElementById('qtrans_select_'+qtrans_get_active_language()).className='wp-switch-editor';
+            document.getElementById('qtrans_select_'+lang).className='wp-switch-editor switch-tmce switch-html';
+               
            // switch content
            qtrans_assign('qtrans_textarea_'+id,qtrans_use(lang,ta.value));
         }
romaintb
 
Posts: 2
Joined: Tue Sep 04, 2012 1:01 pm

Re: Patch to help compatibility with Advanced Custom Fields

Postby MarcGuay » Tue Sep 04, 2012 1:20 pm

Hi,

Does your patch fix the issue of ACF WYSIWYG fields not being translatable? Just scanning over the changes it seems to do more than what I suggested...

Marc
MarcGuay
 
Posts: 2
Joined: Wed Jul 04, 2012 2:38 pm

Re: Patch to help compatibility with Advanced Custom Fields

Postby romaintb » Tue Sep 04, 2012 1:25 pm

hum, i seriously doubt it, but my diff is not really a response to your problem, more a patch submited to qtranslate than an actual response to you, sorry.
the problem that my patch fixes, is that the content of a post is overriden by the last tinymce from ACF.
romaintb
 
Posts: 2
Joined: Tue Sep 04, 2012 1:01 pm

Re: Patch to help compatibility with Advanced Custom Fields

Postby elainemarley » Wed Oct 10, 2012 11:33 am

romaintb's solution did fix my issue with qtranslate rewriting the wordpress area content with my last ACF textarea. Please do update the plugin with this. I still can't get ACF WYSIWYG to translate with qtranslate and I have them duplicated.
elainemarley
 
Posts: 5
Joined: Wed Jun 27, 2012 2:19 pm

Re: Patch to help compatibility with Advanced Custom Fields

Postby gromateist » Sun Dec 30, 2012 5:34 pm

How to aply this patch? Where should I paste the code?
gromateist
 
Posts: 2
Joined: Sun Dec 30, 2012 5:33 pm

Re: Patch to help compatibility with Advanced Custom Fields

Postby alexleonard » Tue Jan 29, 2013 10:36 am

@gromateist

Go into wp-content/plugins/qtranslate/qtranslate_javascript.php

Go to line 308

Delete
Code: Select all
qtrans_save(switchEditors.pre_wpautop(o.content));


Insert
Code: Select all
                if (ed.editorId.match(/^qtrans_/)) {
                       qtrans_save(switchEditors.pre_wpautop(o.content));
                 }


That worked for me.

Qian Qin, any chance this fix could be added to the next plugin version?
alexleonard
 
Posts: 7
Joined: Tue Jun 28, 2011 12:13 pm

Re: Patch to help compatibility with Advanced Custom Fields

Postby gromateist » Tue Feb 26, 2013 5:42 pm

@alexleonard it works! Thanks! :D
gromateist
 
Posts: 2
Joined: Sun Dec 30, 2012 5:33 pm


Return to qTranslate Suggestions Forum

Who is online

Users browsing this forum: No registered users and 2 guests