function heatbeat_unlike_flag_form_alter in Heartbeat 8
Implements hook_form_FORM_ID_alter(). Tokenize the flag link strings.
File
- modules/
heartbeat_unlike/ heartbeat_unlike.module, line 7
Code
function heatbeat_unlike_flag_form_alter(&$form, \Drupal\Core\Form\FormStateInterface $form_state, $form_id) {
if ($form_id == 'flag_add_form' || $form_id == 'flag_edit_form') {
// Setup for the "Browse available tokens" link.
$browse_array = array(
'#theme' => 'token_tree_link',
'#token_types' => array(
'heatbeat_unlike_flag',
),
);
// Validation options to add to form elements.
$token_options = array(
'#element_validate' => array(
'token_element_validate',
),
'#token_types' => array(),
'#min_tokens' => 1,
'#max_tokens' => 10,
);
// Let admin know that this field is now tokenized.
$form['messages']['flag_short']['#description'] .= '<br />' . t('This field supports tokens (try: "Heatbeat_unlike [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: "Truce [flagcount:count]")');
$form['messages']['unflag_short']['#suffix'] = render($browse_array);
$form['messages']['unflag_short'] += $token_options;
}
}