function heatbeat_unlike_flag_tokens in Heartbeat 8
Implements hook_tokens().
File
- modules/
heartbeat_unlike/ heartbeat_unlike.tokens.inc, line 38 - Token for heatbeat_unlike_flag.
Code
function heatbeat_unlike_flag_tokens($type, $tokens, array $data, array $options, BubbleableMetadata $bubbleable_metadata) {
$replacements = array();
if ($type == 'flagcount') {
foreach ($tokens as $name => $original) {
// Find the desired token by name
switch ($name) {
case 'count':
if (isset($data['flag_id']) && isset($data['entity_id'])) {
// Query the db for the count associated with this entity.
$query = \Drupal::database()
->select('flag_counts', 'fc');
$query
->fields('fc', [
'count',
]);
$query
->condition('fc.flag_id', $data['flag_id']);
$query
->condition('fc.entity_id', $data['entity_id']);
$count_db = $query
->execute()
->fetchAssoc();
if (!isset($count_db['count'])) {
$count_db['count'] = 0;
}
$replacements[$original] = $count_db['count'];
}
break;
}
}
}
// Return the replacements.
return $replacements;
}