indigoxela / tinymcebackport

Drupal 7 module that provides an up-to-date TinyMCE as WYSIWYG editor and integration with IMCE.
GNU General Public License v2.0
2 stars 0 forks source link

Not possible to toggle between editors when multiple formats enabled #5

Closed indigoxela closed 2 months ago

indigoxela commented 3 months ago

If the TinyMCE editor's enabled on multiple formats, it's not possible to toggle between them. Or actually to toggle between different option sets, as only one (the default) is attached as js setting.

Additionally the logic relies on the element ID, which is quicksand when it comes to Drupal AJAX. :stuck_out_tongue_winking_eye:

indigoxela commented 3 months ago

Additional benefit of the PR: mulitvalue fields now work properly (they actually didn't before). Downside: it's quite a change in logic.

But here we go: #6

izmeez commented 3 months ago

Tested the PR. Able to apply the patch without difficulty. However, behaviour is unchanged from description in #3. Toggle still not working. No errors displayed. Only error in watchdog is

https://sitename.com/sites/all/modules/tinymcebackport/libraries/tinymce/js/tinymce/plugins/imce/plugin.min.js#overlay-context=

The imce/plugin.min.js is not present in the directory. This is was not a fresh install before patching. Can certainly do that to test.

izmeez commented 3 months ago

Really no need to test a fresh install since there have been no new commits.

izmeez commented 3 months ago

Is it possible that the last line of the tinymcebackport.api.php file is interfering?

indigoxela commented 3 months ago

@izmeez hm. Are you using the Overlay? Never tested with that module, as that has always been the module I uninstalled first. :wink:

To be able to toggle you should enable multiple formats. An example for "foobar.module" (simplified):

function foobar_tinymcebackport_enabled_formats_alter(&$enabled_formats) {
  $enabled_formats[] = 'full_html';
}
function foobar_tinymcebackport_options_alter(&$options, $format) {
  if ($format == 'filtered_html') {
    $options['plugins'] = 'autoresize image link lists';
    $options['toolbar'] = 'bold italic blockquote bullist numlist outdent indent link unlink image';
  }
  elseif ($format == 'full_html') {
    $options['plugins'] = 'accordion advlist autoresize charmap code codesample emoticons fullscreen help image imgalign imce link insertdatetime lists media searchreplace table visualblocks visualchars wordcount';
    $options['toolbar'] = 'bold italic blockquote removeformat bullist numlist outdent indent alignleft aligncenter alignright link unlink image media accordion codesample fullscreen code';
    $options['file_picker_types'] = 'file image media';
    $options['menubar'] = TRUE;
  }
}

Is it possible that the last line of the tinymcebackport.api.php file is interfering?

*api.php files are never executed nor even loaded. So, no that won't interfere.

izmeez commented 2 months ago

Yes, I was using the overlay module. Even with it off I have the same results.

When I try the suggestion in https://github.com/indigoxela/tinymcebackport/issues/5#issuecomment-2268223751 adding content opens with the filtered_html option and fails to display a toolbar with full_html option. On exit it shows Warning: Illegal offset type in _tinymcebackport_pre_render_text_format() (line 66 of /var/www/html/sites/all/modules/tinymcebackport/tinymcebackport.module). The same appears when adding content, seeing the filtered_html with toolbar and immediately exiting. This is with the patch applied to the tinymcebackport module.

indigoxela commented 2 months ago

Warning: Illegal offset type

Interesting, something on your setup seems to interfere. The weird thing is: there's no "type" in the code in line 66. Neither with, nor without the patch. My suspicion is, that something went wrong when applying the patch.

Can you revert all patches, then try to apply it cleanly? https://patch-diff.githubusercontent.com/raw/indigoxela/tinymcebackport/pull/6.diff

indigoxela commented 2 months ago

Reopening for possible feedback.

@izmeez to make testing easier, I merged the pull request. You can now just grab the latest dev, either via git or zip download, to test locally. Don't forget to flush caches, though, after replacing the module. :wink: And make sure, there's only one directory of "tinymcebackport".

izmeez commented 2 months ago

@indigoxela Thank you. I have downloaded the latest zip. If my understanding is correct, the module as is does not provide two options to test the toggle. So with just the module as an admin selecting Filtered HTML displays the small toolbar and selecting Full HTML displays no toolbar.

When I enable my custom module the same behaviour is noticed and that is when the error shows up: Warning: Illegal offset type in _tinymcebackport_pre_render_text_format() (line 66 of /var/www/html/sites/all/modules/tinymcebackport/tinymcebackport.module).

Clearly, I must be doing something wrong. Here is the code in the module.

/**
 * Implements hook_tinymcebackport_enabled_formats_alter().
 */
function fullformat_tinymcebackport_enabled_formats_alter(&$enabled_formats) {
  $enabled_formats[] = array('full_html');
}

function fullformat_tinymcebackport_options_alter(&$options, $format) {
  if ($format == 'filtered_html') {
    $options['plugins'] = 'autoresize image link lists';
    $options['toolbar'] = 'bold italic blockquote bullist numlist outdent indent link unlink image';
  }
  elseif ($format == 'full_html') {
    $options['plugins'] = 'accordion advlist autoresize charmap code codesample emoticons fullscreen help image imgalign imce link insertdatetime lists media searchreplace table visualblocks visualchars wordcount';
    $options['toolbar'] = 'bold italic blockquote removeformat bullist numlist outdent indent alignleft aligncenter alignright link unlink image media accordion codesample fullscreen code';
    $options['file_picker_types'] = 'file image media';
    $options['menubar'] = TRUE;
  }
}

Any thoughts are welcome. Thank you.

I do wonder if it would be worth adding this functionality to the module itself and started to look at that as a possibility, but didn't have enough time to figure it out.

izmeez commented 2 months ago

BTW, disabling the Overlay module makes no difference.

izmeez commented 2 months ago

@indigoxela Problem solved: The error was that the line: $enabled_formats[] = array('full_html'); should have been $enabled_formats[] = 'full_html'; as per your previous comment. So the toggle is working. Thank you.

indigoxela commented 2 months ago

@izmeez glad, you sorted things out with your setup. Many thanks for feedback, and especially for pointing me to the toggle problem in the first place. :+1:

indigoxela commented 2 months ago

New release is out! :tada:

izmeez commented 2 months ago

@indigoxela Thank you for all your help and patience. I still think it would be a great feature to add the full editor option into the module itself.