Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW Scaffold formfields for File and Image using new API #613

Conversation

GuySartorelli
Copy link
Member

@GuySartorelli GuySartorelli commented Jun 4, 2024

Uses new API from silverstripe/silverstripe-framework#11269 to scaffold formfields for Image and File has_one relations.

Note that there's no need to bump the framework dependency here - if installing this with framework 5.1 the old code path will be used instead, but the result will be the same.

Issue

@GuySartorelli GuySartorelli force-pushed the pulls/2/scaffold-relation-fields branch from d6c4a89 to 6b81cdc Compare June 5, 2024 01:25
DataObject $ownerRecord
): FormField&FileHandleField {
$field = parent::scaffoldFormFieldForHasOne($fieldName, $fieldTitle, $relationName, $ownerRecord);
$field->setAllowedFileCategories('image/supported');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
$field->setAllowedFileCategories('image/supported');
if ($field->hasMethod('setAllowedFileCategories')) {
$field->setAllowedFileCategories('image/supported');
}

Might as well do the same check as above since the FileHandleField could be changed with Injector

Copy link
Member Author

Choose a reason for hiding this comment

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

setAllowedFileCategories() is defined in the FileHandleField interface, so we don't need to check for it.

setAllowedMaxFileNumber() isn't defined in that interface, which is why the condition for that method is there.

@emteknetnz emteknetnz merged commit 20cc083 into silverstripe:2 Jun 7, 2024
9 checks passed
@emteknetnz emteknetnz deleted the pulls/2/scaffold-relation-fields branch June 7, 2024 05:06
GuySartorelli added a commit to creative-commoners/silverstripe-assets that referenced this pull request Jul 17, 2024
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.

2 participants