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
Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Méthodes publiques

Свойство Type Description
$view The view to render. Supported views are media-addon, media-callout, or media-sm.

Méthodes publiques

Méthode 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 méthode

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 méthode

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.
Résultat MediaItemModule $this

addButtonIf() public méthode

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.
Résultat MediaItemModule $this

addCssClass() public méthode

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
Résultat MediaItemModule $this

addMeta() public méthode

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

addMetaIf() public méthode

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.
Résultat MediaItemModule $this

addOption() public méthode

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.
Résultat MediaItemModule $this

addOptionIf() public méthode

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.
Résultat MediaItemModule $this

getAttributes() public méthode

public getAttributes ( ) : array
Résultat array

getButtons() public méthode

public getButtons ( ) : array
Résultat array

getCssClasses() public méthode

public getCssClasses ( ) : array
Résultat array The css classes.

getDescription() public méthode

public getDescription ( ) : string
Résultat string

getDropdown() public méthode

public getDropdown ( ) : DropdownModule
Résultat DropdownModule

getImageHtml() public méthode

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

getImageSource() public méthode

public getImageSource ( ) : string
Résultat string

getMeta() public méthode

public getMeta ( ) : array
Résultat array

getOptions() public méthode

public getOptions ( ) : array
Résultat array

getTitle() public méthode

public getTitle ( ) : string
Résultat string

getTitleUrl() public méthode

public getTitleUrl ( ) : string
Résultat string

getToggle() public méthode

public getToggle ( ) : array
Résultat array

getToggleHtml() public méthode

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

prepare() public méthode

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

setAttributes() public méthode

public setAttributes ( array $attributes ) : MediaItemModule
$attributes array
Résultat MediaItemModule $this

setDescription() public méthode

public setDescription ( string $description ) : MediaItemModule
$description string
Résultat MediaItemModule $this

setDropdown() public méthode

public setDropdown ( DropdownModule $dropdown ) : MediaItemModule
$dropdown DropdownModule
Résultat MediaItemModule $this

setImage() public méthode

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.
Résultat MediaItemModule $this

setImageIf() public méthode

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.
Résultat MediaItemModule $this

setMeta() public méthode

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

setTitle() public méthode

public setTitle ( string $title ) : MediaItemModule
$title string
Résultat MediaItemModule $this

setTitleUrl() public méthode

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

setToggle() public méthode

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 méthode

public setView ( string $view ) : MediaItemModule
$view string
Résultat MediaItemModule $this

Property Details

$view public_oe property

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