Skip to content
This repository was archived by the owner on Jun 24, 2018. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [1.14.0]
### Added
- Added support for media bundles tweet and instagram to degov_social_media_settings.

## [1.13.1] - 11-12-2017
### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#}
<article{{ attributes }}>
{% if content %}
{{ content }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content }}
{% endif %}
{% endif %}
</article>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#}
<article{{ attributes }}>
{% if content %}
{{ content }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content }}
{% endif %}
{% endif %}
</article>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#}
<article{{ attributes }}>
{% if content %}
{{ content }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content }}
{% endif %}
{% endif %}
</article>
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
#}
<article{{ attributes }}>
{% if content %}
{{ content }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content }}
{% endif %}
{% endif %}
</article>
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
#}
<article{{ attributes }}>
{% if content %}
{{ content }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content }}
{% endif %}
{% endif %}
{% if content.usage %}
<div class="instagram__usage">
Expand Down
7 changes: 6 additions & 1 deletion degov_media_tweet/templates/media--tweet--default.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
#}
<article{{ attributes }}>
{% if content.embed_code|field_value %}
{{ content.embed_code }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content.embed_code }}
{% endif %}
{% endif %}
{% if content.field_tags|field_value %}
<div class="tags"{{ content.field_tags|quickedit_attr }}>{{ content.field_tags }}</div>
Expand Down
7 changes: 6 additions & 1 deletion degov_media_tweet/templates/media--tweet--embedded.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
<article{{ attributes }}>
{% if content %}
{% if content.embed_code|field_value %}
{{ content.embed_code }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content.embed_code }}
{% endif %}
{% endif %}
{% if content.field_tags|field_value %}
<div class="tags"{{ content.field_tags|quickedit_attr }}>{{ content.field_tags }}</div>
Expand Down
7 changes: 6 additions & 1 deletion degov_media_tweet/templates/media--tweet--preview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
<article{{ attributes }}>
{% if content %}
{% if content.embed_code|field_value %}
{{ content.embed_code }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content.embed_code }}
{% endif %}
{% endif %}
{% if content.field_tags|field_value %}
<div class="tags"{{ content.field_tags|quickedit_attr }}>{{ content.field_tags }}</div>
Expand Down
7 changes: 6 additions & 1 deletion degov_media_tweet/templates/media--tweet--search.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
<article{{ attributes }}>
{% if content %}
{% if content.embed_code|field_value %}
{{ content.embed_code }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content.embed_code }}
{% endif %}
{% endif %}
{% if content.field_tags|field_value %}
<div class="tags"{{ content.field_tags|quickedit_attr }}>{{ content.field_tags }}</div>
Expand Down
7 changes: 6 additions & 1 deletion degov_media_tweet/templates/media--tweet--usage.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@
#}
<article{{ attributes }}>
{% if contentembed_code|field_value %}
{{ content.embed_code }}
{% if social_media_disabled %}
<div class="js-social-media-code">
</div>
{% else %}
{{ content.embed_code }}
{% endif %}
{% endif %}
{% if content.field_tags|field_value %}
<div class="tags"{{ content.field_tags|quickedit_attr }}>{{ content.field_tags }}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ sources:
pinterest: 'Pinterest'
flickr: 'Flickr'
vimeo: 'Vimeo'
instagram: 'Instagram'
other: 'Andere'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sources:
facebook: 'Facebook'
twitter: 'Twitter'
youtube: 'Youtube'
googleplus: 'Google+'
pinterest: 'Pinterest'
flickr: 'Flickr'
vimeo: 'Vimeo'
instagram: 'Instagram'
other: 'Andere'
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
15 changes: 13 additions & 2 deletions degov_social_media_settings/degov_social_media_settings.module
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
Expand Down
36 changes: 36 additions & 0 deletions degov_social_media_settings/js/process.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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';
Expand Down