function social_like_tokens in Open Social 8
Same name and namespace in other branches
- 8.9 modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 8.2 modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 8.3 modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 8.4 modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 8.5 modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 8.6 modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 8.7 modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 8.8 modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 10.3.x modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 10.0.x modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 10.1.x modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
- 10.2.x modules/social_features/social_like/social_like.tokens.inc \social_like_tokens()
Implements hook_tokens().
File
- modules/
social_features/ social_like/ social_like.tokens.inc, line 42 - Builds placeholder replacement tokens for Social Like module.
Code
function social_like_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$replacements = [];
if ($type == 'vote' && !empty($data['message'])) {
/** @var \Drupal\message\Entity\Message $message */
$message = $data['message'];
/** @var \Drupal\votingapi\Entity\Vote $vote */
if ($vote = Vote::load($message->field_message_related_object->target_id)) {
foreach ($tokens as $name => $original) {
switch ($name) {
case 'liked_entity':
$storage = \Drupal::entityManager()
->getStorage($vote
->getVotedEntityType());
$entity = $storage
->load($vote
->getVotedEntityId());
$replacements[$original] = $entity
->toUrl()
->toString();
break;
case 'liked_content_type':
$storage = \Drupal::entityManager()
->getStorage($vote
->getVotedEntityType());
$entity = $storage
->load($vote
->getVotedEntityId());
$content_type = $entity
->getEntityTypeId();
// Check if the content type is node.
if ($content_type === 'node') {
// Then get the bundle name.
$content_type = $entity
->bundle();
}
$replacements[$original] = $content_type;
break;
}
}
}
}
return $replacements;
}