Documentation

AbstractMedia
in package
implements ExportInterface, MediaCollectionInterface, MediaUploadInterface uses ArrayAccess, Countable, Iterator, Export, MediaUploadTrait

AbstractYes

Class AbstractMedia

Table of Contents

Interfaces

ExportInterface
MediaCollectionInterface
Class implements media collection interface.
MediaUploadInterface
Implements media upload and delete functionality.

Properties

$audios  : array<string|int, mixed>
$files  : array<string|int, mixed>
$images  : array<string|int, mixed>
$items  : array<string|int, mixed>
$media_order  : array<string|int, mixed>|null
$path  : string|null
$videos  : array<string|int, mixed>
$_upload_defaults  : array<string|int, mixed>

Methods

__invoke()  : mixed
Call object as function to get medium by filename.
add()  : void
all()  : array<string|int, MediaObjectInterface>
Get a list of all media.
audios()  : array<string|int, MediaObjectInterface>
Get a list of all audio media.
checkFileMetadata()  : string
Checks that file metadata meets the requirements. Returns new filename.
checkUploadedFile()  : string
Checks that uploaded file meets the requirements. Returns new filename.
copyUploadedFile()  : void
Copy uploaded file to the media collection.
createFromArray()  : Medium|null
Create Medium from array of parameters
createFromFile()  : Medium|null
Create Medium from a file.
createFromUploadedFile()  : Medium|null
Create Medium from an uploaded file.
deleteFile()  : void
Delete real file from the media collection.
files()  : array<string|int, MediaObjectInterface>
Get a list of all file media.
get()  : MediaObjectInterface|null
Get medium by filename.
getImageFileObject()  : ImageFile
getPath()  : string|null
Return media path.
getUploadSettings()  : array<string|int, mixed>
Get upload settings.
hide()  : void
images()  : array<string|int, MediaObjectInterface>
Get a list of all image media.
renameFile()  : void
Rename file inside the media collection.
setPath()  : void
setTimestamps()  : $this
Set file modification timestamps (query params) for all the media files.
videos()  : array<string|int, MediaObjectInterface>
Get a list of all video media.
clearCache()  : void
doAddUploadedMedium()  : void
doCopy()  : void
Internal logic to copy file.
doMoveUploadedFile()  : void
Internal logic to move uploaded file.
doRemove()  : void
Internal logic to remove file.
doRemoveMetadata()  : void
doRename()  : void
Internal logic to rename file.
doSanitizeSvg()  : void
doSaveMetadata()  : void
fileExists()  : bool
getConfig()  : Config
getFileParts()  : array<string|int, mixed>
Get filename, extension and meta part.
getGrav()  : Grav
getLanguage()  : Language
orderMedia()  : array<string|int, mixed>
Order the media based on the page's media_order
translate()  : string

Properties

$media_order

protected array<string|int, mixed>|null $media_order

$_upload_defaults

