1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @file |
5
|
|
|
* Contains df_tools_media.module. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
use Drupal\Core\Form\FormStateInterface; |
9
|
|
|
use Drupal\views\ViewEntityInterface; |
10
|
|
|
use Drupal\Core\Template\Attribute; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Implements hook_migration_plugins_alter(). |
14
|
|
|
*/ |
15
|
|
|
function df_tools_media_migration_plugins_alter(&$definitions) { |
16
|
|
|
$id = 'import_media_image'; |
17
|
|
|
$definitions[$id]['source']['path'] = str_replace('..', dirname(__FILE__), $definitions[$id]['source']['path']); |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Implements hook_form_FORM_ID_alter(). |
22
|
|
|
*/ |
23
|
|
|
function df_tools_media_form_entity_browser_media_browser_in_modal_form_alter(array &$form, FormStateInterface $form_state) { |
|
|
|
|
24
|
|
|
$form['#attached']['library'][] = 'lightning_media/browser.styling'; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Implements hook_ENTITY_TYPE_insert(). |
29
|
|
|
*/ |
30
|
|
|
function df_tools_media_views_insert(ViewEntityInterface $view) { |
31
|
|
|
if (\Drupal::isConfigSyncing()) { |
32
|
|
|
return; |
33
|
|
|
} |
34
|
|
|
elseif (drupal_installation_attempted() && $view->id() == 'media') { |
35
|
|
|
$display1 = &$view->getDisplay('entity_browser_1'); |
36
|
|
|
$display2 = &$view->getDisplay('entity_browser_2'); |
37
|
|
|
$display1['display_options']['filters']['field_tags_target_id'] = $display2['display_options']['filters']['field_tags_target_id'] = [ |
38
|
|
|
'id' => 'field_tags_target_id', |
39
|
|
|
'table' => 'media__field_tags', |
40
|
|
|
'field' => 'field_tags_target_id', |
41
|
|
|
'relationship' => 'none', |
42
|
|
|
'group_type' => 'group', |
43
|
|
|
'admin_label' => '', |
44
|
|
|
'operator' => 'or', |
45
|
|
|
'value' => [], |
46
|
|
|
'group' => 1, |
47
|
|
|
'exposed' => true, |
48
|
|
|
'expose' => [ |
49
|
|
|
'operator_id' => 'field_tags_target_id_op', |
50
|
|
|
'label' => 'Tags', |
51
|
|
|
'description' => '', |
52
|
|
|
'use_operator' => false, |
53
|
|
|
'operator' => 'field_tags_target_id_op', |
54
|
|
|
'identifier' => 'field_tags_target_id', |
55
|
|
|
'required' => false, |
56
|
|
|
'remember' => false, |
57
|
|
|
'multiple' => false, |
58
|
|
|
'remember_roles' => [ |
59
|
|
|
'authenticated' => 'authenticated', |
60
|
|
|
'anonymous' => '0', |
61
|
|
|
'administrator' => '0', |
62
|
|
|
'layout_manager' => '0', |
63
|
|
|
'creator' => '0', |
64
|
|
|
'reviewer' => '0', |
65
|
|
|
'media_creator' => '0', |
66
|
|
|
'media_manager' => '0', |
67
|
|
|
], |
68
|
|
|
'reduce' => false, |
69
|
|
|
], |
70
|
|
|
'is_grouped' => false, |
71
|
|
|
'group_info' => [ |
72
|
|
|
'label' => '', |
73
|
|
|
'description' => '', |
74
|
|
|
'identifier' => '', |
75
|
|
|
'optional' => true, |
76
|
|
|
'widget' => 'select', |
77
|
|
|
'multiple' => false, |
78
|
|
|
'remember' => false, |
79
|
|
|
'default_group' => 'All', |
80
|
|
|
'default_group_multiple' => [], |
81
|
|
|
'group_items' => [], |
82
|
|
|
], |
83
|
|
|
'reduce_duplicates' => false, |
84
|
|
|
'type' => 'textfield', |
85
|
|
|
'limit' => true, |
86
|
|
|
'vid' => 'media_tags', |
87
|
|
|
'hierarchy' => false, |
88
|
|
|
'error_message' => true, |
89
|
|
|
'plugin_id' => 'taxonomy_index_tid', |
90
|
|
|
]; |
91
|
|
|
$view->save(); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Implements hook_theme(). |
97
|
|
|
*/ |
98
|
|
|
function df_tools_media_theme() { |
99
|
|
|
return [ |
100
|
|
|
'media_video_file_formatter__df_tools_media' => [ |
101
|
|
|
'base hook' => 'media_video_file_formatter', |
102
|
|
|
], |
103
|
|
|
]; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Implements hook_theme_suggestions_HOOK_alter() for media_video_file_formatter. |
108
|
|
|
*/ |
109
|
|
|
function df_tools_media_theme_suggestions_media_video_file_formatter_alter(array &$suggestions, array $variables, $hook) { |
|
|
|
|
110
|
|
|
$suggestions[] = 'media_video_file_formatter__df_tools_media_video'; |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Implements template_preprocess_HOOK() for media_video_file_formatter. |
115
|
|
|
*/ |
116
|
|
|
function df_tools_media_preprocess_media_video_file_formatter__df_tools_media_video(&$variables) { |
117
|
|
|
// By default, 'extravalue' contains a string. If the HMTL5 video formatter |
118
|
|
|
// has some attributes with values, special chars (like double comma) will be |
119
|
|
|
// escaped. |
120
|
|
|
// To fix this, we replace 'extravalue' with a properly set Twig Attribute |
121
|
|
|
// object and properly update the 'attribute' array as well. |
122
|
|
|
$attribute = new Attribute(); |
123
|
|
|
if (!empty($variables['extravalue'])) { |
124
|
|
|
$attributes_raw = explode(' ', trim($variables['extravalue'])); |
125
|
|
|
|
126
|
|
|
foreach ($attributes_raw as $attribute_raw) { |
127
|
|
|
if (($delimiter_pos = strpos($attribute_raw, '=')) !== FALSE) { |
128
|
|
|
$key = substr($attribute_raw, 0, $delimiter_pos); |
129
|
|
|
$value = trim(substr($attribute_raw, ($delimiter_pos + 1)), " \"\t\n\r\0\x0B"); |
130
|
|
|
|
131
|
|
|
if (!in_array($value, ['true', 'TRUE'])) { |
132
|
|
|
$variables['attributes'][$key] = $value; |
133
|
|
|
$attribute->setAttribute($key, $value); |
134
|
|
|
continue; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$variables['attributes'][$attribute_raw] = TRUE; |
139
|
|
|
$attribute->setAttribute($attribute_raw, TRUE); |
|
|
|
|
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
$variables['extravalue'] = $attribute; |
144
|
|
|
} |
145
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.