PHP Class MediaItemModule, vanilla

A media item usually renders a item with an image, a title, and a description. This modules supports a media item that may have one image, one dropdown menu, any number of buttons, and any number of meta items. There are three views that you can choose to render: media-addon, media-callout, or media-sm. See these variants in the dashboard styleguide.
Since: 2.3
Author: Becky Van Bussel ([email protected])
Inheritance: extends Gdn_Module
Mostrar archivo Open project: vanilla/vanilla Class Usage Examples

Public Properties

Property Type Description
$view The view to render. Supported views are media-addon, media-callout, or media-sm.

Public Methods

Method Description
__construct ( string $title = '', string $titleUrl = '', string $description = '', string $tag = 'div', array $attributes = [] ) MediaItemModule constructor.
addButton ( string $text, string $url, $attributes ) : MediaItemModule Adds a button to the buttons array.
addButtonIf ( boolean | string | array $isAllowed, string $text, string $url, $attributes ) : MediaItemModule Adds a button to the buttons array if it satisfies the $isAllowed condition.
addCssClass ( $key, $class ) : MediaItemModule Adds a css class to the cssClass array. This is useful for adding an arbitrary css class to a media item view.
addMeta ( string $meta ) : MediaItemModule Adds a HTML-formatted string to the meta array. It's up to the view to concatinate this array, using something like implode(' | ', $meta)
addMetaIf ( boolean | string | array $isAllowed, string $meta ) : MediaItemModule Adds a HTML-formatted string to the meta array if it satisfies the $isAllowed condition.
addOption ( string $key, string $value ) : MediaItemModule Adds a HTML-formatted string to the meta array. It's up to the view to add the info in the options.
addOptionIf ( boolean | string | array $isAllowed, string $key, string $value ) : MediaItemModule Adds a HTML-formatted string to the meta array if it satisfies the $isAllowed condition.
getAttributes ( ) : array
getButtons ( ) : array
getCssClasses ( ) : array
getDescription ( ) : string
getDropdown ( ) : DropdownModule
getImageHtml ( ) : string Renders the html for an image with the image* properties.
getImageSource ( ) : string
getMeta ( ) : array
getOptions ( ) : array
getTitle ( ) : string
getTitleUrl ( ) : string
getToggle ( ) : array
getToggleHtml ( ) : string Rendering helper for the toggle.
prepare ( ) : boolean Prepares the media item for rendering.
setAttributes ( array $attributes ) : MediaItemModule
setDescription ( string $description ) : MediaItemModule
setDropdown ( DropdownModule $dropdown ) : MediaItemModule
setImage ( string $source = '', string $url = '', string $cssClass = '', string $alt = '' ) : MediaItemModule Sets the image. The function DOES NOT handle the url()-ing.
setImageIf ( boolean | string | array $isAllowed, string $source = '', string $url = '', string $cssClass = '', string $alt = '' ) : MediaItemModule Sets the image if it satisfies the $isAllowed condition. The function DOES NOT handle the url()-ing.
setMeta ( array $meta ) : MediaItemModule THIS REPLACES THE META ARRAY If you want to add a meta item, use the addMeta method.
setTitle ( string $title ) : MediaItemModule
setTitleUrl ( string $titleUrl ) : MediaItemModule
setToggle ( string $key, boolean $enabled, string $url, string $label, string $cssClass = '', string $anchorCssClass = 'Hijack' ) Sets up a anchor-style toggle.
setView ( string $view ) : MediaItemModule

Method Details

__construct() public method

MediaItemModule constructor.
public __construct ( string $title = '', string $titleUrl = '', string $description = '', string $tag = 'div', array $attributes = [] )
$title string The media item heading.
$titleUrl string If the heading is an anchor, the anchor url (the view handles url()-ing).
$description string The media item description text.
$tag string The root-level tag of the media item, usually a div or li.
$attributes array The root-level attributes for the Media Item.

addButton() public method

Adds a button to the buttons array.
public addButton ( string $text, string $url, $attributes ) : MediaItemModule
$text string The text to display on the button.
$url string The url of the button.
$attributes The button attributes.
return MediaItemModule $this

addButtonIf() public method

Adds a button to the buttons array if it satisfies the $isAllowed condition.
public addButtonIf ( boolean | string | array $isAllowed, string $text, string $url, $attributes ) : MediaItemModule
$isAllowed boolean | string | array Either a boolean to indicate whether to actually add the item or a permission string or array of permission strings (full match) to check.
$text string The text to display on the button.
$url string The url of the button.
$attributes The button attributes.
return MediaItemModule $this

addCssClass() public method

Adds a css class to the cssClass array. This is useful for adding an arbitrary css class to a media item view.
public addCssClass ( $key, $class ) : MediaItemModule
$key
$class
return MediaItemModule $this

addMeta() public method

THIS ADDS AN ITEM TO THE META ARRAY
public addMeta ( string $meta ) : MediaItemModule
$meta string An HTML-formatted string.
return MediaItemModule $this

