Conversation
|
Well I guess its the same as https://github.com/wintercms/winter/pull/990/files 😆 |
|
Kind of worked around it using a partial |
|
That looks awesome and will work for 'all' file types. |
|
Hmm or is that only in the mediafinder and not in form widget? Might need to extend it. Need to test it first. |
@AIC-BV It's only related to the mediamanager! ⚠ Your use case is a little more specific ... I think you are using a If it became possible to carry over dynamic icon support to the |
|
@damsfx perhaps we should take the logic for generating the SVG and put it in a helper class so that the mediamanager and the fileupload field can use it? |
|
@LukeTowers Yes, that would be perfect, but I'm not sure how to get started with that change. |
|
@bennothommo do you have any thoughts on a desired API / direction to go in for the proposal of making it easier to reuse the work that was just added for generating icons based on file extension in the media manager? |
|
Sure, we could use the PHP SVG library. Would be very simple to have it generate text on the fly from what I can see. |
|
@LukeTowers @bennothommo Isn't using a library to generate an SVG image (a simple string of characters) a bit over-dimmed? |
|
@LukeTowers Yes, of course. |
|
HTML, maybe here: https://github.com/wintercms/storm/blob/develop/src/Filesystem/Filesystem.php as @bennothommo @jaxwilko @mjauvin any thoughts? |
Move the MediaManager's file extension SVG icon and its styles into a shared backend partial and LESS file, and use them in the FileUpload image modes for files browsers can't display in an <img>, instead of rendering a broken thumbnail. Replaces the earlier PDF iframe approach. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (13)
Included review availability: Your plan provides up to 4 included reviews per hour; 1 remains after this review. WalkthroughThe change adds shared SVG file-icon rendering and styles. The media manager and file-upload previews use the shared icon for non-image files. File-upload responses include an icon value, and preview code falls back to thumbnails when no icon is provided. Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~12 minutes Merge Risk: ⚪ Minimal · up to The reviewed icon and upload-preview changes show no concrete failure or specific merge blocker. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The new icon is escaped before display, and the upload’s existing validation and attachment flow is unchanged. A failure while rendering an icon could nevertheless leave a saved file behind while reporting that the upload failed. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
See 1st message in conversation |
Replaces the original iframe approach in this PR with the direction discussed above: reuse the file extension icon from the MediaManager (#1061) in the FileUpload FormWidget.
Problem
In
imagemode, the FileUpload widget always renders<img src="thumbUrl">. For files that aren't images (e.g. a PDF whenfileTypesallows it),getThumb()returns the file path itself, so the widget shows a broken image, both for existing files and right after upload.Changes
mediamanager/partials/_item-icon.phpintomodules/backend/partials/_file_icon.php, which takes anextensionvariable. The MediaManager now renders it viamakePartial('~/modules/backend/partials/_file_icon.php'). The extension is now escaped, since FileUpload file names are user-supplied..file-iconrules out ofmediamanager.lessintomodules/backend/assets/less/controls/file-icon.less. Bothmediamanager.lessandfileupload.lessimport it, so the icon renders outside the[data-control="media-manager"]scope.makeFileIcon($file)helper: returns the icon markup for files browsers can't display in an<img>,nullotherwise._image_single.phpand_image_multi.phprender the icon instead of the<img>for those files.onUpload()returns the icon markup asicon.fileupload.jsswaps it in for the thumbnail on success.Notes
$displayableImageExtensions: avif, bmp, gif, ico, jpeg, jpg, png, svg, webp), notFileDefinitions::get('imageExtensions'). That definition is configurable viacms.fileDefinitions, and some installs widen it to allow e.g. PDFs in image fields, which is exactly the case this PR fixes.fileupload.cssandmediamanager.csswere recompiled.Testing
Tested in a Winter 1.2 backend with an
attachManyfield (image-multi) and anattachOnefield (image-single):🤖 Generated with Claude Code