1
|
<?php
|
2
|
|
3
|
/**
|
4
|
* @file
|
5
|
* Definition of MediaBrowserPlugin.
|
6
|
*/
|
7
|
|
8
|
/**
|
9
|
* Defines a Media browser plugin base class.
|
10
|
*
|
11
|
* MediaBrowserPlugin implementations need to implement at least the
|
12
|
* view() method.
|
13
|
*/
|
14
|
abstract class MediaBrowserPlugin implements MediaBrowserPluginInterface {
|
15
|
/**
|
16
|
* The plugin metadata array from hook_media_browser_plugin_info().
|
17
|
*
|
18
|
* @var array
|
19
|
*/
|
20
|
protected $info;
|
21
|
|
22
|
/**
|
23
|
* The parameters for the current media browser from
|
24
|
* media_get_browser_params().
|
25
|
*
|
26
|
* @var array
|
27
|
*/
|
28
|
protected $params;
|
29
|
|
30
|
/**
|
31
|
* Implements MediaBrowserPluginInterface::__construct().
|
32
|
*/
|
33
|
public function __construct($info, $params) {
|
34
|
$this->info = $info;
|
35
|
$this->params = $params;
|
36
|
}
|
37
|
|
38
|
/**
|
39
|
* Implements MediaBrowserPluginInterface::access().
|
40
|
*/
|
41
|
public function access($account = NULL) {
|
42
|
// Backwards compatible support for 'access callback' definitions.
|
43
|
if (isset($this->info['access callback'])) {
|
44
|
$access_callback = $this->info['access callback'];
|
45
|
$access_arguments = isset($this->info['access arguments']) ? $this->info['access arguments'] : array();
|
46
|
return function_exists($access_callback) && call_user_func_array($access_callback, $access_arguments);
|
47
|
}
|
48
|
|
49
|
return TRUE;
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* Provide a render array to display the plugin in a media browser.
|
54
|
*
|
55
|
* This render array will be a jQuery tab in the media browser.
|
56
|
*
|
57
|
* Some elements are special:
|
58
|
* - #settings: Drupal.settings.media.browser.$key (where key is the array
|
59
|
* key).
|
60
|
* - #callback: If provided, will make the tab an "ajax" tab.
|
61
|
* - #title: If provided, will be used as the tab's title. Otherwise the
|
62
|
* 'title' value from the plugin's hook_media_browser_plugin_info() will
|
63
|
* be used.
|
64
|
* - #weight: If provided, will be used to order the tabs between each other.
|
65
|
* A lower weight will be displayed first while a higher weight will be
|
66
|
* displayed later. If not provided, and there is a 'weight' value in the
|
67
|
* plugin's hook_media_browser_plugin_info() then it will be used,
|
68
|
* otherwise a default of 0 will be used.
|
69
|
* - form: If the plugin is to display a native Drupal form, then the output
|
70
|
* of drupal_get_form should be returned into the 'form' render key. If a
|
71
|
* form's callback isn't normally loaded, module_load_include() should be
|
72
|
* used to ensure that the form can be displayed.
|
73
|
*
|
74
|
* Example usage:
|
75
|
* @code
|
76
|
* module_load_include('inc', 'mymodule', 'mymodule.pages');
|
77
|
* $build['#attached']['js'][] = drupal_get_path('module', 'mymodule') . '/js/mymodule.media.browser.js';
|
78
|
* $build['form'] = drupal_get_form('mymodule_media_form');
|
79
|
* return $build;
|
80
|
* @endcode
|
81
|
*
|
82
|
* @return array
|
83
|
* Renderable array.
|
84
|
*/
|
85
|
abstract public function view();
|
86
|
}
|