VichFileType : Fix translation for 'delete_label' when 'download_label' is a callable #1573 - #1574
Conversation
…callable - creating separate 'translation_domain' options for each label dustin10#1573
|
You can rebase to get the PHP-CS-Fixer errors fixed. |
…nload_label_translation_domain"
|
Should be ok! |
|
Sorry, changes got lost between repos locally, I should have re-run tests before pushing. Fixed. |
There was a problem hiding this comment.
Pull request overview
Fixes translation-domain interference in VichFileType when download_label is callable/true by separating translation-domain handling for the download link vs. the delete checkbox label (issue #1573).
Changes:
- Added per-label translation domain options:
download_label_translation_domainanddelete_label_translation_domain. - Updated download-label resolution to avoid clobbering the form’s
translation_domain. - Updated the form theme and adjusted tests to expect the new download-label domain key.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
src/Form/Type/VichFileType.php |
Introduces new options and updates download/delete label translation-domain wiring. |
templates/Form/fields.html.twig |
Switches download link translation to use download_label_translation_domain. |
tests/Form/Type/VichFileTypeTest.php |
Updates expectations for the renamed download-label translation domain key. |
Comments suppressed due to low confidence (1)
tests/Form/Type/VichFileTypeTest.php:214
- The updated expectations cover cases where
download_label_translation_domainis returned byresolveDownloadLabel, but there’s no test for the new explicit option (download_label_translation_domainin the field options) being propagated to the view/template whendownload_labelis a plain string. Adding such a case would help catch the current regression where the widget may ignore the configured domain/falsevalue unless it comes from the callable/truebranches.
$object,
[
'download_label' => true,
'download_uri' => true,
'asset_helper' => false,
],
[
'object' => $object,
'download_label' => 'image.jpeg',
'download_label_translation_domain' => false,
'download_uri' => 'resolved-uri',
'value' => null,
'attr' => [],
'asset_helper' => false,
],
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ain", fix VichFileType>file to use "'translation_domain'"
|
Note: added a |
…ed to VichFileType
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 'download_label' => $result['download_label'] ?? $result, | ||
| 'translation_domain' => $result['translation_domain'] ?? false, | ||
| 'download_label_translation_domain' => $result['download_label_translation_domain'] | ||
| ?? $result['translation_domain'] | ||
| ?? false, | ||
| ]; |
There was a problem hiding this comment.
In the callable download_label branch, $result can be a plain string (as covered by VichFileTypeTest), but the code still attempts $result['download_label'] / $result['download_label_translation_domain'] / $result['translation_domain']. Accessing array offsets on a string triggers PHP warnings (and can be a TypeError depending on PHP version/settings). Consider branching on is_array($result) (or instanceof \ArrayAccess) and: (1) for scalar results, set download_label to the scalar and download_label_translation_domain to $options['download_label_translation_domain'] ?? $options['translation_domain']; (2) for array results, read keys safely and fall back to the same options when the callable doesn’t specify a domain.
There was a problem hiding this comment.
Wrong : isset / ?? never trigger warnings for non-existent variables, and also it's not a regression, as I only adopted the same codestyle as existing code.
@garak : agree?
|
There seems to be an issue with PHPStan when you create a mock from a final class: phpstan/phpstan#8901 For some reason that issue was present but not detected in Don't know what to do about it. |
|
Ok I got it, the error was already happening but it was manually excluded in Doing the same for |
… TestCaseTrait.php
|
Thanks! |
Ported changes: - Fix translation for 'delete_label' when 'download_label' is a callable (#1574) - Fix VichImageTypeTest failing with LiipImagine enabled (#1580) - Add test with LiipImagine enabled in CI - Fix coding standard (Dockerfile85, static fn) - Document Gedmo/DoctrineExtensions issue (#1582) - Update directory_namer service id in doc - Extract TestCaseTrait for reuse across test base classes - Fix Product::getImage() return type Skipped (not applicable to 3.x): - XML to PHP config migration (already done) - Annotation deprecation layer (3.x removed annotations) - Allow Symfony 8 (3.x already supports it) - BypassFinal fix (not used in 3.x) Agent-Logs-Url: https://github.com/dustin10/VichUploaderBundle/sessions/94f40c3f-9548-4dcc-afd3-c04655b22ed2 Co-authored-by: garak <179866+garak@users.noreply.github.com>
In VichFileType, when
download_labelis either a callable or true,delete_labeltranslation domain is affected, breaking the label. Added separate 'translation_domain' options for each label (download_label_translation_domain,delete_label_translation_domain)#1573