fix(manager): restore template preview image when creating document#16889
fix(manager): restore template preview image when creating document#16889Ibochkarev wants to merge 2 commits intomodxcms:3.xfrom
Conversation
- Add getPreviewPath() and getPreviewSourceId() to modElement so phpThumb receives a filesystem path and source id instead of a URL - Template/GetList now passes path and source to phpthumb.php; fixes blank preview when base_url is not / and when Flysystem received URLs - In modMediaSource::prepareSrcForThumb(), convert local URLs to paths before fileExists() so legacy callers passing URLs still work - In PhpThumb processor: guard pathinfo extension for PHP 8.1 (strtolower null deprecation) and remove error_reporting(E_ALL) so deprecations do not corrupt image output Fixes modxcms#16256
Code ReviewSummary Fixes template preview images when creating documents. Adds Suggestions
Assessment Solid fix addressing a real issue with phpThumb expecting filesystem paths rather than URLs. The PhpThumb processor cleanup (removing Verdict: Approve |
- Rename getPreviewPath() to resolvePreviewSource() for clarity and encapsulate logic for resolving the preview file source. - Update getPreviewPath() to utilize the new method, returning an empty string if no preview file is set. - Modify getPreviewSourceId() to return the source ID from the resolved preview source. - Enhance documentation for clarity on return types and functionality.
What does it do?
getPreviewPath()andgetPreviewSourceId()tomodElementso the template list can pass a filesystem path and media source id to phpThumb instead of a URL.Template/GetListto build the template preview phpThumb URL using path + source; phpThumb’s default source (Flysystem) expects a path, so passing a URL caused blank output.modMediaSource::prepareSrcForThumb(), converts local HTTP URLs (matching the site base URL) to filesystem paths before thefileExists()check, so callers that still pass URLs (e.g. subdirectory installs) continue to work.pathinfo(..., PATHINFO_EXTENSION)returns null (guard withis_string($ext)beforestrtolower($ext)), and removeserror_reporting(E_ALL)so deprecations do not corrupt the image response.Why is it needed?
Template preview images did not render when creating a new document (Create document → template picker): the preview URL pointed at phpThumb with
srcset to a full URL. The default media source uses Flysystem, which expects a path;fileExists($url)failed and the processor returned empty output. In subdirectory installs the image path was also wrong. PHP 8.1+ triggered a deprecation forstrtolower(null)anderror_reporting(E_ALL)caused that to appear in the image body.How to test
assets/images/or a media source).base_urle.g./subdir/), repeat and confirm the preview still loads.Related issue(s)/PR(s)
Resolves #16256