private array<string|int, mixed> $_upload_defaults = [ 'self' => true, // Whether path is in the media collection path itself. 'avoid_overwriting' => false, // Do not override existing files (adds datetime postfix if conflict). 'random_name' => false, // True if name needs to be randomized. 'accept' => ['image/*'], // Accepted mime types or file extensions. 'limit' => 10, // Maximum number of files. 'filesize' => null, // Maximum filesize in MB. 'destination' => null, ]

Methods

__invoke()

Call object as function to get medium by filename.

public __invoke(string $filename) : mixed
Parameters
$filename : string
Attributes
#[ReturnTypeWillChange]

checkFileMetadata()

Checks that file metadata meets the requirements. Returns new filename.

public checkFileMetadata(array<string|int, mixed> $metadata[, string $filename = null ][, array<string|int, mixed>|null $settings = null ]) : string
Parameters
$metadata : array<string|int, mixed>
$filename : string = null
$settings : array<string|int, mixed>|null = null
Tags
throws
RuntimeException
Return values
string

checkUploadedFile()

Checks that uploaded file meets the requirements. Returns new filename.

public checkUploadedFile(UploadedFileInterface $uploadedFile[, string|null $filename = null ][, array<string|int, mixed>|null $settings = null ]) : string
Parameters
$uploadedFile : UploadedFileInterface
$filename : string|null = null
$settings : array<string|int, mixed>|null = null
Tags
example

$filename = null; // Override filename if needed (ignored if randomizing filenames). $settings = ['destination' => 'user://pages/media']; // Settings from the form field. $filename = $media->checkUploadedFile($uploadedFile, $filename, $settings); $media->copyUploadedFile($uploadedFile, $filename);

throws
RuntimeException
Return values
string

copyUploadedFile()

Copy uploaded file to the media collection.

public copyUploadedFile(UploadedFileInterface $uploadedFile, string $filename[, array<string|int, mixed>|null $settings = null ]) : void

WARNING: Always check uploaded file before copying it!

Parameters
$uploadedFile : UploadedFileInterface
$filename : string
$settings : array<string|int, mixed>|null = null
Tags
example

$settings = ['destination' => 'user://pages/media']; // Settings from the form field. $filename = $media->checkUploadedFile($uploadedFile, $filename, $settings); $media->copyUploadedFile($uploadedFile, $filename, $settings);

throws
RuntimeException

createFromArray()

Create Medium from array of parameters

public createFromArray([array<string|int, mixed> $items = [] ][, Blueprint|null $blueprint = null ]) : Medium|null
Parameters
$items : array<string|int, mixed> = []
$blueprint : Blueprint|null = null
Return values
Medium|null

createFromFile()

Create Medium from a file.

public createFromFile(string $file[, array<string|int, mixed> $params = [] ]) : Medium|null
Parameters
$file : string
$params : array<string|int, mixed> = []
Return values
Medium|null

createFromUploadedFile()

Create Medium from an uploaded file.

public createFromUploadedFile(UploadedFileInterface $uploadedFile[, array<string|int, mixed> $params = [] ]) : Medium|null
Parameters
$uploadedFile : UploadedFileInterface
$params : array<string|int, mixed> = []
Return values
Medium|null

deleteFile()

Delete real file from the media collection.

public deleteFile(string $filename[, array<string|int, mixed>|null $settings = null ]) : void
Parameters
$filename : string
$settings : array<string|int, mixed>|null = null
Tags
throws
RuntimeException

getPath()

Return media path.

public getPath() : string|null
Return values
string|null

getUploadSettings()

Get upload settings.

public getUploadSettings([array<string|int, mixed>|null $settings = null ]) : array<string|int, mixed>
Parameters
$settings : array<string|int, mixed>|null = null

Form field specific settings (override).

Return values
array<string|int, mixed>

hide()

public hide(string $name) : void
Parameters
$name : string

renameFile()

Rename file inside the media collection.

public renameFile(string $from, string $to[, array<string|int, mixed>|null $settings = null ]) : void
Parameters
$from : string
$to : string
$settings : array<string|int, mixed>|null = null

setPath()

public setPath(string|null $path) : void
Parameters
$path : string|null

setTimestamps()

Set file modification timestamps (query params) for all the media files.

public setTimestamps([string|int|null $timestamp = null ]) : $this
Parameters
$timestamp : string|int|null = null
Return values
$this

doAddUploadedMedium()

protected doAddUploadedMedium(string $name, string $filename, string $path) : void
Parameters
$name : string
$filename : string
$path : string

doCopy()

Internal logic to copy file.

protected doCopy(string $src, string $dst, string $path) : void
Parameters
$src : string
$dst : string
$path : string

doMoveUploadedFile()

Internal logic to move uploaded file.

protected doMoveUploadedFile(UploadedFileInterface $uploadedFile, string $filename, string $path) : void
Parameters
$uploadedFile : UploadedFileInterface
$filename : string
$path : string

doRemove()

Internal logic to remove file.

protected doRemove(string $filename, string $path) : void
Parameters
$filename : string
$path : string

doRemoveMetadata()

protected doRemoveMetadata(string $filename, string $path) : void
Parameters
$filename : string
$path : string

doRename()

Internal logic to rename file.

protected doRename(string $from, string $to, string $path) : void
Parameters
$from : string
$to : string
$path : string

doSanitizeSvg()

protected doSanitizeSvg(string $filename, string $path) : void
Parameters
$filename : string
$path : string

doSaveMetadata()

protected doSaveMetadata(array<string|int, mixed> $metadata, string $filename, string $path) : void
Parameters
$metadata : array<string|int, mixed>
$filename : string
$path : string

fileExists()

protected fileExists(string $filename, string $destination) : bool
Parameters
$filename : string
$destination : string
Return values
bool

getFileParts()

Get filename, extension and meta part.

protected getFileParts(string $filename) : array<string|int, mixed>
Parameters
$filename : string
Return values
array<string|int, mixed>

orderMedia()

Order the media based on the page's media_order

protected orderMedia(array<string|int, mixed> $media) : array<string|int, mixed>
Parameters
$media : array<string|int, mixed>
Return values
array<string|int, mixed>

translate()

protected translate(string $string) : string
Parameters
$string : string
Return values
string

        
On this page

Search results