last day (15 days later) » 

3:30 PM
-2
Q: Onesignal push API not sending notifications

MikeL5799I set up an entity hook in Drupal 8 to leverage the API and send push notifications if a new node in Drupal is created. I have the hook set up in the OneSignalConfigForm.php file of the OneSignal integration module for Drupal 8, but when I create a new node, no notification comes up as expected. ...

 
I believe you want $node->isNew().
 
@leymannx that's been deleted
 
Where is $node coming from?
 
@Kevin thanks. I just changed it still no dice
@leymannx $node is coming from being created in drupal admin. It's supposed to check if every time a new content node is created in drupal admin, then send the notification
 
3:30 PM
I mean where within the scope of this function is $node coming from. Maybe you mean $entity->isNew()?
 
@leymannx I thought the scope of node was from drupal core. Sorry I'm still new to drupal. Also could it be because I placed this function inside of the module's php file?
 
Uh, yes. There's a lot of things going wrong. You must create your own custom module to call that hook. You must never add custom code to any contrib or core file. Hooks is a non-OOP concept. So placing that inside a class it probably never gets called (or hooked up). Place in a custom module's *.module file.
 
This isn't so much Drupal as it is PHP. You have a function that is passed an argument of $entity, but you are referencing $node. $node does not exist in this context. hook_ should be replaced with your module name. You also want to check that the incoming $entity is actually a node object as well.
 
ok just created a custom module for that @leymannx hopefully that works.
@Kevin ok thanks
Ok, so upon further reading of entity api, there's a public function isNew() that should take care of the if statement. Do I still have to use a hook as well ? @leymannx
@Kevin Ok, so upon further reading of entity api, there's a public function isNew() that should take care of the if statement. Do I still have to use a hook as well?
 
I think you need to back up a bit and first understand what you are doing and break it down piece by piece.
 
3:30 PM
@MikeL5799 It would be wise to take Kevin's advice - no offence intended, but you're kind of all over the place here and most of your problem seems to be lack of knowledge about or confusion over basic PHP. We can't support a collaborative debug session here, that's not what Q+A is about, and unfortunately that's what this has become in the comments
 

last day (15 days later) »