Hi,
I'm using Wysiwyg template (which is great !) with tinymce 4, and it is not working since a large part of the code changed in tinymce since version 4. I finally found a solution and wished to share it to help in the integration of tinymce4 that is much nicer than the version 3 :

// wysiwyg_template.module  l. 146
function wysiwyg_template_wysiwyg_plugin($editorName, $version) {
  switch ($editorName) {
    case 'tinymce':
      return array(
        'template' => array(
          'buttons' => array('template' => t('Insert templates')),
          'url' => 'http://drupal.org/project/wysiwyg_template',
          'internal' => TRUE,
          'options' => array(
            'template_external_list_url' => _wysiwyg_template_get_list_url($editorName),
+           'templates' => _wysiwyg_template_get_list_url($editorName),
            //load the javascript template list
            //'template_selected_content_classes' => variable_get('wysiwyg_template_selected_content_classes', ''),
            //'template_replace_values' => array('caption' => 'Replace with this content')
          ),
          'extended_valid_elements' => array( //tinymce specific - allows additional elements to be used
            'img[id|class|src|border=0|alt|title|width|height|align|name|style]',
          ),
          'load' => TRUE,
        ),
      );
      break;
    case 'ckeditor':

// wysiwyg_template.module  l. 221
function wysiwyg_template_list_js($editorName, $contentType) {
  global $base_url;
  //don't cache templates
  drupal_add_http_header('CacheControl', 'no-cache');
  drupal_add_http_header('Expires', '-1');
  drupal_add_http_header('Content-Type', 'text/javascript; charset=UTF-8');
  $templates = wysiwyg_template_load_all($contentType);
  switch ($editorName) {
    case 'tinymce':
+			$editors = wysiwyg_load_includes('editors', 'editor');			
+			$version = wysiwyg_tinymce_version($editors[$editorName]);
+			if( version_compare($version, '4', '>') ){
+				$outArray = array();
+				foreach ($templates as $template) {
+					$outArray[] = array(
+						'title' => $template['title'],
+						'description' => $template['description'],
+						'url' => url('wysiwyg-templates/' . $editorName . '/load/') . $template['name'],
+					);
+				}
+				print json_encode($outArray);
+			}else{
				print 'var tinyMCETemplateList = ';
				$outArray = array();
				foreach ($templates as $template) {
					$outArray[] = array(
						$template['title'],
						url('wysiwyg-templates/' . $editorName . '/load/') . $template['name'],
						$template['description'],
					);
				}
				print json_encode($outArray) . ";";
+			}
      break;
    case 'ckeditor':

Hope this helps and could be ported in next version !

Comments

seren10pity13’s picture

Issue summary: View changes
jurgenhaas’s picture

Status: Needs review » Needs work

Hi @seren10pity13, this is great and your help in making it work with newer editor versions is much appreciated.

To get others in the team to review your work it would help a lot if you could provide your work as a proper patch and if your coding was following Drupal's coding standards.

jurgenhaas’s picture

Status: Needs work » Postponed

@seren10pity13, is this still a relevant issue? If so, would you mind providing a patch so that we can move on with the solution?

seren10pity13’s picture

Hi Jurgenhaas,

I didn't used it since a long time, but I think it's still a relevant issue.
I'm sorry I didn't answered your previous message, but I just don't know how to create a proper patch. I'm not a developper, I don't use Drush etc. I guess the code provided above is following the Drupal coding standard's as I reused existing pieces of your code, and already existing functions, but I can't be shure.
Sorry I can't help further.

calvinjuarez’s picture

Why was this postponed? TinyMCE 4 doesn't recognize any WYSIWYG templates, but the info page for this module lists TinyMCE as a supported editor. So you should update the docs or (obviously much better) update the module so it can actually do what it claims to do.

jurgenhaas’s picture

Why was this postponed?

To answer your question, the reason was that we didn't get any response for as long a 2 years from comment #2 above.

So if you anybody wants to move this forward, providing a patch is highly appreciated and will give others who are using that editor a chance to review the solution which is necessary to get this into the module eventually.

@calvinjuarez are you interested? Let us know if we can help you getting started.

sim_1’s picture

Version: 7.x-2.11 » 7.x-2.12
Status: Postponed » Needs review
StatusFileSize
new2.82 KB

Hi --
This is still an issue (Drupal 7.67, Wysiwyg 7.x-2.5+20-dev, Wysiwyg API template plugin 7.x-2.12 and TinyMCE 4.9.4).

I'm attaching a patch (made from the code above) for anyone else who is trying to use TinyMCE 4.x with Wysiwyg Templates. This worked for me to get the template dialog displaying and inserting templates again.

happypanda’s picture

The patch by sim_1 works, thanks for providing that!