diff --git a/degov_media_tweet/templates/media--tweet--default.html.twig b/degov_media_tweet/templates/media--tweet--default.html.twig
index bb692fa4..76d93f28 100644
--- a/degov_media_tweet/templates/media--tweet--default.html.twig
+++ b/degov_media_tweet/templates/media--tweet--default.html.twig
@@ -14,7 +14,12 @@
#}
{% if content.embed_code|field_value %}
- {{ content.embed_code }}
+ {% if social_media_disabled %}
+
+
+ {% else %}
+ {{ content.embed_code }}
+ {% endif %}
{% endif %}
{% if content.field_tags|field_value %}
{{ content.field_tags }}
diff --git a/degov_media_tweet/templates/media--tweet--embedded.html.twig b/degov_media_tweet/templates/media--tweet--embedded.html.twig
index 3681826b..2056e095 100644
--- a/degov_media_tweet/templates/media--tweet--embedded.html.twig
+++ b/degov_media_tweet/templates/media--tweet--embedded.html.twig
@@ -15,7 +15,12 @@
{% if content %}
{% if content.embed_code|field_value %}
- {{ content.embed_code }}
+ {% if social_media_disabled %}
+
+
+ {% else %}
+ {{ content.embed_code }}
+ {% endif %}
{% endif %}
{% if content.field_tags|field_value %}
{{ content.field_tags }}
diff --git a/degov_media_tweet/templates/media--tweet--preview.html.twig b/degov_media_tweet/templates/media--tweet--preview.html.twig
index 3681826b..2056e095 100644
--- a/degov_media_tweet/templates/media--tweet--preview.html.twig
+++ b/degov_media_tweet/templates/media--tweet--preview.html.twig
@@ -15,7 +15,12 @@
{% if content %}
{% if content.embed_code|field_value %}
- {{ content.embed_code }}
+ {% if social_media_disabled %}
+
+
+ {% else %}
+ {{ content.embed_code }}
+ {% endif %}
{% endif %}
{% if content.field_tags|field_value %}
{{ content.field_tags }}
diff --git a/degov_media_tweet/templates/media--tweet--search.html.twig b/degov_media_tweet/templates/media--tweet--search.html.twig
index 3681826b..2056e095 100644
--- a/degov_media_tweet/templates/media--tweet--search.html.twig
+++ b/degov_media_tweet/templates/media--tweet--search.html.twig
@@ -15,7 +15,12 @@
{% if content %}
{% if content.embed_code|field_value %}
- {{ content.embed_code }}
+ {% if social_media_disabled %}
+
+
+ {% else %}
+ {{ content.embed_code }}
+ {% endif %}
{% endif %}
{% if content.field_tags|field_value %}
{{ content.field_tags }}
diff --git a/degov_media_tweet/templates/media--tweet--usage.html.twig b/degov_media_tweet/templates/media--tweet--usage.html.twig
index 54294bd6..b4e8ca9a 100644
--- a/degov_media_tweet/templates/media--tweet--usage.html.twig
+++ b/degov_media_tweet/templates/media--tweet--usage.html.twig
@@ -14,7 +14,12 @@
#}
{% if contentembed_code|field_value %}
- {{ content.embed_code }}
+ {% if social_media_disabled %}
+
+
+ {% else %}
+ {{ content.embed_code }}
+ {% endif %}
{% endif %}
{% if content.field_tags|field_value %}
{{ content.field_tags }}
diff --git a/degov_social_media_settings/config/install/degov_social_media_settings.default.yml b/degov_social_media_settings/config/install/degov_social_media_settings.default.yml
index b1979ece..cf77f8f7 100644
--- a/degov_social_media_settings/config/install/degov_social_media_settings.default.yml
+++ b/degov_social_media_settings/config/install/degov_social_media_settings.default.yml
@@ -6,4 +6,5 @@ sources:
pinterest: 'Pinterest'
flickr: 'Flickr'
vimeo: 'Vimeo'
+ instagram: 'Instagram'
other: 'Andere'
diff --git a/degov_social_media_settings/config/update_8004/install/degov_social_media_settings.default.yml b/degov_social_media_settings/config/update_8004/install/degov_social_media_settings.default.yml
new file mode 100644
index 00000000..cf77f8f7
--- /dev/null
+++ b/degov_social_media_settings/config/update_8004/install/degov_social_media_settings.default.yml
@@ -0,0 +1,10 @@
+sources:
+ facebook: 'Facebook'
+ twitter: 'Twitter'
+ youtube: 'Youtube'
+ googleplus: 'Google+'
+ pinterest: 'Pinterest'
+ flickr: 'Flickr'
+ vimeo: 'Vimeo'
+ instagram: 'Instagram'
+ other: 'Andere'
diff --git a/degov_social_media_settings/degov_social_media_settings.install b/degov_social_media_settings/degov_social_media_settings.install
index 688b408d..881d5618 100644
--- a/degov_social_media_settings/degov_social_media_settings.install
+++ b/degov_social_media_settings/degov_social_media_settings.install
@@ -7,3 +7,11 @@
* and every minor release as well until 1.13 respectively.
* The fresh install should have all the changes from 1.1 to 1.13.
*/
+
+/**
+ * Add social media source Instagram.
+ */
+function degov_social_media_settings_update_8004() {
+ \Drupal::service('degov_config.module_updater')
+ ->applyUpdates('degov_social_media_settings', '8004');
+}
diff --git a/degov_social_media_settings/degov_social_media_settings.module b/degov_social_media_settings/degov_social_media_settings.module
index cd56792e..6d76c45e 100644
--- a/degov_social_media_settings/degov_social_media_settings.module
+++ b/degov_social_media_settings/degov_social_media_settings.module
@@ -110,7 +110,7 @@ function degov_social_media_settings_preprocess_media(&$variables) {
// - a field formatter or
// - a preprocess function for the fields and a hook that informs this
// module about fields that need to be disabled
- if ($media instanceof MediaInterface && in_array($bundle, ['some_embed', 'video'])) {
+ if ($media instanceof MediaInterface && in_array($bundle, ['some_embed', 'video', 'tweet', 'instagram'])) {
switch ($bundle) {
case 'some_embed':
// Maybe make sure this runs after degov_media_social_media_embed_preprocess_media__some_embed
@@ -120,17 +120,28 @@ function degov_social_media_settings_preprocess_media(&$variables) {
$allowed_tags = degov_media_social_media_embed_allowed_tags();
$markup = Xss::filter($field_value, $allowed_tags);
}
+ $source = $media->field_social_media_source->value;
break;
case 'video':
$field_value = \Drupal::service('twig_field_value.twig.extension')->getFieldValue($variables['content']['field_media_video_embed_field']);
$markup = \Drupal::service('renderer')->render($field_value);
+ $source = $media->field_social_media_source->value;
+ break;
+ case 'tweet':
+ case 'instagram':
+ // Detach module libraries because they load js from twitter/instagram.
+ unset($variables['content']['embed_code']['#attached']);
+ $field_value = \Drupal::service('twig_field_value.twig.extension')
+ ->getFieldValue($variables['content']['embed_code']);
+ $markup = \Drupal::service('renderer')->render($field_value);
+ $source = $bundle === 'tweet' ? 'twitter' : 'instagram';
break;
}
if (!empty($markup)) {
$variables['#attached']['drupalSettings']['degov_social_media_settings']['code'][$entity_id] = $markup;
$variables['attributes']['class'][] = 'js-social-media-wrapper';
- $variables['attributes']['data-social-media-source'] = $media->field_social_media_source->value;
+ $variables['attributes']['data-social-media-source'] = $source;
$variables['attributes']['data-social-media-entity'] = $entity_id;
$variables['social_media_disabled'] = TRUE;
}
diff --git a/degov_social_media_settings/js/process.js b/degov_social_media_settings/js/process.js
index 2a4cf8cf..56748e58 100644
--- a/degov_social_media_settings/js/process.js
+++ b/degov_social_media_settings/js/process.js
@@ -84,6 +84,14 @@
// Show the code if source is enabled.
if (sources.hasOwnProperty(source) && sources[source] === true && code.hasOwnProperty(entity)) {
target.html(code[entity]);
+
+ if (source === 'twitter') {
+ initTwitter(wrapper);
+ }
+
+ if (source === 'instagram') {
+ initInstagram();
+ }
}
else {
if (Drupal.eu_cookie_compliance !== undefined && Drupal.eu_cookie_compliance.hasAgreed()) {
@@ -145,6 +153,34 @@
});
}
+ // Initialize twitter media from media bundle tweet.
+ function initTwitter(wrapper) {
+ function _initTwitter () {
+ twttr.widgets.load(wrapper);
+ }
+
+ if (typeof twttr === 'undefined') {
+ $.getScript('//platform.twitter.com/widgets.js', _initTwitter);
+ }
+ else {
+ _initTwitter();
+ }
+ }
+
+ // Initialize instagram media from media bundle instagram.
+ function initInstagram() {
+ function _initInstagram () {
+ instgrm.Embeds.process();
+ }
+
+ if (typeof instgrm === 'undefined') {
+ $.getScript('//platform.instagram.com/en_US/embeds.js', _initInstagram);
+ }
+ else {
+ _initInstagram();
+ }
+ }
+
// Checks if the cookie exists.
function cookieExists() {
return typeof $.cookie(cookie) !== 'undefined';