This repository has been archived by the owner on Oct 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
media_mpx.module
193 lines (182 loc) · 6.12 KB
/
media_mpx.module
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
/**
* @file
* Module hooks for the media_mpx module.
*/
use Drupal\Core\Access\AccessResult;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Session\AccountInterface;
use Drupal\Core\Url;
use Drupal\media\MediaInterface;
use Drupal\media_mpx\FormAlter\MediaFormAlter;
use Drupal\media_mpx\Plugin\QueueWorker\ThumbnailDownloader;
/**
* Implements hook_help().
*/
function media_mpx_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'media_mpx.settings':
return [
'#prefix' => '<p>',
'#markup' => t('Setting up mpx for the first time? Make sure you have an mpx username and password. With that username and password, <a href="@create-user">create a user</a>, and then <a href="@create-account">create one or more accounts</a> to import content from.', [
'@create-user' => Url::fromRoute('entity.media_mpx_user.add_form')->toString(),
'@create-account' => Url::fromRoute('entity.media_mpx_account.add_form')->toString(),
]),
'#suffix' => '</p>',
];
}
return NULL;
}
/**
* Implements hook_theme().
*/
function media_mpx_theme() {
return [
'media_mpx_iframe_wrapper' => [
'variables' => [
'attributes' => [],
'meta' => [],
'content' => [],
'entity' => NULL,
'mpx_media' => NULL,
],
],
'media_mpx_iframe' => [
'variables' => [
'url' => '',
'attributes' => [],
],
],
];
}
/**
* Implements hook_queue_info_alter().
*/
function media_mpx_queue_info_alter(&$queues) {
// Alter the queue so we can support recreating jobs if the thumbnail fails
// to download.
$queues['media_entity_thumbnail']['class'] = ThumbnailDownloader::class;
}
/**
* Implements hook_ENTITY_TYPE_access().
*/
function media_mpx_media_access(EntityInterface $entity, $operation, AccountInterface $account) {
if ($entity instanceof MediaInterface && $operation == 'view') {
/** @var \Drupal\media_mpx\Access\MediaAvailableAccess $access */
$access = \Drupal::service('media_mpx.media_available_access');
return $access->view($entity, $account);
}
return AccessResult::neutral();
}
/**
* Implements hook_migration_plugins_alter().
*/
function media_mpx_migration_plugins_alter(array &$migrations) {
// Add mappings for fields stored at mpx_video table.
foreach ($migrations as $migration_id => $migration) {
if ($migration['source']['plugin'] == 'media_mpx_entity_item') {
$migrations[$migration_id]['process']['name'] = [
'plugin' => 'get',
'source' => 'title',
];
$migrations[$migration_id]['process']['field_mpx_released_file_pids'] = [
'plugin' => 'get',
'source' => 'released_file_pids',
];
$migrations[$migration_id]['process']['field_mpx_main_released_file_pid'] = [
'plugin' => 'get',
'source' => 'default_released_file_pid',
];
$migrations[$migration_id]['process']['field_mpx_media_categories'] = [
'plugin' => 'get',
'source' => 'categories',
];
$migrations[$migration_id]['process']['field_mpx_title'] = [
'plugin' => 'get',
'source' => 'title',
];
$migrations[$migration_id]['process']['field_mpx_id'] = [
'plugin' => 'get',
'source' => 'id',
];
$migrations[$migration_id]['process']['field_mpx_guid'] = [
'plugin' => 'get',
'source' => 'guid',
];
$migrations[$migration_id]['process']['field_mpx_description'] = [
'plugin' => 'get',
'source' => 'description',
];
$migrations[$migration_id]['process']['field_mpx_author'] = [
'plugin' => 'get',
'source' => 'author',
];
$migrations[$migration_id]['process']['field_mpx_airdate'] = [
'plugin' => 'get',
'source' => 'airdate',
];
$migrations[$migration_id]['process']['field_mpx_available_date'] = [
'plugin' => 'get',
'source' => 'available_date',
];
$migrations[$migration_id]['process']['field_mpx_expiration_date'] = [
'plugin' => 'get',
'source' => 'expiration_date',
];
$migrations[$migration_id]['process']['field_mpx_keywords'] = [
'plugin' => 'get',
'source' => 'keywords',
];
$migrations[$migration_id]['process']['field_mpx_copyright'] = [
'plugin' => 'get',
'source' => 'copyright',
];
$migrations[$migration_id]['process']['field_mpx_related_link'] = [
'plugin' => 'get',
'source' => 'related_link',
];
$migrations[$migration_id]['process']['field_mpx_fab_rating'] = [
'plugin' => 'get',
'source' => 'fab_rating',
];
$migrations[$migration_id]['process']['field_mpx_fab_subratings'] = [
'plugin' => 'get',
'source' => 'fab_sub_ratings',
];
$migrations[$migration_id]['process']['field_mpx_mpaa_rating'] = [
'plugin' => 'get',
'source' => 'mpaa_rating',
];
$migrations[$migration_id]['process']['field_mpx_mpaa_subratings'] = [
'plugin' => 'get',
'source' => 'mpaa_sub_ratings',
];
$migrations[$migration_id]['process']['field_mpx_vchip_rating'] = [
'plugin' => 'get',
'source' => 'vchip_rating',
];
$migrations[$migration_id]['process']['field_mpx_vchip_subratings'] = [
'plugin' => 'get',
'source' => 'vchip_sub_ratings',
];
$migrations[$migration_id]['process']['field_mpx_exclude_countries'] = [
'plugin' => 'get',
'source' => 'exclude_countries',
];
$migrations[$migration_id]['process']['field_mpx_countries'] = [
'plugin' => 'get',
'source' => 'countries',
];
}
}
}
/**
* Implements hook_form_FORM_ID_alter().
*/
function media_mpx_form_media_form_alter(&$form, $form_state, $form_id) {
$update_service = \Drupal::service('media_mpx.service.update_video_item');
$logger = \Drupal::service('media_mpx.exception_logger');
$media_form_alter = new MediaFormAlter($update_service, $logger);
$media_form_alter->alter($form, $form_state, $form_id);
}