Skip to content

VichFileType : Fix translation for 'delete_label' when 'download_label' is a callable #1573 - #1574

Merged
garak merged 17 commits into
dustin10:masterfrom
theredled:bugfix-translations-1573
Mar 12, 2026
Merged

VichFileType : Fix translation for 'delete_label' when 'download_label' is a callable #1573#1574
garak merged 17 commits into
dustin10:masterfrom
theredled:bugfix-translations-1573

Conversation

@theredled

@theredled theredled commented Feb 24, 2026

Copy link
Copy Markdown
Contributor

In VichFileType, when download_label is either a callable or true, delete_label translation domain is affected, breaking the label. Added separate 'translation_domain' options for each label (download_label_translation_domain, delete_label_translation_domain)
#1573

…callable - creating separate 'translation_domain' options for each label dustin10#1573
@theredled theredled changed the title VichFileType : Ffix translation for 'delete_label' when 'download_label' is a callable VichFileType : Fix translation for 'delete_label' when 'download_label' is a callable #1573 Feb 24, 2026
@garak

garak commented Mar 1, 2026

Copy link
Copy Markdown
Collaborator

You can rebase to get the PHP-CS-Fixer errors fixed.
The rest of the failures are up to you.

@theredled

Copy link
Copy Markdown
Contributor Author

Should be ok!
I also added 'translation_domain' option back in VichFileType for full backwards-compatibility

@theredled

Copy link
Copy Markdown
Contributor Author

Sorry, changes got lost between repos locally, I should have re-run tests before pushing.

Fixed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_domain and delete_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_domain is returned by resolveDownloadLabel, but there’s no test for the new explicit option (download_label_translation_domain in the field options) being propagated to the view/template when download_label is a plain string. Adding such a case would help catch the current regression where the widget may ignore the configured domain/false value unless it comes from the callable/true branches.
                $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.

Comment thread templates/Form/fields.html.twig
Comment thread src/Form/Type/VichFileType.php
Comment thread src/Form/Type/VichFileType.php Outdated
Comment thread src/Form/Type/VichFileType.php
@theredled

theredled commented Mar 3, 2026

Copy link
Copy Markdown
Contributor Author

Note: added a $options parameter to signature of VichFileType::resolveDownloadLabel (required to access the configuration)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines 172 to 176
'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,
];

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot do you agree with the comment above?

Comment thread src/Form/Type/VichImageType.php
Comment thread src/Form/Type/VichFileType.php
@theredled

theredled commented Mar 11, 2026

Copy link
Copy Markdown
Contributor Author

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 master branch
Only thing I've done was moving the methods that were creating mocks from final classes (PropertyMapping, PropertyMappingFactory, MetadataReader, UploadHandler) from Vich\UploaderBundle\Tests\TestCase to new trait Vich\UploaderBundle\Tests\TestCaseTrait, and they're now triggering errors from PHPStan

Don't know what to do about it.

@theredled

Copy link
Copy Markdown
Contributor Author

Ok I got it, the error was already happening but it was manually excluded in phpstan-baseline.neon for TestCase.php.

Doing the same for TestCaseTrait.php.

@garak
garak merged commit 4b88b23 into dustin10:master Mar 12, 2026
13 checks passed
@theredled

Copy link
Copy Markdown
Contributor Author

Thanks!

@theredled
theredled deleted the bugfix-translations-1573 branch March 12, 2026 08:56
Copilot AI added a commit that referenced this pull request Apr 11, 2026
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>
garak pushed a commit to garak/VichUploaderBundle that referenced this pull request May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants