-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathvideo_embed_field.api.php
129 lines (117 loc) · 4.33 KB
/
video_embed_field.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* API Info for video_embed_field module
*/
/**
* @function hook_video_embed_handler_info
* Can be used to add more handlers for video_embed_field
* @return an array of handlers, each handler is an array with the following
* keys:
* 'title' : required, the untranslated title of the provider, to show to the
* admin user.
* 'function' : required, the function used to generate the embed code.
* 'thumbnail_function' : optional, the function used to provide the thumbnail
* for a video.
* 'thumbnail_default : optional, the default thumbnail image to display in case
* thumbnail_function does not exist or has no results.
* 'data_function' : optional, the function to return an array of video data.
* 'form' : required, the function that returns the settings form for your
* provider.
* 'form_validate: optional the function that validates the settings form for
* your provider.
* 'domains' : required, an array of domains to match against, this is used to
* know which provider to use.
* 'defaults' : default values for each setting made configurable in your form
* function.
*
* @see hook_video_embed_handler_info_alter()
* @see below for function definitions
*/
function hook_video_embed_handler_info() {
$handlers = array();
$handlers['ustream'] = array(
'title' => 'UStream',
'function' => 'your_module_handle_ustream',
'thumbnail_function' => 'your_module_handle_ustream_thumbnail',
'thumbnail_default' => backdrop_get_path('module', 'your_module') . '/img/ustream.jpg',
'data_function' => 'your_module_handler_ustream_data',
'form' => 'your_module_handler_ustream_form',
'form_validate' => 'your_module_handler_ustream_form_validate',
'domains' => array(
'ustream.com',
),
'defaults' => array(
'width' => 640,
'height' => 360,
),
);
return $handlers;
}
/**
* Performs alterations on video_embed_field handlers.
*
* @param $info
* Array of information on video handlers exposed by
* hook_video_embed_handler_info() implementations.
*/
function hook_video_embed_handler_info_alter(&$info) {
// Change the thumbnail function for 'ustream' provider.
if (isset($info['ustream'])) {
$info['ustream']['thumbnail_function'] = 'your_module_handle_ustream_thumbnail_alter';
}
}
/**
* Example callbacks for a provider (in this case for ustream).
* Obviously, these functions are only for example purposes.
*/
/**
* Generate the embed code for a video
* @param $url - the video url as entered by the user
* @param $settings - the settings for this provider as defined in the form function,
* defaulting to your provider's defaults
* @return the embed code as a renderable array
*/
function your_module_handle_ustream($url, $settings) {
return array(
//this should be the full embed code for your provider, including each of the settings
'#markup' => '<iframe src="ustream"></iframe>',
);
}
/**
* Retrieve information about the thumbnail for a given url
* @param $url - the url of the video as entered by the user
* @return an array with the keys:
* 'id' => an id for the video which is unique to your provider, used for naming the cached thumbnail file
* 'url' => the url to retrieve the thumbnail from
*/
function your_module_handle_ustream_thumbnail($url) {
return array(
'id' => '12332243242', //generally the id that the provider uses for the video
'url' => 'https://something/thumbnail/something.jpg', //the url of the thumbnail
);
}
/**
* A forms api callback, returns the settings form for the provider
* @param $defaults - default/current values for your provider, the currently saved settings
* with empty values filled with the defaults provided in info hook
* @return a form as defined by forms api
*
* @see https://api.drupal.org/api/drupal/developer!topics!forms_api_reference.html/7
*/
function your_module_handler_ustream_form($defaults) {
$form = array();
$form['width'] = array(
'#type' => 'textfield',
'#title' => t('Player Width'),
'#description' => t('The width of the player in pixels'),
'#default_value' => $defaults['width'],
);
return $form;
}
/**
* Return an array of extra data to be stored with the video, this data will be available for theming
* @return an array
*/
function your_module_handler_ustream_data($url) {
return array();
}