function heartbeat_like_form_alter in Heartbeat 8
Same name in this branch
- 8 modules/heartbeat_like/heartbeat_like.module \heartbeat_like_form_alter()
- 8 modules/heartbeat_comment_like/heartbeat_like.module \heartbeat_like_form_alter()
Implements hook_form_FORM_ID_alter(). Tokenize the flag link strings.
File
- modules/
heartbeat_comment_like/ heartbeat_like.module, line 7
Code
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') {
// Setup for the "Browse available tokens" link.
$browse_array = array(
'#theme' => 'token_tree_link',
'#token_types' => array(
'heartbeat_like',
),
);
// 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: "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;
}
}