Stop dropping media custom properties on create/edit - #2598
Open
wakqasahmed wants to merge 1 commit into
Open
Conversation
MediaRelationManager treated custom_properties as a closed set of name/primary. The CreateAction handler enumerated only those two keys, discarding anything an extension added via extendForm(). The EditAction wrote submitted form data straight onto the array-cast custom_properties column, replacing the whole JSON instead of merging, so any key the edit form didn't render was silently lost. Pass the submitted custom_properties array through on create, and merge submitted values onto the record's existing custom_properties on edit so unrendered keys survive. Closes lunarphp#2596
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2596
Summary
MediaRelationManagertreatedcustom_propertiesas a closed set of exactly two keys (name,primary), which silently broke Spatie Media Library's open key/value contract in two ways:CreateActionhandler enumerated onlyname/primaryfrom the submitted form data and discarded everything else, so any field added via the documentedRelationManagerExtension::extendForm()seam rendered, validated, and submitted — but its value was never persisted.EditActionwrote the submitted form data straight onto the model. Becausecustom_propertiesis anarray-cast column, this replaced the whole JSON value instead of merging into it, so any key not rendered by the edit form (imported metadata, dedup markers, alt text, etc.) was silently dropped on save.Fix
custom_propertiesarray through towithCustomProperties()instead of hand-pickingname/primary.mutateDataUsing()to theEditActionthat merges the submittedcustom_propertieson top of the record's existingcustom_properties, so unrendered keys survive while submitted keys still win.Testing
RelationManagerExtension::extendForm()field is persisted when a media item is created.vendor/bin/pest tests/admin/Feature/Support(built a PHP 8.3 + intl/exif/bcmath/gd toolchain via Docker to install the monorepo's Composer dependencies): all 16 tests in that directory pass, including the 2 new tests and the pre-existingPriceRelationManagerTest/RelationManagerExtensionTest/CreatePageExtensionTestsuites.nullinstead of'Jane Doe'), confirming it actually exercises bug 1.php -lon both changed files (no syntax errors).