-
Notifications
You must be signed in to change notification settings - Fork 0
/
media_entity_ustudio.module
102 lines (93 loc) · 3.06 KB
/
media_entity_ustudio.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
<?php
/**
* @file
* Contains media_entity_ustudio.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Drupal\Core\Entity\EntityTypeInterface;
use Drupal\Core\Field\BaseFieldDefinition;
use Drupal\Core\Form\FormStateInterface;
/**
* Implements hook_help().
*/
function media_entity_ustudio_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the media_entity_ustudio module.
case 'help.page.media_entity_ustudio':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('Provides Ustudio Media Entity') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function media_entity_ustudio_theme() {
return [
'media_entity_ustudio' => [
'variables' => [
'embed' => NULL,
'destination' => NULL,
'video' => NULL,
],
],
];
}
/**
* Implements hooK_form_FORM_ID_alter().
*/
function media_entity_ustudio_form_media_ustudio_add_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
// media_entity_ustudio_alter_media_form($form, $form_state);
}
function media_entity_ustudio_form_media_ustudio_edit_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
// media_entity_ustudio_alter_media_form($form, $form_state);
}
/**
* Implements hook_form_BASE_FORM_ID_alter()
*/
function media_entity_ustudio_alter_media_form(&$form, \Drupal\Core\Form\FormStateInterface $form_state) {
$media = $form_state->getFormObject()->getEntity();
$form['ustudio_upload_settings'] = [
'#type' => 'details',
'#title' => t('uStudio Upload settings'),
'#group' => 'advanced',
'#access' => !empty($form['ustudio_upload']['#access']) && $media->hasField('ustudio_upload') && $media->get('ustudio_upload')->access('edit'),
'#attributes' => [
'class' => ['ustudio-upload-form'],
],
'#weight' => 30,
];
$fetcher = \Drupal::service('media_entity_ustudio.fetcher');
$config = \Drupal::config('media_entity_ustudio.settings');
$access_token = $config->get('access_token');
$studio = $config->get('studio');
$destinations = $fetcher->retrieveDestinations($access_token, $studio);
$form['ustudio_upload_settings']['destination'] = [
'#type' => 'select',
'#title' => t('Destination'),
'#options' => $destinations,
'#size' => 1,
'#required' => TRUE,
'#empty_value' => "",
];
$form['ustudio_upload']['#group'] = 'usudio_upload_settings';
}
/**
* Implements hook_entity_bundle_field_info().
*/
function media_entity_ustudio_entity_bundle_field_info(EntityTypeInterface $entity_type, $bundle, array $base_field_definitions) {
if ($entity_type->id() == 'media' && $bundle == 'ustudio') {
$fields['ustudio_upload'] = BaseFieldDefinition::create('ustudio_upload')
->setLabel(t('uStudio Upload'))
->setTranslatable(FALSE)
->setDisplayOptions('form', [
'type' => 'ustudio_upload',
'weight' => 30,
])
->setDisplayConfigurable('form', TRUE)
->setComputed(FALSE);
return $fields;
}
}