Skip to content

Commit e11f818

Browse files
Visualizer button in Gutenberg's classic block shows no title
1 parent 7587317 commit e11f818

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

classes/Visualizer/Module/Admin.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,23 @@ public function init() {
198198
$this->_addFilter( 'mce_external_languages', 'add_tinymce_lang', 10, 1 );
199199
$this->_addFilter( 'mce_external_plugins', 'tinymce_plugin', 10, 1 );
200200
$this->_addFilter( 'mce_buttons', 'register_mce_button', 10, 1 );
201+
$this->_addFilter( 'tiny_mce_before_init', 'get_strings_for_block', 10, 1 );
201202
}
202203
}
203204

205+
/**
206+
* Add the strings required for the TinyMCE buttons for the classic block (not the classic editor).
207+
*
208+
* @since ?
209+
* @access friendly
210+
*/
211+
function get_strings_for_block( $settings ) {
212+
$class = new Visualizer_Module_Language();
213+
$strings = $class->get_strings();
214+
$array = array( 'visualizer_tinymce_plugin' => json_encode( $strings ) );
215+
return array_merge( $settings, $array );
216+
}
217+
204218
/**
205219
* Load plugin translation for - TinyMCE API
206220
*

classes/Visualizer/Module/Language.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,18 @@ public function tinymce_translation() {
6868
return $translated;
6969
}
7070

71+
/**
72+
*
73+
* The method that returns the strings array
74+
*
75+
* @since ?
76+
* @access public
77+
* @return array
78+
*/
79+
public function get_strings() {
80+
return $this->strings;
81+
}
82+
7183
}
7284

7385
$visualizerLangClass = new Visualizer_Module_Language();

js/mce.js

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
(function($) {
44
tinymce.PluginManager.add('visualizer_mce_button', function( editor, url ) {
55
editor.addButton( 'visualizer_mce_button', {
6-
title: editor.getLang( 'visualizer_tinymce_plugin.plugin_label' ),
7-
label: editor.getLang( 'visualizer_tinymce_plugin.plugin_label' ),
6+
title: getTranslation( editor, 'plugin_label' ),
7+
label: getTranslation( editor, 'plugin_label' ),
88
icon: 'visualizer-icon',
99
onclick: function() {
1010
var frame = wp.media({
@@ -16,4 +16,18 @@
1616
});
1717
});
1818

19+
/**
20+
* Gets the translation from the editor (when classic editor is enabled)
21+
* OR
22+
* from the settings array inside the editor (when classic block inside gutenberg)
23+
*/
24+
function getTranslation(editor, slug){
25+
var string = editor.getLang('visualizer_tinymce_plugin.' + slug);
26+
// if the string is the same as the slug being requested for, look in the settings.
27+
if(string === '{#visualizer_tinymce_plugin.' + slug + '}'){
28+
string = editor.settings.visualizer_tinymce_plugin[slug];
29+
}
30+
return string;
31+
}
32+
1933
})(jQuery);

0 commit comments

Comments
 (0)