October\Rain\Database\Traits\TranslatableAttachments
Overview
TranslatableAttachments stores the files of attachment relations listed in $translatable per locale.
Usage:
use \October\Rain\Database\Traits\Translatable; use \October\Rain\Database\Traits\TranslatableAttachments; public $translatable = ['name', 'image']; public $attachOne = 'image' => [\System\Models\File::class];
Public Methods
public forgetAttachmentTranslation()
public forgetAttachmentTranslation($key, $locale): void
forgetAttachmentTranslation removes the files stored for a locale so it falls back to the default files.
public forgetAttachmentTranslations()
public forgetAttachmentTranslations($key): void
forgetAttachmentTranslations removes the files stored for every non-default locale of an attachment.
public getTranslatableAttachments()
public getTranslatableAttachments(): array
getTranslatableAttachments returns the translatable attributes defined as file attachment relations.
public getTranslatedAttachmentLocales()
public getTranslatedAttachmentLocales($key): array
getTranslatedAttachmentLocales returns the non-default locales that store files of their own for an attachment.
public hasAttachmentTranslation()
public hasAttachmentTranslation($key, $locale = null): bool
hasAttachmentTranslation checks if a locale stores files of its own for an attachment, defaulting to the active locale.
public initializeTranslatableAttachments()
public initializeTranslatableAttachments(): void
initializeTranslatableAttachments trait for a model
Protected Methods
protected defineTranslatableAttachments()
protected defineTranslatableAttachments(): void
defineTranslatableAttachments swaps translatable attachment relations for ones that store files per locale.
protected deleteTranslatableAttachments()
protected deleteTranslatableAttachments(): void
deleteTranslatableAttachments removes the attachment files of every locale after the record is deleted.
protected forgetTranslatableAttachmentFiles()
protected forgetTranslatableAttachmentFiles($key, $locales = null): void
forgetTranslatableAttachmentFiles removes the files stored for the given locales, or every non-default locale.
protected getTranslatableAttachmentField()
protected getTranslatableAttachmentField($key, $locale): string
getTranslatableAttachmentField returns the field column value for an attachment in a locale.
protected getTranslatableAttachmentFiles()
protected getTranslatableAttachmentFiles($key): void
getTranslatableAttachmentFiles returns the attachment files for the default locale and every other locale.
protected getTranslatableAttachmentLocale()
protected getTranslatableAttachmentLocale($key, $field): string|null
getTranslatableAttachmentLocale returns the locale from a field column value, or null for the default locale.
protected isTranslatableAttachment()
protected isTranslatableAttachment($key): bool
isTranslatableAttachment checks if a translatable attribute is a file attachment relation.
protected removeTranslatableAttachmentFiles()
protected removeTranslatableAttachmentFiles($key, $files): void
removeTranslatableAttachmentFiles deletes or orphans files following the relation delete option.