heartbeat_like.module in Heartbeat 8
File
modules/heartbeat_like/heartbeat_like.module
View source
<?php
function heartbeat_like_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_id == 'flag_add_form' || $form_id == 'flag_edit_form') {
$browse_array = array(
'#theme' => 'token_tree_link',
'#token_types' => array(
'heartbeat_like',
),
);
$token_options = array(
'#element_validate' => array(
'token_element_validate',
),
'#token_types' => array(),
'#min_tokens' => 1,
'#max_tokens' => 10,
);
$form['messages']['flag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Like [flagcount:count]")');
$form['messages']['flag_short']['#suffix'] = render($browse_array);
$form['messages']['flag_short'] += $token_options;
$form['messages']['unflag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Unlike [flagcount:count]")');
$form['messages']['unflag_short']['#suffix'] = render($browse_array);
$form['messages']['unflag_short'] += $token_options;
}
}
function heartbeat_like_preprocess_flag(&$variables) {
$token = Drupal::token();
$variables['title'] = $token
->replace($variables['title'], array(
'flag_id' => $variables['flag']
->id(),
'entity_id' => $variables['flaggable']
->id(),
));
}