This course is archived!
This tutorial is built using Drupal 8.0. The fundamental concepts of Drupal 8 - like services & routing - are still valid, but newer versions of Drupal *do* have major differences.
17.
Event Arguments and the Request
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
10 Comments
Hello weaverryan,
It's an interesting topic here, and thank you for explaining this dangerous skills in event subscribe thingy.
I have 1 question, which I tried myself but I am still blur on this.
I have a webform, which I want to subscribe the even when any webform submission edited (as approved) by me.
I don't know which exact listener to put actually. I tried with
KernelEvents::FINISH_REQUEST
I can see the params to manipulate, in the dump, but when I tried to use it, it returns null as cannot access it in the class.
Well, the strugle is quite overkill now, May I know if there any easier to workout with putting subscriber for specific event like webform update or node update?
Or do we have to use hook instead..
Hey Muhammad Al Maudoodi
Maybe this section about the request lifecycle can help you out figuring which event fits better to your needs.
If you still have more questions feel free to message us :)
Cheers!
Hi Diego and KNPU Team. Thank you for the reply.
At first I was confused about some particular event thingy, later I tried out a module https://www.drupal.org/proj... and it has a specific event to use easily, in my case for entity update.
So intstead of using Kernel Event, I use this and it works! But anyway it still a great tutorial that I learned to subscribe event via this course, and then I realized I would like to dig more on the event options, without this course I don't event know what I missing.
Another thing is I was mistakenly grab the $event parameters directly, when it got layers of properties. So I learned that for each $event type that returned, it showing up in the var_dump or etc, but when calling it's sub param, I cannot call directly as it will return null. Each sub $event has other $object must use the it's ObjectClass methods to call and it will return the value as it should.
I am enjoying learning this, I did replay lots of time on the vids. It is simple but lots of dangerous tips along the tutorial, that brings it a very interesting part.
Hey Muhammad Al Maudoodi
I'm happy to hear that you are loving our tutorials, and that you are actually improving your programming skills.
If you have more questions or feedback, feel free to contact us again :)
Cheers!
I get same error message:
TypeError: Argument 1 passed to Drupal\dino_roar\Jurassic\DinoListener::__construct() must implement interface Drupal\Core\Logger\LoggerChannelFactoryInterface, array given
myController:
Hey Habibun Noby!
Hmm, interesting! So, your
__construct()function (I assume this is from yourDinoListenerclass?) and your services YAML code looks perfect to me: Drupal should be passing the LoggerChannelFactory into your DinoListener. So, let's debug!1) Have you definitely cleared all your caches? Of course, I always need to ask this first :).
2) Do you have a full stack trace that you can take a screenshot of? I'm curious to see if possibly someone else is instantiating the
DinoListenerclass, which is causing the confusion.But definitely, you're close - I see no issues at all with the code you have here.
Cheers!
hey weaverryan,
i used drupal console for clearing cache.but some how it's not worked.So after that i manually delete all files under sites/default/files/* and rebuild again. now it's working....i don't know may be there is a issue with drupal console.
your mentioned debug tricks help me to find out the problem....
thanks
Very happy it worked in the end - I thought your code looked perfect! :)
I think it's an issue with drupal console. If I try to load a page after adding the __constructor argument, but before doing drupal cache:rebuild then the the error weaverryan mentioned starts occuring. In fact, once that error gets thrown on page load it also prevents drupal cache:rebuild from running, but drush cr; works.
That's totally possible - it's one of the tricky things about Drupal's container cache, which has bitten me a few times. With Drupal console, I believe it actually uses your Drupal container in order to do things. If your container is in a "broken" state, then you might not be able to rebuild it with drupal console. I don't know the specifics about this - I'm sure it's something they're aware of and there might be proper workarounds (though Drush is itself a very proper workaround!)
Cheers!
"Houston: no signs of life"
Start the conversation!