Questions tagged [events]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
0 votes
0 answers
26 views

Is there any events to trigger for inserting data into orderAdjustment table

I'm implementing a module to integrate a third party gift voucher into the craft cms application. For that I need to trigger the order Adjuster every time the cart gets updated. TIA
Gowri Shankar's user avatar
1 vote
1 answer
48 views

What is the best way to automatically add a job (queue) every day?

I would like to add a daily job that updates data. I have the following code: Event::on( Controller::class, Controller::EVENT_BEFORE_ACTION, static function (ActionEvent $event) { ...
antdev's user avatar
  • 135
1 vote
0 answers
33 views

Run function after "Save Draft" but don't run if it autosaveDraft?

Since CRAFT_AUTOSAVE_DRAFTS=false was deprecated in Craft 4, and actually this method also affect some Craft functionality. i want to know if there another method or event that will run myfunction ...
Nixxian365's user avatar
1 vote
1 answer
23 views

How to call and print only Event Types of Event Plugin

How to call and print only Event Types (title and handle of event types) of Event Plugin -> https://verbb.io/craft-plugins/events/features Moderator Added from Comments: I need to filter the events ...
user14621's user avatar
1 vote
2 answers
139 views

Stop customers from increasing line item

I have a site where the owners want to stop customers from ordering more than 1 type of item. The Twig logic is already in place to stop any forms showing that would allow customers adding more than ...
Jaytrix's user avatar
  • 187
1 vote
1 answer
88 views

Set default values for new Commerce products

I'm trying to set some defaults for newly created products. That is, when a new product is created, I want to set some settings to specific default values, but users should be allowed to change those. ...
MoritzLost's user avatar
  • 11.2k
0 votes
0 answers
108 views

How to modify a custom field on cart, when the cart is created

I want to set a custom field on shopping cart when I first retrieve it. https://craftcms.com/docs/commerce/4.x/extend/events.html#modifycartinfo sounds appropriate so I tried doing this: Event::on( ...
kindoflike's user avatar
2 votes
1 answer
61 views

Registering an element source with EVENT_REGISTER_SOURCES for a specific site ID

Is it possible to register an element source for a specific site ID, while it not appearing in another? I have a module which is currently registering element sources, however we are now looking to ...
James White's user avatar
1 vote
1 answer
330 views

Custom validation & messages

I'm trying to add some custom validation rules to user sign up like this: Event::on( User::class, Element::EVENT_DEFINE_RULES, static function(DefineRulesEvent $event) { $event->rules[] = [['...
supazu's user avatar
  • 576
1 vote
1 answer
55 views

How to check read-only mode in plugin?

I have written a plugin and it listens to different events to run some tasks. Now if the app is in "read-only mode", I do not want some of these events to run: class MyPlugin extends Plugin {...
7ochem's user avatar
  • 163
1 vote
1 answer
353 views

Adding Custom button to CP

I'm trying to add a custom button in the sidebar of one of my entries. I've found that it could be done in Craft 3 with this template hook: cp.entries.edit.details (e.g. How to add a custom button at ...
Robin Gauthier's user avatar
1 vote
1 answer
136 views

Call external API when event is firing

I would like to send a post request to an API when a new order in in Craft Commerce is paid. So I've got this event into a plugin: Event::on( Order::class, OrderStatuses::class,...
Davide's user avatar
  • 35
1 vote
1 answer
167 views

How to rename an asset on file upload Craft 4

I am looking to update some custom module code which updates the file name on upload. In Craft 3 I had this working by listening to the EVENT_AFTER_SAVE on an Asset. It would detect the ID of the ...
zizther's user avatar
  • 449
1 vote
1 answer
163 views

Can I detect if the event is saving entry?

I have been implementing my own module like this; protected function myFunction() { Event::on( ElementQuery::class, ElementQuery::EVENT_BEFORE_PREPARE, function(Event $event) { ...
Kota.M's user avatar
  • 423
1 vote
1 answer
71 views

Is there an Event that detects when all templates have been processed?

I'm working on a Content Security Policy and need to set an HTTP header after all templates have finished processing. Right now I'm doing that by calling a module variable at the bottom of the main ...
plaintxt's user avatar
  • 488
0 votes
1 answer
89 views

Craft 4: How to programmatically attach a new tab in elements tab?

I'm trying to add a new Tab in entry elements from my module using events. Event::on( FieldLayout::class, FieldLayout::EVENT_DEFINE_NATIVE_FIELDS, static function(...
Amsal Situmorang's user avatar
1 vote
1 answer
67 views

Feed Me Plugin - Prevent Feed from Being Triggered Multiple Times in Quick Succession

I’d like to prevent a feedme feed from running more than once when multiple requests are received within a few seconds of each other. My first guess is that I would want to target an event such as ‘’’...
Chris Drew's user avatar
1 vote
1 answer
292 views

Check user data before login - Events on Craft3?

I need some help with my login process, it's working but I feel it's not the best approach to achieve it I have the following workflow for the Login process : 1- enter username/password -> press ...
Ra3d K's user avatar
  • 125
1 vote
1 answer
109 views

Event triggered when Craft sends email

Is there an event that would be triggered every time email is being sent by Craft? So email message can be intercepted.
Piotr Pogorzelski's user avatar
5 votes
1 answer
83 views

Identify event origin (e.g. via admin vs module code)?

When using Craft Event triggers in PHP (e.g. Event::on), is there any event metadata that can tell where the event originated from? E.g. if it was triggered from an admin action, or if it was ...
iamkeir's user avatar
  • 468
1 vote
1 answer
157 views

What's the attribute of a Matrix field to add error message

I try to validate some fields before saving the entry, if the field is invalid, prevent the entry from saving and return the error message, I'm doing it via Element::EVENT_BEFORE_SAVE event. It works ...
Thomas's user avatar
  • 69
1 vote
1 answer
59 views

Manipulating search event

Looking at a means to perform subqueries against certain searches in the back-end of the Craft CMS eg for searches against particular sections within Admin > Entries. Looking into this it seems ...
Cole Henley's user avatar
  • 1,741
2 votes
1 answer
200 views

Craft Event Date Range in Craft

I'm creating a date range where I only want to show upcoming events in the next 30 days based on a start date. I have created my query but when I add my if statement to filter on the start date it ...
Dan Lee's user avatar
  • 1,107
2 votes
1 answer
100 views

Asset upload hangs when uploading to asset field in entry

I wrote the following code in Module.php that checks if a file size is too large during an asset upload (the file size limit and asset volume handles are defined in a globals: a table with one column ...
berrydev's user avatar
2 votes
1 answer
553 views

Update matrix block field before saving entry

I have a custom module, on EVENT_BEFORE_SAVE I am looping through a matrix field, this matrix field has a block which has an entry field, a number field and a lightswitch (to know if this block has ...
zizther's user avatar
  • 449
1 vote
1 answer
355 views

UrlManager::EVENT_REGISTER_CP_URL_RULES event not firing in custom plugin

I'm working on building out a custom plugin for Craft 3 to create a new element type called Events. Following the Craft docs for creating edit pages, I hit the point where I'm trying to register my ...
braican's user avatar
  • 111
12 votes
3 answers
2k views

How do we distinguish between a 'New' and 'Updated' Live Entry using the craft\elements\Entry::EVENT_AFTER_SAVE event?

I can't decide if I'm missing something or this should be a bug. With the recent changes to Drafts/Revisions in Craft 3.7 it's not clear to me how to distinguish between New and Updated Entries using ...
Ben Parizek's user avatar
  • 13.4k
1 vote
1 answer
351 views

Craftcms 3 Module - API call validation (on EVENT_BEFORE_SAVE, EVENT_BEFORE_VALIDATE, EVENT_AFTER_VALIDATE, EVENT_AFTER_SAVE)

I am trying to validate entries on Save in a Module. My specific use case requires that the Entry validation - on failure to validate will return user to form with field errors. On successful ...
matty_rj45's user avatar
1 vote
1 answer
328 views

How would I detect whether an entry's asset field has been updated on save?

We need to send a notification email when an entry's asset field, Custom Image, has been updated on entry save. We're able to do this consistently for text fields but I'm having trouble doing the same ...
plaintxt's user avatar
  • 488
1 vote
1 answer
87 views

Listening for Change at Entry Save

I want to send an email if/when an entry is saved with a lightswitch switched on after previously being off. I have the below code in my plugin's init file, but I don't know how to check for the ...
Kevin Amézaga's user avatar
2 votes
1 answer
186 views

Apply custom filter on the entries in admin control panel using custom plugin in craft cms 3.5

I was referring to Filter entries in the CP based on custom permission and Filter entries in the CP based on custom permission It seems onBuildElementsQuery was available only in 2.x. Is there any ...
Ram's user avatar
  • 41
1 vote
2 answers
117 views

Multiple Listeners (Handlers) on Event

Is it possible to register multiple EventHandlers? I mean something like this: Event::on( Entry::class, Entry::EVENT_AFTER_SAVE,[ NotifyWhenCookPostedArticle::handle, ...
Slowwie's user avatar
  • 235
1 vote
1 answer
949 views

Hook into Entry::EVENT_AFTER_SAVE when user saves it

I want to send a Mail to an admin, whenever a User of group ‚Cook‘ creates an Entry of Type ‚Recipe‘. For that I created an Event reacting on Entry::EVENT_AFTER_SAVE : Event::on( Entry::class, ...
Slowwie's user avatar
  • 235
1 vote
1 answer
45 views

Email notifications solspace calendar

I'm considering the Solspace Calendar plugin for a project. Can the plugin send automatic e-mail notifications when an event has been submitted from the front-end? Can the plugin save events ...
steve1938's user avatar
  • 105
4 votes
1 answer
458 views

Is there a way to compare what has changed on an entry while it's being saved?

I'm taking my first baby steps into the php side of Craft, and my php experience in general is extremely fledgling. But I'm pretty much forced to create a module for a project I have, so here I am ...
Brimby's user avatar
  • 343
1 vote
1 answer
154 views

Parent are not set anymore after saveElement()

In this code I try to create a new Entry and set a Parent to it. The sectionId and the typeId are actually the same. $navigationItem = new Entry(); $navigationItem->typeId = 4; $navigationItem->...
Slowwie's user avatar
  • 235
1 vote
1 answer
48 views

Stop image upload if moderation fails using EVENT_BEFORE_HANDLE_FILE

I have a frontend form where images can be uploaded. I am handling the image moderation within EVENT_BEFORE_HANDLE_FILE on the Asset class. I am setting session errors for any moderation issues ...
zizther's user avatar
  • 449
1 vote
1 answer
626 views

EVENT_BEFORE_SAVE event not getting $entry-id when creating an entry

I don't know if it was with Craft 3.5, but did something change slightly when using the EVENT_BEFORE_SAVE event? I have a simple use case where I am encoding the entry ID and updating the slug when ...
zizther's user avatar
  • 449
1 vote
1 answer
90 views

How to differentiate EVENT_BEFORE_UPDATE_SUBSCRIPTION events in Commerce 2/3

I'm listening for various subscription events to send emails to members. Right now, I'm dealing with subscriptions where a renewal payment fails. I'm specifically listening for ...
Clive Portman's user avatar
1 vote
1 answer
87 views

Accessing Commerce ‘Product Fields’ in events hooks

I've added an Entries field called linkedCourseEntry to a Product (Product Type > Product Fields tab). In the Product itself I've assigned an entry. I need to access linkedCourseEntry from one or ...
Mere Development's user avatar
1 vote
2 answers
411 views

Commerce: Remove tax adjuster from line item in plugin

I need to remove adjusters from each line item if a certain condition is not met. I see that in the CP you can manually remove them by editing the line item but hunting down this code in Commerce's ...
Ryan's user avatar
  • 1,952
1 vote
1 answer
32 views

Do Freeform Events Fire From Control Panel?

It appears to me that Freeform Submission events do not fire when editing events in the control panel. They certainly fire from a front-end submission. That would make this statement in the ...
Steve Mock's user avatar
1 vote
1 answer
61 views

Do something on save of an entry

if that entry is in a particular section, then I want to do some task. I can't really find the event docs I need to do that. Everything I've come across has been for Craft 2. Any steps for a hint?
Steven Grant's user avatar
  • 1,855
1 vote
1 answer
237 views

Update entry Enabled value based on field value when saving

I am trying to update the value of the entry enabled field depending on a certain field value. I am listening to the EVENT_BEFORE_SAVE event and have it updating as such $entry->enabled = $status =...
zizther's user avatar
  • 449
1 vote
1 answer
513 views

Event when an entry is enabled

I've been looking for an event that get triggered when an entry is moved from a disabled to enabled status. Currently I'm trying to find it through the EVENT_AFTER_SAVE_ELEMENT event but I have no ...
Mr.Smithyyy's user avatar
1 vote
1 answer
829 views

Choose not to save an element on EVENT_BEFORE_SAVE_ELEMENT

I want to do some server side checks to see if the entry should be saved or not. In my plugin I have something like that Event::on( Elements::class, Elements::EVENT_BEFORE_SAVE_ELEMENT, ...
Lukigi's user avatar
  • 565
1 vote
1 answer
77 views

How should we be setting up product categories/sub-categories?

New to Craft CMS and currently don't understand the terminology or how things work together in the platform yet. If I want to set up a category structure like the below in Commerce, how is the best ...
zigojacko's user avatar
  • 135
1 vote
1 answer
784 views

EVENT_BEFORE_SAVE_ELEMENT Saving element loop in task/queue

I'm calling EVENT_BEFORE_SAVE_ELEMENT to trigger a task that then updates the entry, but it's causing a loop? The event is triggered when a specific entry type is saved: Event::on( Elements::class,...
Tim Coysh's user avatar
4 votes
0 answers
435 views

User Event before Login - check if user has password and logged in before

Is there a User Event before the authentication is fired? I want to show a message if the user doesn't have a password yet and if it's his first login / check if he never logged in before - All in ...
Christopher Dosin's user avatar
3 votes
1 answer
415 views

How to determine source of Elements save event

We need to send notification emails when entries of a particular type are created, updated, or enabled/disabled. The entrypoint for this happens in a module's init() method: Event::on(Elements::class,...
plaintxt's user avatar
  • 488