Projet

Général

Profil

Paste
Télécharger (2,75 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / media / includes / MediaBrowserPlugin.inc @ e4215af7

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 current media browser from media_get_browser_params().
24
   *
25
   * @var array
26
   */
27
  protected $params;
28

    
29
  /**
30
   * Implements MediaBrowserPluginInterface::__construct().
31
   */
32
  public function __construct($info, $params) {
33
    $this->info = $info;
34
    $this->params = $params;
35
  }
36

    
37
  /**
38
   * Implements MediaBrowserPluginInterface::access().
39
   */
40
  public function access($account = NULL) {
41
    // Backwards compatible support for 'access callback' definitions.
42
    if (isset($this->info['access callback'])) {
43
      $access_callback = $this->info['access callback'];
44
      $access_arguments = isset($this->info['access arguments']) ? $this->info['access arguments'] : array();
45
      return function_exists($access_callback) && call_user_func_array($access_callback, $access_arguments);
46
    }
47

    
48
    return TRUE;
49
  }
50

    
51
  /**
52
   * Provide a render array to display the plugin in a media browser.
53
   *
54
   * This render array will be a jQuery tab in the media browser.
55
   *
56
   * Some elements are special:
57
   *  - #settings: Drupal.settings.media.browser.$key (where key is the array
58
   *    key).
59
   *  - #callback: If provided, will make the tab an "ajax" tab.
60
   *  - #title: If provided, will be used as the tab's title. Otherwise the
61
   *    'title' value from the plugin's hook_media_browser_plugin_info() will
62
   *    be used.
63
   *  - #weight: If provided, will be used to order the tabs between each other.
64
   *    A lower weight will be displayed first while a higher weight will be
65
   *    displayed later. If not provided, and there is a 'weight' value in the
66
   *    plugin's hook_media_browser_plugin_info() then it will be used,
67
   *    otherwise a default of 0 will be used.
68
   *  - form: If the plugin is to display a native Drupal form, then the output
69
   *    of drupal_get_form should be returned into the 'form' render key. If a
70
   *    form's callback isn't normally loaded, module_load_include() should be
71
   *    used to ensure that the form can be displayed.
72
   *
73
   * Example usage:
74
   * @code
75
   *   module_load_include('inc', 'mymodule', 'mymodule.pages');
76
   *   $build['#attached']['js'][] = drupal_get_path('module', 'mymodule') . '/js/mymodule.media.browser.js';
77
   *   $build['form'] = drupal_get_form('mymodule_media_form');
78
   *   return $build;
79
   * @endcode
80
   *
81
   * @return array
82
   *   Renderable array.
83
   */
84
  abstract public function view();
85

    
86
}