-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom upcasting for image widget #1080
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tl;dr It looks like unnecessary overcomplication at this point.
I believe we should not further customize upcast
/upcasts
combo just for this widget. Actually I think we don't need this feature at this point.
What you wanted to do here is to add a common handling for all element types in imagebase
definition, and allow extending plugin to easily provide upcast for just any element.
Doing this is still a straightforward task:
- Extract common task to
CKEDITOR.plugins.imagebase.imageWidgetDefinition
method, say_isValidImageElement()
. - Simply use this function in your deriving widgetDefinition, say easyImageWidgetDefinition.
Take a look at t/932-2970-upcast-simplified
branch.
However it required one issue fix in 6232b54, as currently widget upcast
methods are executed in a totally random context.
The issue with the solution you suggested is the fact that IMO it would be a very common scenario to load content into the editor with no |
@Comandeer I agree that upcast needs often to alter the markup, but it does so after checking if the input markup/element is OK. At this point element is not yet changed. Am I missing something? |
Ok, let's think about
And that overwrite covers only one case. What about other ones? E.g. image wrapped in link? If widget would allow linking, then links with images should have additional upcast method. If we're trying to create universal base plugin, adding new upcasting method alongside new feature integration should be easier than requesting to overwrite
I don't understand it. |
You're not forced to duplicate and copy the code. If you want to upcast a link that could contain a Look at my recent push to the This implementation looks even cleaner that I thought, and it reuses existing API. Assuming that #1094 is fixed Thus I don't think we need to introduce custom upcasting logic, as we can solve nicely this problem with existing mechanisms. |
Actually your workaround is not really a workaround, because I'd also move it into |
After talk with @mlewand we decided to go with |
What is the purpose of this pull request?
New feature for new feature
Does your PR contain necessary tests?
All patches which change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.
This PR contains
What changes did you make?
I've created custom
upcast
menu for image widgets created byimagebase
plugin, which loops through all functions passed inupcasts
property and does additional checks (at the moment it checks only if the element is not a fake object) before upcasting.