Support from Acquia helps fund testing for Drupal Acquia logo

Comments

acrollet’s picture

Oof, I was working on a patch for this last night/this morning as well - hey ho for duplicated effort. Anyway, I took a bit different approach, in that I created a separate directory for the 4-compatible version of the plugin, and added a test in hook_ckeditor_plugin() to use it if the ckeditor major version is > 3.

Patch attached for review, we may want to combine code/approaches.

reptilex’s picture

Issue summary: View changes

I managed to get it to work perfectly with ckeditor 4 with one addition to the patch posted by R.Muilwijk.

I had to add a "$plugin['footnotes']['load'] = 1;" to the if clause.

It seems the structure of the footnotes wysiwyg module has changed so this ist the way the file looks now:

function footnotes_wysiwyg_wysiwyg_plugin($editor, $version) {
  $plugin = array(
    'footnotes' => array(
      'buttons' => array('footnotes' => t('Add Footnotes')),
      // This is annoying since it entices you to click on the link in
      // admin/settings/wysiwyg/profile/2/edit and if you do, you lose all unsaved settings.
      // 'url' => 'http://drupal.org/project/footnotes',
      // CKEditor specific, moved: 'extended_valid_elements' => array('fn'),
      'basePath' => base_path(),
      // TinyMCE specific, moved: 'load' => 1
    ),
  );
  switch ($editor) {
    case 'tinymce':
      // This is a hack, the plugin is not loaded without this. (no button shows up.)
      // wysiwyg_tinymce_plugin_settings() removes plugins that have empty($plugin['load'])
      // I'm assuming the wysiwyg module should actually set this for plugins it wants to load?
      // Since there aren't many native external TinyMCE plugins currently, this is likely a bug nobody has noticed.
      $plugin['footnotes']['load'] = 1;
      // For TinyMCE it used to be that 'path' was actually pointing to the editor_plugin.js file.
      // In Drupal 7 this is separated into 'path' and 'filename'.
      // Again wysiwyg_tinymce_plugin_settings() requires this to be present.
      $plugin['footnotes']['filename'] = 'editor_plugin.js';
      $plugin['footnotes']['path'] = drupal_get_path('module', 'footnotes_wysiwyg') . '/tinymce_plugin/';
      return $plugin;
      break;
    case 'ckeditor':
      // For CKEditor, path must be to the directory, not the .js file. The .js file must be called 'plugin.js'.
      // (If including filename here, images to the buttons (defined in js/css)
      // are lost because they are appended to this path.)
      $plugin['footnotes']['path'] = drupal_get_path('module', 'footnotes_wysiwyg') . '/ckeditor_plugin/';
      $plugin['footnotes']['extended_valid_elements'] = array('fn');
      if ($version > 3) {
        $plugin['footnotes']['path'] = drupal_get_path('module', 'footnotes_wysiwyg') . '/ckeditor4_plugin/';
        $plugin['footnotes']['load'] = 1;
      }
      return $plugin;
      break;
  }
}
DamienMcKenna’s picture

Status: Needs review » Needs work

This needs work, at the very least the patch needs to be updated to Drupal's coding standards.

DamienMcKenna’s picture

Status: Needs work » Needs review
FileSize
13.12 KB

A rerolled version of R.Muilwijk's patch.

DamienMcKenna’s picture

BTW the patch in #4 has to be applied with "git apply" instead of the usual "patch -p1" because the image is attached inline.

DamienMcKenna’s picture

FYI the patch appears to work correctly with CKEditor v4.4.6, I think replacing the existing CKEditor v3 handler is a reasonable approach given that it's no longer supported.

zwerg’s picture

Both patches are not working for me. Is it possible to upload the patched files (for CKEditor v3 and v4)?

Thanks in advance!

rbroberts’s picture

Footnote mostly works. So long as you don't enable the plugin it works. After poking around in the debugger, here's what I've found.

To get the plugin working, you need to edit footnotes/footnotes_wysiwyg/ckeditor_plugin/plugin.js and change editor.addCss to CKEDITOR.addCss. That's it.

If you really need to support both v3 and v4 of ckeditor (never mind v5), you'll have to play some games with pulling the version number like the ckeditor module does.

rbroberts’s picture

Okay, I'm going to take that back. While that seems to make it work, you have to have a pretty loose definition of work. While the first footnote added this way was just fine, when I went back to edit the page and insert a second footnote, the first one got trashed.

So don't enable the plugin in the ckeditor config, and just use the filter for [fn][/fn]

pifagor’s picture

Status: Needs review » Needs work
Michelle’s picture

FYI, the latest dev snapshot on the 3.x branch works with CKEditor 4.x with no patch needed.

scott_euser’s picture

Status: Needs work » Closed (outdated)