Skip to content

Commit 919484b

Browse files
committed
Add Brightcove module and its dependencies
This includes modules only, not the relevant library. https://github.com/18F/nsf/issues/78
1 parent 3964a00 commit 919484b

File tree

201 files changed

+21607
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+21607
-0
lines changed

modules/brightcove/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

modules/brightcove/LICENSE.txt

+339
Large diffs are not rendered by default.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: Brightcove
2+
type: module
3+
description: Brightcove Video Connect
4+
# core: 8.x
5+
package: Brightcove
6+
configure: entity.brightcove_api_client.collection
7+
dependencies:
8+
- datetime
9+
- image
10+
- inline_entity_form
11+
- link
12+
- options
13+
- path
14+
- time_formatter
15+
- taxonomy
16+
- token
17+
- views
18+
19+
# Information added by Drupal.org packaging script on 2017-03-24
20+
version: '8.x-1.2'
21+
core: '8.x'
22+
project: 'brightcove'
23+
datestamp: 1490367795

modules/brightcove/brightcove.install

+173
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
<?php
2+
/**
3+
* @file
4+
* Brightcove install file.
5+
*/
6+
use Drupal\brightcove\Entity\BrightcoveAPIClient;
7+
use Drupal\brightcove\Entity\BrightcoveSubscription;
8+
use Drupal\Core\Field\BaseFieldDefinition;
9+
use Drupal\Core\Url;
10+
11+
/**
12+
* Implements hook_requirements().
13+
*/
14+
function brightcove_requirements($phase) {
15+
$requirements = [];
16+
17+
$requirements['brightcove'] = [
18+
'title' => 'Brightcove API',
19+
];
20+
21+
// Check for API availability.
22+
if (!class_exists('Brightcove\API\API')) {
23+
$requirements['brightcove'] += [
24+
'description' => t('Missing Brightcove API from the vendor folder.'),
25+
'severity' => REQUIREMENT_ERROR,
26+
];
27+
}
28+
29+
// If everything passes show that the Brightcove API is installed
30+
// successfully.
31+
if (!isset($requirements['severity']) || $requirements['severity'] == REQUIREMENT_OK) {
32+
$requirements['brightcove'] += [
33+
'description' => t('Installed'),
34+
'severity' => REQUIREMENT_OK,
35+
];
36+
}
37+
38+
return $requirements;
39+
}
40+
41+
/**
42+
* Copy values from brightcove_callback table to a expirable key value store.
43+
*/
44+
function brightcove_update_8100(&$sandbox) {
45+
// Get database connection.
46+
$database = \Drupal::database();
47+
48+
if (!isset($sandbox['progress'])) {
49+
$sandbox['progress'] = 0;
50+
$sandbox['max'] = $database->select('brightcove_callback', 'bc')
51+
->fields('bc', ['id'])
52+
->countQuery()
53+
->execute()
54+
->fetchField();
55+
}
56+
57+
$key_value_expirable = \Drupal::keyValueExpirable('brightcove_callback');
58+
$entries = $database->select('brightcove_callback')
59+
->fields('brightcove_callback')
60+
->orderBy('id', 'ASC')
61+
->range($sandbox['progress'], 50)
62+
->execute()
63+
->fetchAll();
64+
foreach ($entries as $entry) {
65+
$sandbox['progress']++;
66+
67+
if (REQUEST_TIME < $entry->expires) {
68+
$key_value_expirable->setWithExpire($entry->token, $entry->video_id, $entry->expires - REQUEST_TIME);
69+
}
70+
}
71+
72+
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : ($sandbox['progress'] / $sandbox['max']);
73+
}
74+
75+
/**
76+
* Drop brightcove_callback table.
77+
*/
78+
function brightcove_update_8101() {
79+
\Drupal::database()
80+
->schema()
81+
->dropTable('brightcove_callback');
82+
}
83+
84+
/**
85+
* Update BrightcoveAPIClient config entity's schema.
86+
*/
87+
function brightcove_update_8102() {
88+
$config_factory = \Drupal::configFactory();
89+
foreach ($config_factory->listAll('brightcove.brightcove_api_client.') as $brightcove_api_client_config) {
90+
$config = $config_factory->getEditable($brightcove_api_client_config);
91+
$config->clear('access_token');
92+
$config->clear('access_token_expire_date');
93+
$config->save(TRUE);
94+
}
95+
drupal_flush_all_caches();
96+
}
97+
98+
/**
99+
* Sets a default callback for the reference_id.
100+
*/
101+
function brightcove_update_8103() {
102+
/** @var \Drupal\Core\Field\BaseFieldDefinition $installed_field_definition */
103+
$installed_field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('reference_id', 'brightcove_video');
104+
$installed_field_definition->setDefaultValueCallback('\Drupal\brightcove\Entity\BrightcoveVideo::getDefaultReferenceId');
105+
\Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition($installed_field_definition);
106+
107+
/** @var \Drupal\Core\Field\BaseFieldDefinition $installed_field_definition */
108+
$installed_field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('reference_id', 'brightcove_playlist');
109+
$installed_field_definition->setDefaultValueCallback('\Drupal\brightcove\Entity\BrightcovePlaylist::getDefaultReferenceId');
110+
\Drupal::entityDefinitionUpdateManager()->updateFieldStorageDefinition($installed_field_definition);
111+
}
112+
113+
/**
114+
* Updates the entity with the video_url base field.
115+
*/
116+
function brightcove_update_8104() {
117+
$storage_definition = BaseFieldDefinition::create('uri')
118+
->setLabel(t('Video source URL'))
119+
->setDisplayOptions('form', [
120+
'type' => 'uri',
121+
])
122+
->setDisplayOptions('view', [
123+
'type' => 'uri_link',
124+
'label' => 'inline',
125+
'settings' => [
126+
'trim_length' => 150,
127+
'target' => '_blank',
128+
],
129+
])
130+
->setDisplayConfigurable('form', TRUE)
131+
->setDisplayConfigurable('view', TRUE);
132+
133+
\Drupal::entityDefinitionUpdateManager()
134+
->installFieldStorageDefinition('video_url', 'brightcove_video', 'brightcove_video', $storage_definition);
135+
}
136+
137+
138+
/**
139+
* Update entity definitions.
140+
*/
141+
function brightcove_update_8105() {
142+
\Drupal::entityDefinitionUpdateManager()->applyUpdates();
143+
}
144+
145+
/**
146+
* Create default subscription for each available client.
147+
*/
148+
function brightcove_update_8106() {
149+
/** @var BrightcoveAPIClient[] $clients */
150+
$clients = BrightcoveAPIClient::loadMultiple();
151+
$messages = [];
152+
foreach ($clients as $client) {
153+
// Create new default subscription if not exist yet.
154+
$id = "default_{$client->id()}";
155+
$subscription = BrightcoveSubscription::load($id);
156+
157+
if (empty($subscription)) {
158+
BrightcoveSubscription::create([
159+
'id' => $id,
160+
'status' => FALSE,
161+
'default' => TRUE,
162+
'api_client_id' => $client->id(),
163+
'endpoint' => Url::fromRoute('brightcove_notification_callback', [], ['absolute' => TRUE])->toString(),
164+
'events' => ['video-change'],
165+
])->save(FALSE);
166+
}
167+
else {
168+
$messages[] = t('Default subscription for "@client" client already exist, skipping...', ['@client' => $client->label()]) . PHP_EOL;
169+
}
170+
}
171+
172+
return implode(PHP_EOL, $messages);
173+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
brightcove.video:
2+
version: 1.0
3+
css:
4+
theme:
5+
css/video.css: {}
6+
js:
7+
js/video.js: {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
entity.brightcove_api_client.add_form:
2+
route_name: 'entity.brightcove_api_client.add_form'
3+
title: 'Add Brightcove API Client'
4+
appears_on:
5+
- entity.brightcove_api_client.collection
6+
7+
entity.brightcove_video.add_form:
8+
route_name: entity.brightcove_video.add_form
9+
title: 'Add Brightcove Video'
10+
appears_on:
11+
- entity.brightcove_video.collection
12+
13+
entity.brightcove_playlist.add_form:
14+
route_name: entity.brightcove_playlist.add_form
15+
title: 'Add Brightcove Playlist'
16+
appears_on:
17+
- entity.brightcove_playlist.collection
18+
19+
entity.brightcove_subscription.add_form:
20+
route_name: entity.brightcove_subscription.add_form
21+
title: 'Add subscription'
22+
appears_on:
23+
- entity.brightcove_subscription.collection
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# Brightcove API Client menu items definition.
2+
entity.brightcove_api_client.collection:
3+
title: 'Brightcove API Client'
4+
route_name: entity.brightcove_api_client.collection
5+
description: 'Configure Brightcove API Clients (credentials).'
6+
parent: system.admin_config_media
7+
weight: 99
8+
9+
# Brightcove Video menu items definition.
10+
entity.brightcove_video.collection:
11+
title: 'Brightcove Videos'
12+
route_name: entity.brightcove_video.collection
13+
description: 'List Brightcove Videos.'
14+
parent: system.admin_content
15+
weight: 100
16+
17+
brightcove_video.settings:
18+
title: Brightcove Video settings
19+
description: 'Configure Brightcove Videos.'
20+
route_name: brightcove_video.settings
21+
parent: system.admin_structure
22+
weight: 100
23+
24+
# Brightcove Playlist menu items definition.
25+
entity.brightcove_playlist.collection:
26+
title: 'Brightcove Playlists'
27+
route_name: entity.brightcove_playlist.collection
28+
description: 'List Brightcove Playlists.'
29+
parent: system.admin_content
30+
weight: 102
31+
32+
brightcove_playlist.settings:
33+
title: 'Brightcove Playlist settings'
34+
description: 'Configure Brightcove Playlists.'
35+
route_name: brightcove_playlist.settings
36+
parent: system.admin_structure
37+
weight: 102
38+
39+
# Brightcove Status Overview menu item definition.
40+
brightcove_status_overview:
41+
title: 'Brightcove Status Overview'
42+
route_name: brightcove_status_overview
43+
description: 'List all Brightcove entities and queues with the number of items in them.'
44+
parent: system.admin_reports
45+
46+
# Brightcove Subscriptions
47+
entity.brightcove_subscription.collection:
48+
title: 'Brightcove Subscriptions'
49+
description: 'Manage Brightcove subscriptions.'
50+
route_name: entity.brightcove_subscription.collection
51+
parent: system.admin_config_system
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Brightcove Video routing definition
2+
brightcove_video.settings_tab:
3+
route_name: brightcove_video.settings
4+
title: 'Settings'
5+
base_route: brightcove_video.settings
6+
7+
entity.brightcove_video.canonical:
8+
route_name: entity.brightcove_video.canonical
9+
base_route: entity.brightcove_video.canonical
10+
title: 'View'
11+
12+
entity.brightcove_video.edit_form:
13+
route_name: entity.brightcove_video.edit_form
14+
base_route: entity.brightcove_video.canonical
15+
title: Edit
16+
17+
entity.brightcove_video.delete_form:
18+
route_name: entity.brightcove_video.delete_form
19+
base_route: entity.brightcove_video.canonical
20+
title: Delete
21+
weight: 10
22+
23+
entity.brightcove_video.collection:
24+
title: 'Brightcove Videos'
25+
route_name: entity.brightcove_video.collection
26+
base_route: system.admin_content
27+
28+
# Brightcove Text Track routing definition.
29+
entity.brightcove_text_track.canonical:
30+
route_name: entity.brightcove_text_track.canonical
31+
base_route: entity.brightcove_text_track.canonical
32+
title: 'View'
33+
34+
entity.brightcove_text_track.delete_form:
35+
route_name: entity.brightcove_text_track.delete_form
36+
base_route: entity.brightcove_text_track.canonical
37+
title: Delete
38+
weight: 10
39+
40+
# Brightcove Playlist routing definition
41+
brightcove_playlist.settings_tab:
42+
route_name: brightcove_playlist.settings
43+
title: 'Settings'
44+
base_route: brightcove_playlist.settings
45+
46+
entity.brightcove_playlist.canonical:
47+
route_name: entity.brightcove_playlist.canonical
48+
base_route: entity.brightcove_playlist.canonical
49+
title: 'View'
50+
51+
entity.brightcove_playlist.edit_form:
52+
route_name: entity.brightcove_playlist.edit_form
53+
base_route: entity.brightcove_playlist.canonical
54+
title: Edit
55+
56+
entity.brightcove_playlist.delete_form:
57+
route_name: entity.brightcove_playlist.delete_form
58+
base_route: entity.brightcove_playlist.canonical
59+
title: Delete
60+
weight: 10
61+
62+
entity.brightcove_playlist.collection:
63+
title: 'Brightcove Playlists'
64+
route_name: entity.brightcove_playlist.collection
65+
base_route: system.admin_content

0 commit comments

Comments
 (0)