-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathableplayer_extend.module
More file actions
executable file
·112 lines (95 loc) · 4.54 KB
/
ableplayer_extend.module
File metadata and controls
executable file
·112 lines (95 loc) · 4.54 KB
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
<?php
/**
* @file
* Contains ableplayer_extend.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
/**
* Implements hook_help().
*/
function ableplayer_extend_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the ableplayer_extend module.
case 'help.page.ableplayer_extend':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Ableplayer Extend') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_field_formatter_third_party_settings_form().
* Provides additional two config options for Ableplayer
*/
function ableplayer_extend_field_formatter_third_party_settings_form($plugin, $field_definition, $view_mode, $form, $form_state) {
$element = [];
// Add a 'my_setting' checkbox to the settings form for 'foo_formatter' field
// formatters.
if ($plugin->getPluginId() == 'ableplayer_audio') {
$element['display_ableplayer_transcript_audio'] = [
'#type' => 'checkbox',
'#title' => t('Display Transcript Container by Default'),
'#default_value' => $plugin->getThirdPartySetting('ableplayer_extend', 'display_ableplayer_transcript_audio'),
];
$element['show_timestamp_audio'] = [
'#type' => 'checkbox',
'#title' => t('Display Cue Timestamp'),
'#default_value' => $plugin->getThirdPartySetting('ableplayer_extend', 'show_timestamp_audio'),
];
}
if ($plugin->getPluginId() == 'ableplayer_video') {
$element['display_ableplayer_transcript_video'] = [
'#type' => 'checkbox',
'#title' => t('Display Transcript Container by Default'),
'#default_value' => $plugin->getThirdPartySetting('ableplayer_extend', 'display_ableplayer_transcript_video'),
];
$element['show_timestamp_video'] = [
'#type' => 'checkbox',
'#title' => t('Display Cue Timestamp'),
'#default_value' => $plugin->getThirdPartySetting('ableplayer_extend', 'show_timestamp_video'),
];
}
return $element;
}
/**
* Implements hook_preprocess_field().
* Setups the javascript to enable Ableplayer related functions
*/
function ableplayer_extend_preprocess_field(&$variables) {
// Provide an extra variable to the field template when the field uses
// a formatter of type 'foo_formatter'.
if ($variables['element']['#formatter'] == 'ableplayer_audio') {
$entity = $variables['element']['#object'];
$view_mode = $variables['element']['#view_mode'];
$field_name = $variables['element']['#field_name'];
// Get the field formatter settings...
$entity_display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
$field_display = $entity_display->getComponent($field_name);
// Make the setting available in the field template.
if (isset($field_display['third_party_settings']['ableplayer_extend'])) {
$display_ableplayer_transcript_audio = $field_display['third_party_settings']['ableplayer_extend']['display_ableplayer_transcript_audio'];
$show_timestamp_audio = $field_display['third_party_settings']['ableplayer_extend']['show_timestamp_audio'];
$variables['#attached']['drupalSettings']['display_ableplayer_transcript'] = $display_ableplayer_transcript_audio;
$variables['#attached']['drupalSettings']['show_timestamp'] = $show_timestamp_audio;
}
$variables['#attached']['library'][] = 'ableplayer_extend/ableplayer_extend.transcript_position';
}
if ($variables['element']['#formatter'] == 'ableplayer_video') {
$entity = $variables['element']['#object'];
$view_mode = $variables['element']['#view_mode'];
$field_name = $variables['element']['#field_name'];
// Get the field formatter settings...
$entity_display = EntityViewDisplay::collectRenderDisplay($entity, $view_mode);
$field_display = $entity_display->getComponent($field_name);
// Make the setting available in the field template.
if (isset($field_display['third_party_settings']['ableplayer_extend'])) {
$display_ableplayer_transcript_video = $field_display['third_party_settings']['ableplayer_extend']['display_ableplayer_transcript_video'];
$show_timestamp_video = $field_display['third_party_settings']['ableplayer_extend']['show_timestamp_video'];
$variables['#attached']['drupalSettings']['display_ableplayer_transcript'] = $display_ableplayer_transcript_video;
$variables['#attached']['drupalSettings']['show_timestamp'] = $show_timestamp_video;
}
$variables['#attached']['library'][] = 'ableplayer_extend/ableplayer_extend.transcript_position';
}
}