0

The method invoked during the flagging event is implemented in Symfony\Component\EventDispatcher\EventSubscriberInterface.

class JIEventSubscriber implements EventSubscriberInterface{

  protected $staticCache;

  public function __construct() {
    $this->staticCache = &drupal_static("migration_running");
  }

  public static function getSubscribedEvents() {
    $events[Drupal\flag\Event\FlagEvents::ENTITY_FLAGGED] = ['onFlag',10];
    return $events;
  }

  public function onFlag(Drupal\flag\Event\FlaggingEvent $event){
   $flagging = $event->getFlagging();
   $entity = $flagging->getFlaggable();
   $flag_id = $flagging->getFlagId();
   if($flag_id == 'relevant_id'){
      Node::create(..);
   }

  }
}

The service is registered in services.yml as:

services:
  my_custom.event_subscriber:
      class: Drupal\my_custom\EventSubscriber\JIEventSubscriber
      arguments: ['@entity_type.manager']
      tags:
        - { name: 'event_subscriber' }

The flagging of flag 'relevant_id' is done through confirmation form. When the confirmation button is clicked twice simultaneously, two nodes are created. I've removed JS click eventListeners on the confirmation button after the first click but is there no way to prevent this on server side?

0

Your Answer

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

Browse other questions tagged or ask your own question.