Problem/Motivation
As soon as you upgrade to the 3.x branch, CKEditor 4 will break on any content that contains anchor links with the js error:
Uncaught TypeError: editor.createFakeParserElement is not a function
This is problematic if you wish to test with both editors to ensure a smooth transition, or if you want to retain CKEditor 4 for a while should you need to fall back for some reason.
During the (excellent) work to create the 3.x branch, the decision was made to drop support for CKEditor 4, but functionality can be restored with some minor tweaks to the current 3.x code.
Steps to reproduce
- Update anchor_links to the 3.x branch
- Edit a content item that is still using CKEditor 4 and contains anchor links -OR- create a new content item that uses CKE4 and attempt to add an anchor link.
The error above should appear in the browser console.
(If you're updating from the 8.x-2.x branch, you might also note that composer has removed the CKEditor FakeObjects module even though Drupal will still think it's installed.)
Proposed resolution
- Restore the fakeobjects dependency, or manually require it in your project during the transition.
- Add the dependency back the Anchor plugin.
- Consider adding name attribute back to rendered content for true backward compatibility.
Regarding #3: The plugin currently upcasts anchors with name attributes, but does not include the name attribute in the resulting page source (See: #3399656: Support the "name" attribute for backwards compatibility). As a result, anchor links that have been edited in CKEditor 5 will no longer be present if the text format is switched back to one using CKEditor 4.
Remaining tasks
- ✅ File an issue
- ✅ Addition/Change/Update/Fix
- ➖ Testing to ensure no regression
- ➖ Code review by maintainers
- ➖ Merge
- ❌ Release
API changes
- N/A
Data model changes
- N/A
Release notes snippet
- N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #7 | anchor_link-support-cke4-3484756-7.patch | 3.41 KB | marc.groth |
| #6 | anchor_link-support-cke4-3484756-6.patch | 3.03 KB | marc.groth |
| #2 | anchor_link-support-cke4.patch | 1.96 KB | justcaldwell |
Issue fork anchor_link-3484756
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
justcaldwellI'm attaching a patch with the necessary changes. I'll open an issue branch/MR soon.
I opted to not reintroduce the hard dependency on the CKEditor FakeObjects module now, but to use these changes you would need to include it in your project:
composer require 'drupal/fakeobjects:^1.2'As I said above, this is probably a good idea anyway if you're updating from 8.x-2.x, as composer may well remove the module (if it's not required elsewhere) without uninstalling it. FakeObjects can be uninstalled and removed when it's no longer needed.
The patch also corrects broken paths to the CKEditor 4 toolbar icons.
Comment #4
justcaldwellMR created as promised 🙂
Comment #5
marc.groth commentedThanks for your work on this @justcaldwell!
Unfortunately I'm able to get this working. After updating (details below) I get the following error in the console (when the page loads; the WYSIWYG is missing completely):
It looks like the issue is in the anchor_link module js itself (/modules/contrib/anchor_link/js/unlink/plugin.js which references baseStyles which apparently no longer exists). It's also referenced in /modules/contrib/anchor_link/js/link/plugin.js
My setup is as follows:
Drupal: 10.4.6
Anchor Link: 3.0.3 (with #3484756 and #3399656 patches applied)
Fake Objects: 2.0.1
FWIW: Removing those references seems to fix the issue. Am I missing something or should the patch be updated to include these removals?
Comment #6
marc.groth commentedAttached is an updated patch that includes these removals. The MR on drupalcode will need to be updated to include these changes if this is the correct approach...
Comment #7
marc.groth commentedSorry, for some reason that patch file was not created correctly. Attached is a version that should work.
Comment #9
liam morland@marc.groth the patch in #7 makes more changes than the merge request. It removes
baseStylein four places. Those changes are not in the merge request. Do you know why that is?The merge request solved this problem for us.
However, I think this should be adding a dependency on
fakeobjectsto the info and Composer files.::getDependencies()was removed in commit 1496136 for #3206676: Start a 3.0.x branch for CKEditor Anchor Link for semantic versioning and better integration with Drupal 10, CKEditor 5, and LinkIt and that also removed that dependency.I don't know if the
requires: 'fakeobjects',should be re-added to theplugin.jsfiles.Comment #10
rajab natshah3.0.x depends on ckeditor5, and Drupal 10 and up ship no CKEditor 4, so this does not apply on this branch. CKEditor 4 lives on 8.x-2.x.
Comment #11
rajab natshah