Skip to content

Commit 977f4e4

Browse files
committed
Work around for #22, Doesn't appear to work with repeating fields
1 parent 2665e35 commit 977f4e4

File tree

5 files changed

+92
-8
lines changed

5 files changed

+92
-8
lines changed

VideoEmbedFieldtype.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function blank()
3434
'thumbnail_large' => '',
3535
'thumbnail_medium' => '',
3636
'thumbnail_small' => '',
37-
'key' => $data['key'] = $this->getConfig('key', '')
37+
'youtube_key' => $this->getConfig('key', '')
3838
];
3939
}
4040

@@ -48,7 +48,7 @@ public function preProcess($data)
4848
{
4949
// Pass the YouTube API key to Vue & set defaults if data is not set
5050
// - For example if info url was added via editing the yaml file
51-
$data['key'] = $this->getConfig('key', '');
51+
$data['youtube_key'] = $this->getConfig('key', '');
5252
$data['url'] = isset($data['url']) ? $data['url'] : '';
5353
$data['title'] = isset($data['title']) ? $data['title'] : '';
5454
$data['description'] = isset($data['description']) ? $data['description'] : '';
@@ -104,7 +104,7 @@ public function process($data)
104104
}
105105

106106
// Important! Unset the YouTube API key so it is not saved with the content
107-
unset($data['key']);
107+
unset($data['youtube_key']);
108108

109109
// If there is no description unset it (so a blank string is not saved in YAML)
110110
// This way templates can easily just check if the description exists

VideoEmbedServiceProvider.php

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
namespace Statamic\Addons\VideoEmbed;
4+
5+
use Statamic\Extend\ServiceProvider;
6+
use Statamic\Extend\Meta;
7+
8+
class VideoEmbedServiceProvider extends ServiceProvider
9+
{
10+
11+
/**
12+
* Bootstrap the application services.
13+
*
14+
* @return void
15+
*/
16+
public function boot() {
17+
//
18+
}
19+
20+
/**
21+
* Register the application services.
22+
*
23+
* @return void
24+
*/
25+
public function register() {
26+
$this->app->bind('VideoEmbed.resolve-resource-path', function () {
27+
/**
28+
* @param string $path The filename relative to the `resources/assets` directory.
29+
* eg. `js/foo.js`
30+
* @param Addon $addon An instance of Statamic\Extend\Addon for your addon.
31+
* @return string The filename relative to `resources/assets`
32+
* eg. `js/foo.js?id=1234` or `js/foo.somehash.js`
33+
*/
34+
return function ($path, $addon) {
35+
$meta = new Meta($addon);
36+
$version = '';
37+
38+
if ($meta->exists()) {
39+
$meta->load();
40+
$version = $meta->get('version');
41+
}
42+
43+
return $path . '?v=' . $version;
44+
};
45+
});
46+
}
47+
}

meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: VideoEmbed
2-
version: 2.2.5
2+
version: 2.2.6
33
description: A field type for embedding YouTube and Vimeo Videos
44
url: https://github.com/jrc9designstudio/statamic-video-embed
55
developer: JRC9 Design Studio

readme.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Video Embed for Statamic 2
22
*Requirement:* Statamic v2.6.x, curl
3-
*Version:* 2.2.4
3+
*Version:* 2.2.6
44

55
### What is this?
66
Add YouTube and Vimeo videos to Statamic with a Video Embed field.
@@ -120,6 +120,7 @@ If you really want a simple tag that does it all for you, you can create your ow
120120
- `portrait_cinema` 9:21
121121

122122
### Version Log
123+
- 2.2.6 Fix grid / replicator issue
123124
- 2.2.4 Add Video Preview Image to Replicator Preview Text
124125
- 2.2.3 Auto Focus & Change Watcher Fix
125126
- 2.2.2 Add Replicator Preview Text

resources/assets/js/fieldtype.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,37 @@
11
/* global Vue, $, Fieldtype, translate */
22

3+
// Polyfill Object.assign for IE...
4+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/assign#Polyfill
5+
if (typeof Object.assign !== 'function') {
6+
// Must be writable: true, enumerable: false, configurable: true
7+
Object.defineProperty(Object, "assign", {
8+
value: function assign(target, varArgs) { // .length of function is 2
9+
'use strict';
10+
if (target === null || target === undefined) {
11+
throw new TypeError('Cannot convert undefined or null to object');
12+
}
13+
14+
var to = Object(target);
15+
16+
for (var index = 1; index < arguments.length; index++) {
17+
var nextSource = arguments[index];
18+
19+
if (nextSource !== null && nextSource !== undefined) {
20+
for (var nextKey in nextSource) {
21+
// Avoid bugs when hasOwnProperty is shadowed
22+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
23+
to[nextKey] = nextSource[nextKey];
24+
}
25+
}
26+
}
27+
}
28+
return to;
29+
},
30+
writable: true,
31+
configurable: true
32+
});
33+
}
34+
335
Vue.component('video_embed-fieldtype', {
436
mixins: [Fieldtype],
537

@@ -8,9 +40,8 @@ Vue.component('video_embed-fieldtype', {
840
loading: true,
941
fail: false,
1042
previous_url: '',
11-
youTubeKeySet: this.data.key.length > 0,
43+
youTubeKeySet: this.data.youtube_key.length > 0,
1244
ajax: undefined,
13-
autoBindChangeWatcher: false // Disable the automagic binding
1445
}
1546
},
1647

@@ -172,7 +203,7 @@ Vue.component('video_embed-fieldtype', {
172203
}
173204

174205
this.ajax = $.ajax({
175-
url: 'https://www.googleapis.com/youtube/v3/videos?part=id%2C+snippet,contentDetails&id=' + this.getYouTubeID + '&key=' + this.data.key
206+
url: 'https://www.googleapis.com/youtube/v3/videos?part=id%2C+snippet,contentDetails&id=' + this.getYouTubeID + '&key=' + this.data.youtube_key
176207
}).done(function(data) {
177208
if (! data.items[0]) {
178209
that.fail = translate('addons.VideoEmbed::settings.youtube_lookup_no_data');
@@ -233,6 +264,11 @@ Vue.component('video_embed-fieldtype', {
233264
},
234265

235266
ready: function() {
267+
// Make sure the default props is not mutated, a unique copy should be made
268+
// this works around a bug where adding more than one video field in a replicator or grid
269+
// before a save causes all url fields to share data / be linked
270+
// https://github.com/jrc9designstudio/statamic-video-embed/issues/22
271+
this.data = Object.assign({}, this.data);
236272
// Update the data as soon as Vue is ready.
237273
this.getData();
238274
},

0 commit comments

Comments
 (0)