Skip to content

Media Field

Overview

The media field type allows users to upload and manage media files. It includes options for previewing, setting dimensions, adding alt text, and customizing button labels. This field provides flexible configuration options to suit different use cases.

Field Configuration

A simple implementation of the media field type:

php
array(
    'id'    => 'media_id',
    'type'  => 'media',
    'title' => 'My Media',
),

Specific Parameters

ParameterTypeDefaultDescription
urlbooleantrueEnables or disables the URL input field for the media file.
previewbooleantrueEnables or disables previewing of the media file.
libraryarrayarray()Specifies allowed media types (e.g., image, video).
button_titlestringUploadCustom label for the upload button.
remove_titlestringRemoveCustom label for the remove button.
altstring-(Optional) Provides alternative text for accessibility.

General Parameters

ParameterTypeDefaultDescription
idstring-Unique identifier for the field.
typestring-Defines the field type.
titlestring-The title displayed for the field.
subtitlestring-The text displayed under the title.
classstring-Field additional class.
data_typestringserializeDefines how data is stored (e.g., serialize).
namestring-Custom name for the field.
placeholderstringNot selectedPlaceholder text for the input.
attributesarrayarray()Custom HTML attributes.
beforestring-Content to display before the field.
afterstring-Content to display after the field.
descriptionstring-A detailed description of the field.
descstring-A short description, used if description is not set.
helpstring-Additional helper text for guidance. Usually show on the top right corner of the field.
errorstring-Error message to display when validation fails.
dependenciesarray-Show/Hide a field base on another field value.

Example Usage

php
array(
    'id'            => 'media_key',
    'type'          => 'media',
    'title'         => 'Field Title',
    'library'       => array('image', 'video'),
),

Notes

  • The library parameter can be restricted to specific media types (e.g., array('image') for images only).
  • Error messages (error) should be customized for better user feedback.