123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- /**
- * Implements hook_form_FORM_ID_alter().
- * Tokenize the flag link strings.
- */
- function heartbeat_like_comment_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_comment'),
- );
- // 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;
- }
- }
- /**
- * Implements hook_preprocess_HOOK().
- */
- function heartbeat_like_comment_preprocess_flag(&$variables) {
- // Replace the link title with any tokens.
- $token = Drupal::token();
- $variables['title'] = $token->replace($variables['title'], array(
- 'flag_id' => $variables['flag']->id(),
- 'entity_id' => $variables['flaggable']->id(),
- ));
- }
|