Hello, I am working in one of the project using Flag module.

I want to add custom event when user flag any content. I am trying to use hook_flag_flag but it is not working.

I have added following uses in the module file for the flag.

use Drupal\flag\FlagInterface;
use Drupal\flag\Event\FlagEvents;
use Drupal\flag\Event\FlaggingEvent;

Is there anything to add more?

Thanks in advance.

Comments

Anks created an issue. See original summary.

joachim’s picture

Issue tags: -D8 hook_flag_flag not working.

In what way is it not working?

Have you checked it still exists? A lot of hooks were removed in the development process of the D8 version.

(BTW please don't use the tags field to duplicate other information. There's no point in doing that at all.)

Anks’s picture

Hello Joachim,

Thanks for the message.

Yes, I have checked that hook_flag changed to hook_flag_flag in D8. (https://www.drupal.org/node/1734814)

This is the code I am using in a module file.


use Drupal\Core\Form\FormStateInterface;
use Drupal\node\Entity\NodeType;
use Drupal\flag\Plugin\Flag\EntityFlagType;
use Drupal\flag\FlagInterface;
use Drupal\flag\Event\FlagEvents;
use Drupal\flag\Event\FlaggingEvent;
use Drupal\Core\Session\AccountInterface;

function nppe_custom_flag_flag( $flag, $entity_id, $account, $flagging) {
  drupal_set_message("This is custom message after Flag.");
}

But it is giving no output , Not even single error in errorlog.

Can you please help me for this issue.

Thanks.

joachim’s picture

That change record is for the 7.x-3.x branch. I do think it may have been removed completely for D8.

Anks’s picture

Alright. I should go with some customized solution.

Thank you so much for quick response.

LOBsTerr’s picture

Status: Active » Closed (works as designed)