Mediabrowser
Introduction

The MediaBrowser provides access to ressources (Content Manager Pages, MediaSource Files/Objects). Additionally, it allows the upload of new files (through component Uploader).
Integration
Client-side integration
In "backend" mode MediaBrowser is always loaded and can be configured and triggered
using JavaScript. The following binds the click event of <element> to a
MediaBrowser with the given configuration:
<element>: Element to bind the click event to<availableViews>: Any combination of "filebrowser,", "uploader," and "sitestructure," (take care of the trailing comma!)<startView>: One of "filebrowser", "uploader", "sitestructure"<availableMediatypes>: "all" or a list of any registred MediaSource. I.e.: "files", "media1", "media2", "media3", "media4", "attach", "shop", "gallery", "access", "mediadir", "downloads", "calendar", etc.<startMediatype>: Any registered MediaSource (see above).<clickCallback>: Callback to call when the button is pressed. Receives the original click event withe.preventDefault()already called on it.<closeCallback>: Callback to call when MediaBrowser is closed
Image chooser
In "backend" mode ImageChooser can by triggered by creating the necessary
markup and calling cx.mb.imagechooser.init(el, mediatypes = "all", startMediatype = "files") on it.
Server-side integration
Image chooser
If you want to let the user choose an image you can use the image chooser integration. See Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser::getImageChooserMarkup().
Warning
Currently, this only works in backend.
Example
Only
<inputName> and <currentImgFile> are required.
Button
To include the MediaBrowser in your own component through a HTML-button element, do as follows:
-
Create new instance of
\Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser: -
Configure MediaBrowser using options. I.e.:
-
Register the name of a JavaScript callback (that will be triggered once the user did select a ressource in the MediaBrowser):
-
Call the method
MediaBrowser::getXHtml($label)on your instance to fetch the HTML-snippet:$labelwill be used as display name of the button -
Insert the fetched HTML-snippet in the (Sigma) template:
This will create a HTML-button with the label $label set. On trigger, the MediaBrowser will appear on the screen.
Custom layout integration
If you want to open the MediaBrowser not through the default HTML-button (as generated through MediaBrowser::getXHtml($label), but instead through a custom trigger, then simple hide the generated HTML-button (using CSS) and trigger the click-event on the button manually. This allows dynamic customization of the MediaBrowser, by passing a specific config (see available options) to the click-event.
With this method you can also add temporary options and an individual callback.
Options
The following options allow customization of the MediaBrowser modal.
Options can either be set in PHP using Cx\Core_Modules\MediaBrowser\Model\Entity\MediaBrowser::setOptions() or dynamically in JavaScript (through jQuery) when using a custom layout integration.
JavaScript (jQuery)
Note
A vanilla JavaScript integration is currently not supported, as the MediaBrowser does internally depend on jQuery (using instance cx.variables.get("jquery", "mediabrowser")) to track its state.
| PHP option name | jQuery option name | Possible datatypes | Possible values | Default value | Description |
|---|---|---|---|---|---|
type |
- | string | button |
Set the type attribute of the HTML-input element |
|
id |
- | string | Set the id attribute of the HTML-input element. |
||
views |
cxMbViews |
string | sitestructure / uploader / filebrowser |
all |
Set the views (as comma-separated list) that shall be loaded and be available in the left navigation pane. |
startview |
cxMbStartview |
string | sitestructure / uploader / filebrowser |
filebrowser |
Set the default view to display when loading the MediaBrowser. Note: If you do register your own view, you can also set that as startView. |
startmediatype |
cxMbStartmediatype1 |
string | Any registred MediaSource. I.e.: files / media1 / media2 / media3 / media4 / attach / shop / gallery / access / mediadir / downloads / calendar / etc. |
files |
Set initial MediaSource to display (for view filebrowser) |
mediatypes |
cxMbMediatypes |
string | all or a list of any registred MediaSource. I.e.: files / media1 / media2 / media3 / media4 / attach / shop / gallery / access / mediadir / downloads / calendar / etc. |
all |
Set the list of available MediaSources in view filebrowser. |
multipleselect |
cxMbMultipleselect |
boolean | true / false |
false |
Whether or not the selection of multiple ressources is permitted |
modalopened |
cxMbModalopened |
mixed | false / name of callback as string |
false |
Set JavaScript callback to be called after the MediaBrowser has been opened. I.e.: $mediabrowser->setOption(array('modalopened' => 'mediabrowser__opened_callback',));window.mediabrowser__opened_callback = function(){...}; |
modalclosed |
cxMbModalclosed |
mixed | false / name of callback as string |
false |
Can be used instead of MediaBrowser::setCallback(). I.e.: $mediabrowser->setOption(array('modalclosed' => 'mediabrowser__closed_callback',));window.mediabrowser__closed_callback = function(data){...}; |
| - | startPath |
undocumented | undocumented | Last accessed path of MediaSource | Allows overriding the entry point of a MediaSource. |
Callback arguments
Depending on the user's action, the data passed to the modalclose callback has the following form:
File has been selected
Content Manager Page has been selected
Nothing selected
If the user has closed the MediaBrowser without any selection:
Add own view
To add your own view, do as follows:
-
Register an EventLister to event
MediaBrowser.Plugin:initializein ComponentController: -
Register view in
\Cx\Modules\<component>\Model\Event\MyEventListener: -
Implement a JsonData adapter as provider for the view's data
-
Inject view into MediaBrowser in
modules/<component>/View/Script/MediaBrowser.js -
Add template for view in
modules/<component>/View/Template/Generic/MyView.html
-
Is ignored if already set through PHP. ↩