Skip to content

Commit

Permalink
DIGITAL-118: Added new og:meta_description token and use it in global.
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsqd committed Dec 3, 2024
1 parent c92966b commit e67f877
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
8 changes: 4 additions & 4 deletions config/sync/metatag.metatag_defaults.global.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ label: Global
tags:
article_publisher: 'https://www.facebook.com/digitalgov'
canonical_url: '[current-page:url]'
description: '[site:slogan]'
description: '[dg:meta_description]'
fb_admins: '100000569454928'
og_description: '[site:slogan]'
og_description: '[dg:meta_description]'
og_image: '[dg:meta_image]'
og_image_alt: ' '
og_locale: en_US
og_site_name: '[site:name]'
og_title: '[current-page:title]'
og_type: website
og_type: '[dg:og_type]'
og_url: '[current-page:url]'
robots: 'index, follow'
title: '[current-page:title] | [site:name]'
twitter_cards_creator: '@Digital_gov'
twitter_cards_description: '[site:slogan]'
twitter_cards_description: '[dg:meta_description]'
twitter_cards_image: '[dg:meta_image]'
twitter_cards_site: '@Digital_gov'
twitter_cards_title: '[current-page:title]'
Expand Down
4 changes: 0 additions & 4 deletions config/sync/metatag.metatag_defaults.node.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,4 @@ id: node
label: Content
tags:
article_published_time: '[node:created:html_datetime]'
description: '[node:field_summary]'
og_description: '[node:field_summary]'
og_type: '[dg:og_type]'
og_video: '[dg:meta_video]'
twitter_cards_description: '[node:field_summary]'
26 changes: 26 additions & 0 deletions web/modules/custom/dg_token/dg_token.module
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ function dg_token_token_info(): array {
'description' => t("Image used for og:video."),
'type' => 'node',
];
$dg['meta_description'] = [
'name' => t("Meta Tag: Description"),
'description' => t("Image used for og:description, twitter description, and description."),
'type' => 'node',
];

return [
'types' => ['dg' => $type],
Expand Down Expand Up @@ -84,13 +89,34 @@ function dg_token_tokens($type, $tokens, array $data, array $options, Bubbleable
$replacements[$original] = _dg_token_meta_video($node);
break;

case 'meta_description':
$replacements[$original] = _dg_token_meta_description($node);
break;

}
}
}

return $replacements;
}

/**
* For a given node or null, return the meta tag description.
*
* @param \Drupal\node\NodeInterface|null $node
* The node that will have the description.
*
* @return string
* The URL to the meta tag description.
*/
function _dg_token_meta_description(?NodeInterface $node): string {
if ($node && $node->hasField('field_summary') && !$node->get('field_summary')->isEmpty()) {
return $node->get('field_summary')->processed;
}
$config = \Drupal::config('system.site');
return $config->get('slogan') ?: '';
}

/**
* For a given node or null, return the meta tag video URL.
*
Expand Down

0 comments on commit e67f877

Please sign in to comment.