Postponed
Project:
Focal Point
Version:
2.x-dev
Component:
Other Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
26 Mar 2020 at 21:10 UTC
Updated:
17 Dec 2025 at 03:54 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #2
bleen commentedwhat happens when you:
Its unclear if you ever did that last step from the original post. If you did then a focal point record would be created and I suspect you will get errors all over the place when you try to view that node anywhere.
I understand the use-case you are looking to support but I'm not sure what the "right" user experience should be here. It seems like if we want to allow other mimetypes to be uploaded we would need to detect that and not show the focal point UI and not save the focal point position, etc.
thoughts?
Comment #3
kasey_mk commentedI typically use Paragraphs instead of having a media field directly on a node, but I tried adding a media field for images to a node type and still had no problems.
The image field I'm changing the widget on is on my image media type. But as noted, I can edit and save the media after turning the Focal Point widget back on with only a warning in the log: "Could not apply Thumbnail (100×100) image style to public://filename.svg because the style does not support it." But the image still looks and acts totally fine wherever it's in use.
I'm using Drupal 8.8.4; Focal Point 1.3.0; and SVG Image 1.13.0
I haven't tested any other mimetypes, so I can't say whether allowing anything someone might put into "Allowed file extensions" on the field is a good idea, or if some would result in worse results than a warning in the log. Perhaps svg_image is effectively sidestepping more serious issues for SVGs.
Comment #4
tlthades commentedFocal Point is installed in the Varbase Drupal assembly and I cannot load SVG images. It is necessary to allow loading SVG bypassing the Focal Point functions as if we would load it through the standard Image field.
Comment #5
bleen commentedI'm still not convinced that this is the "right" thing to do, but I'm certainly willing to consider it. It may require a checkbox or some other configuration to let site owners affirm "yes, I want to allow SVGs and yes I understand that the focal point wont actually do anything" or some other warning... otherwise I see people submitting all sorts of bugs that focal point isnt working because they do not understand how SVGs work
Patches welcome
Comment #6
tlthades commentedSo far I have abandoned SVG and used PNG.
This will complicate the user interface and is likely to be an extra feature.
By default, SVG is not used. To add a new extension, we must manually add it in the field settings. Not many will face this challenge. Maybe, when loading a format other than png, gif, jpg, jpeg, make a notification that Focal Point processes only png, gif, jpg, jpeg? Now we get an error that the format is not supported, you can write a notification instead:
Focal Point only works with png, gif, jpg, jpeg. Other formats are downloaded without the participation of Focal Point.Such a solution will be universal for any other format and will not limit users.
I am not strong in the technical part of the implementation, so my proposal may not be the most successful.
Comment #7
anybodyWell from a users perspective this is a quite important functionality. As you can see in svg_image module there's also confusion and demand for that: #3187356: SVG image not being accepted in the Media Library Image type
So I think there are two questions:
1. Can we improve the behaviour if there are file suffixes allowed which focal doesn't support? This would prevent people from searching for the reason why a file suffix doesn't work even if allowed in the field settings.
2. If an SVG is uploaded, wouldn't it be possible to fall back to the default widget (or hide focal functionality and show a message)?
3. Is it technically possible to set a focal point on an SVG? Then we'd need someone to do or sponsor it?
Comment #8
anybodyComment #9
kasey_mk commentedI really like TLTHades' suggestion:
I'm afraid I don't understand the focal_point code well enough to attempt a patch that would do this, but it would perfectly satisfy my needs and I don't think it would be too confusing for general use.
Comment #10
ochenk commentedThere's a quick fix here, and it's extending the focal_point form widget off of svg_image's widget instead of core's image widget. Just doing that seems to make this work pretty flawlessly, at least in my testing. However, there's a huge downside, and that's svg_image becomes a dependency of focal_point. My guess is that's a no-go, so implementing it properly properly is probably going to require not using svg_image and instead rolling your own svg support. Which makes this task a much larger lift.
In the meantime, here's a patch for the quick fix. With this applied, you can add svg as an available extension in the field settings, and then upload svgs via the focal_point widget. It even previews it with the crosshairs. Of course it doesn't actually crop the svg, since I don't think that's possible, but functionally, this allows svg uploads using the focal_point widget.
Comment #11
ahmad abbad commentedPatch #10 worked for me on core 9.2.x
Comment #12
ckidowDrupal: 9.1.10
Focal Point: 8.x-1.5
After applying patch from comment #10 the Form Widget Type "Image (Focal Point)" ("image_focal_point") is gone and can't selected any more. Only "Entity Browser" and "Image" are available.
Comment #13
schoenef commentedPatch #10 workes for me as well without problems. @CKIDOW, do you have the contrib svg_image module installed? It is required for this patch.
Comment #14
schoenef commentedok, we realized now, that #10 is killing the "image_focal_point" widget in the form display, which kind of defying the purpose - it only happened like this recently, I'm pretty sure it worked 8 days ago...
We are now on Drupal 9.2.7
Comment #15
schoenef commentedI added another patch, I think the problem is the changed field_types in the @FieldWidget anotation by @ochenk.
Comment #16
schoenef commentedalright, and now a patch, that actually applies... (#12)
Comment #17
schoenef commentedAnd a one, that applies and is working - copy paste is harder then you think ;)
Comment #18
schoenef commentedComment #19
anybody@Schoenef, are you a maintainer? I can't see a commit or release.
Comment #21
smustgrave commented#17 works like a charm
Comment #22
higherform commentedPatch #17 working as expected with Drupal 9.4.5, focal_point 1.5.0, and svg_image 1.16.0.
Recommend merging this patch for next release.
Thanks, @Schoenf
Comment #23
hudriThe existing patch would enforce a hard dependency to the svg_image module, which is completely unacceptable, so back to needs work.
I can see two options:
a) Duplicate the entire focal point widget code into a sub-module, which can have the dependency
OR
b) make a class alias so we can dynamically extend from the appropriate class, without code duplication and without the user having to configure anything:
I do have time budget to create a proper merge request, but need feedback from maintainer which way to go.
Comment #24
joshi.rohit100I think, this should be like -
Comment #25
hudriChanged to postponed due to planned changes in the field widget (convert to standalone form element, 2657592)
Comment #26
hudriI don't think comment #24 covers the root problem: Do we need to inherit from the core image module or from the svg_image module? Creating a base widget surely is a good idea, but it just moves the same problem to the base widget.
But I think I've found the proper way to dynamically react on the existance of the svg_image module: hook_element_plugin_alter (change record, API doc)
It was explicitly designed to change the plugin class on runtime, exactly what is needed here. However, I still think we should wait for the other issue with the standalone form element.
Comment #27
mesharideb commentedThis patch enhances the Drupal Focal Point module to handle SVG images. It introduces a dependency on the SVG Image module and modifies the FocalPointImageWidget to extend from SvgImageWidget instead of ImageWidget. Additionally, it adds a condition to check if the image is an SVG. If it is, the function returns an empty array, bypassing the focal point functionality which is not applicable to SVG images.
Comment #28
milos.kroulik commentedUnfortunately, the patch from #27 doesn't seem to be working for me, as the "sub-widget" still doesn't allow SVG.
Comment #29
skaughtIMO: this should be at least it's own submodule to focal_point, it not it's own project. the dependency to svg_field is heavy (also new vendor package needed to be installed), forces every site to now use another module even if they don't 'need svg' at this time.
Certainly, would be nice if Drupal Core had an SVG solution in place to work with.
Comment #30
skaughtComment #31
miiimoooAdding a re-roll of the patch in #13 for 2.1.0
The patch in #27 adds some check which is not part of this patch
Comment #34
liam morlandCreated a merge request with the patch in #31.
Comment #35
inregards2plutoRe-roll of patch to add commit from #34. I can also confirm that the patch works for D11.2.10 and focal_point v2.1.2. I will note that, while it allows uploads, it does NOT show updated images in the Preview sub-modal. But, based on the comment in #27, it sounds like this bypass is intentional and expected?