addMetaIf() public method

It's up to the view to concatinate the contents of this array, using something like implode(' | ', $meta)
public addMetaIf ( boolean | string | array $isAllowed, string $meta ) : MediaItemModule
$isAllowed boolean | string | array Either a boolean to indicate whether to actually add the item or a permission string or array of permission strings (full match) to check.
$meta string An HTML-formatted string.
return MediaItemModule $this

addOption() public method

Adds a HTML-formatted string to the meta array. It's up to the view to add the info in the options.
public addOption ( string $key, string $value ) : MediaItemModule
$key string A key to access the data.
$value string An HTML-formatted string.
return MediaItemModule $this

addOptionIf() public method

It's up to the view to concatinate the contents of this array, using something like implode(' | ', $meta)
public addOptionIf ( boolean | string | array $isAllowed, string $key, string $value ) : MediaItemModule
$isAllowed boolean | string | array Either a boolean to indicate whether to actually add the item or a permission string or array of permission strings (full match) to check.
$key string A key to access the data.
$value string An HTML-formatted string.
return MediaItemModule $this

getAttributes() public method

public getAttributes ( ) : array
return array

getButtons() public method

public getButtons ( ) : array
return array

getCssClasses() public method

public getCssClasses ( ) : array
return array The css classes.

getDescription() public method

public getDescription ( ) : string
return string

getDropdown() public method

public getDropdown ( ) : DropdownModule
return DropdownModule

getImageHtml() public method

Renders the html for an image with the image* properties.
public getImageHtml ( ) : string
return string The html for an image.

getImageSource() public method

public getImageSource ( ) : string
return string

getMeta() public method

public getMeta ( ) : array
return array

getOptions() public method

public getOptions ( ) : array
return array

getTitle() public method

public getTitle ( ) : string
return string

getTitleUrl() public method

public getTitleUrl ( ) : string
return string

getToggle() public method

public getToggle ( ) : array
return array

getToggleHtml() public method

Rendering helper for the toggle.
public getToggleHtml ( ) : string
return string An HTML-formatted string for a toggle.

prepare() public method

Prepares the media item for rendering.
public prepare ( ) : boolean
return boolean Whether to render the module.

setAttributes() public method

public setAttributes ( array $attributes ) : MediaItemModule
$attributes array
return MediaItemModule $this

setDescription() public method

public setDescription ( string $description ) : MediaItemModule
$description string
return MediaItemModule $this

setDropdown() public method

public setDropdown ( DropdownModule $dropdown ) : MediaItemModule
$dropdown DropdownModule
return MediaItemModule $this

setImage() public method

Sets the image. The function DOES NOT handle the url()-ing.
public setImage ( string $source = '', string $url = '', string $cssClass = '', string $alt = '' ) : MediaItemModule
$source string The image source url. The function DOES NOT handle the url()-ing.
$url string The image anchor link, if the image is an anchor. The function DOES NOT handle the url()-ing.
$cssClass string The CSS class for the image.
$alt string The image alt.
return MediaItemModule $this

setImageIf() public method

Sets the image if it satisfies the $isAllowed condition. The function DOES NOT handle the url()-ing.
public setImageIf ( boolean | string | array $isAllowed, string $source = '', string $url = '', string $cssClass = '', string $alt = '' ) : MediaItemModule
$isAllowed boolean | string | array Either a boolean to indicate whether to actually add the item or a permission string or array of permission strings (full match) to check.
$source string The image source url. The function DOES NOT handle the url()-ing.
$url string The image anchor link, if the image is an anchor. The function DOES NOT handle the url()-ing.
$cssClass string The CSS class for the image.
$alt string The image alt.
return MediaItemModule $this

setMeta() public method

THIS REPLACES THE META ARRAY If you want to add a meta item, use the addMeta method.
public setMeta ( array $meta ) : MediaItemModule
$meta array
return MediaItemModule $this

setTitle() public method

public setTitle ( string $title ) : MediaItemModule
$title string
return MediaItemModule $this

setTitleUrl() public method

public setTitleUrl ( string $titleUrl ) : MediaItemModule
$titleUrl string Url for title, the view handles url()-ing.
return MediaItemModule $this

setToggle() public method

Sets up a anchor-style toggle.
public setToggle ( string $key, boolean $enabled, string $url, string $label, string $cssClass = '', string $anchorCssClass = 'Hijack' )
$key string The toggle key/slug
$enabled boolean Whether the toggle is enabled.
$url string The endpoint the toggle hits.
$label string The aria-label for the toggle.
$cssClass string The toggle css class.
$anchorCssClass string The css class for the anchor. Should probably have 'Hijack' in there.

setView() public method

public setView ( string $view ) : MediaItemModule
$view string
return MediaItemModule $this

Property Details

$view public_oe property

The view to render. Supported views are media-addon, media-callout, or media-sm.
public $view