Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

INREL-3964: add changes for pinterest image to AMP theme #16

Open
wants to merge 1 commit into
base: 8.x-2.x
Choose a base branch
from
Open
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
INREL-3964: add changes for pinterest image to AMP theme
killes committed Jun 5, 2018
commit 7cda7022657a07f481d226e95c984a1ac255a072
49 changes: 49 additions & 0 deletions infinite_amp.theme
Original file line number Diff line number Diff line change
@@ -360,3 +360,52 @@ function infinite_amp_views_pre_render(ViewExecutable $view) {
function infinite_amp_preprocess_page(&$variables) {
$variables['site_name'] = \Drupal::config('system.site')->get('name');
}


function infinite_amp_preprocess_container(&$variables) {
if (isset($variables['element']['#parent'])) {
if (isset($variables['element']['#parent']['#node'])) {
$entity = $variables['element']['#parent']['#node'];
}
elseif (isset($variables['element']['#parent']['#taxonomy_term'])) {
$entity = $variables['element']['#parent']['#taxonomy_term'];
}
elseif (isset($variables['element']['#parent']['#user'])) {
$entity = $variables['element']['#parent']['#user'];
}
}
if (isset($entity)) {
// use dedicated pinterest image for sharing
$variables['pinterest_share_img_url'] = MediaHelper::getImageUrlFromMediaReference(
$entity,
'field_pinterest_image'
);
// as fallback, if no dedicated pinterest image is set
// use a 2:3 format of share image
if (empty($variables['pinterest_share_img_url'])) {
$variables['pinterest_share_img_url'] = MediaHelper::getImageUrlFromMediaReference(
$entity,
'field_teaser_media',
'pinterest_fallback_teaser_image'
);
}
// use seo description for pinterest share description
if (method_exists($entity, 'bundle') && method_exists($entity, 'get') && method_exists($entity, 'hasField')) {
switch ($entity->bundle()) {
// field_teaser_text is misused as seo description on these content types
// this should be fixed in https://jira.burda.com/browse/INREL-4095
case 'article':
case 'magazine_products':
if ($entity->hasField('field_teaser_text')) {
$variables['pinterest_share_description'] = $entity->get('field_teaser_text')->value;
}
break;
default:
if ($entity->hasField('field_seo_description')) {
$variables['pinterest_share_description'] = $entity->get('field_seo_description')->value;
}
break;
}
}
}
}
3 changes: 2 additions & 1 deletion templates/embeds/social_icons.html.twig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{# Process label to be plain_text and trimmed always #}
{% set label = label|plain_text|trim %}
{% set pinterest_share_description = pinterest_share_description|plain_text|trim %}
{% set whatsapp_share_text = whatsapp_share_text|plain_text|trim %}
{% set socials_size = socials_size|default(32) %}
{% set url = url ~ "?utm_medium=social&utm_campaign=Sharing&utm_source=" %}
@@ -28,7 +29,7 @@
type="pinterest"
data-param-url="{{ (url ~ "Sharing_Pinterest") | e('html_attr') }}"
data-param-media="{{ (pinterest_share_img_url|default(share_img_url)) | e('html_attr') }}"
data-param-description="{{ label | e('html_attr') }}">
data-param-description="{{ pinterest_share_description|default(label) | e('html_attr') }}">

</amp-social-share>
{% endblock %}