I have a node flag abuse and I want to remove/hide unflag link text "non-abuse" once the abuse flag is set.

How to do this in Drupal? Since I am new to Drupal, I can't think of a solution for this.

Note: I'm using this inside the Panels module.


4 Answers 4


In Drupal 7 you can use The Flag API (JavaScript) for this

The flagGlobalAfterLinkUpdate event : This event is triggered immediately after a flag link has been updated. (Flag links appear in two flavors: "Bookmark this!" and "Unbookmark this!", and when we speak of "update" we mean this change in appearance).

    (function ($) {
        $(document).bind('flagGlobalAfterLinkUpdate', function(event, data) {
            if (data.flagName == 'yourFlagName' && data.flagStatus == 'flagged') { //dont forget to add your flag name
                var flgName = '.flag-'+data.flagName;
  • Thanks for your reply! Can u please tell me where should i attach this code?
    – 12345
    Jun 19, 2014 at 7:06
  • Inside your theme JS file(sites/all/themes/YourTheme/js/ or in your custom module .js file). You can add it in any of your custom javascript file. But make sure, .js file should load on those pages.
    – Inizio
    Jun 19, 2014 at 11:27
  • I put the above code in sites/all/themes/myTheme/js folder but its not working. Unflag link text "non-abuse" is still displaying once the flag is flagged.How can i hide it?
    – 12345
    Sep 8, 2014 at 5:06

In the flag settings page under FLAG ACCESS you have Roles that may use this flag Just un-check UNFLAG option for all the roles.

  • I have tried with it but still unflag text is getting displayed once flag is flagged.
    – 12345
    Jul 3, 2014 at 12:13

So u are using Panels. It would be better to add a visibility criteria on the flag link block.

For that, go to that block on the panels page -> Click on Visibility rule -> Click on Add a new Rule -> Check on Content is flagged.

enter image description here

So when u hit save it would show you all the flags that are there.

In my case it shows this

enter image description here

So select the desired flag and check the Reverse(Not) checkbox.

Hit save and it would serve your purpose.

  • Yeah! I have set the same in panel page and unflag link text is invisible only after the page is refreshed,without refreshing the page it is still visible once the flag is flagged.I have used views_flag_refresh module for this in my view but still i need refresh the page to make unflag link text invisible.
    – 12345
    Jul 4, 2014 at 8:52

I am new to Drupal Javascript, but try this. https://www.drupal.org/docs/7/api/javascript-api/managing-javascript-in-drupal-7

Declare JS in root theme .info file - put mycustomjs.js in theme root folder

(function ($) {

Drupal.behaviors.exampleModule = { attach: function (context, settings) { // Code to be run on page load, and // on ajax load added here } }; }(jQuery));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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