Skip to content

Add support uuid for attachments #3062

@cat4year

Description

@cat4year

Overriding the Attachment and Attachmentable models is not a problem — Dashboard::useModel handles that.

The problem lies in the attachment-related UI components that do not support UUIDs: Attach, Upload, Picture, and Cropper (which extends Picture).

For Attach in the loadRelatedAttachments method, and for Upload in the __construct method, the original code is:

if (! Assert::isIntArray($value)) {
    return $this;
}

I override it with:

if (! Assert::isArrayClosure($value, static fn (string $uuid) => \Ramsey\Uuid\Uuid::isValid($uuid))) {
    return $this;
}

For Picture, in the targetId method, the original code is:

if (! ctype_digit($value)) {
    return;
}

I override it with:

if (\Ramsey\Uuid\Uuid::isValid($value)) {
    return;
}

I understand that with these overrides the components will now support only UUIDs.

I assume that the proper long-term solution would be to add, for each component, a separate method such as targetUuid() for assigning the attribute. Or by getKeyType method from Attachment model.

For Upload and Attachment, we could add a target attribute with a default value of id. Based on the value of this target attribute, the component would validate the array of identifiers accordingly.

If this is something the platform is interested in, please provide recommendations and I will prepare a PR.

Thank you!

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions