1

One of the options for Flags is to have the flag automatically accept when the user clicks the link, or you can have it send the user to a confirmation dialog box where they have to click another button to confirm.

The default text for this dialog message is "Flag confirm", with a button to confirm and then a link for "Cancel".

"Flag confirm" is pretty obtuse, is there any way to alter the display of this dialog box? Thanks!

1

I figured this out.

When you create a new Flag, at the very bottom of the Flag set up screen is the option to choose if a dialog confirmation box is required for selecting your flag.

If you choose yes, an additional option box becomes available below this were you can set the message to be displayed when a user is either Flagging or Unflagging content with this dialog box.

If you don't enter any values (text string) in these fields, it seems the default text input by the system is "Flag confirm".

0

In Drupal 8, you can also alter this with hook_preprocess_flag function in your custom module:

 function mymodule_preprocess_flag(&$variables) {
   if (strpos($variables['attributes']['id'], 'flag-interest') === 0) {
     $variables['title'] = t('hello world');
   }
 }

You can use regex to grab the entity id, and then alter the data using information from the entity:

function mymodule_preprocess_flag(&$variables) {
   // Change text of button for "interest" flag to taxonomy term label.
   if (preg_match('/flag-interest-id-(\d+)/', $variables['attributes']['id'], $matches)) {
     $tid = $matches[1];
     $entity = \Drupal::entityManager()->getStorage('taxonomy_term')->load($tid);
     $variables['title'] = $entity->label();
   }
 }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.