Questions tagged [events]
The events tag has no usage guidance.
151
questions
0
votes
1
answer
11
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
1
vote
2
answers
138
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 ...
1
vote
1
answer
57
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.
...
0
votes
0
answers
84
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(
...
2
votes
1
answer
50
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 ...
1
vote
1
answer
273
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[] = [['...
1
vote
1
answer
43
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
{...
1
vote
1
answer
245
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 ...
1
vote
1
answer
106
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,...
1
vote
1
answer
140
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 ...
1
vote
1
answer
139
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) {
...
1
vote
1
answer
57
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 ...
0
votes
1
answer
72
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(...
1
vote
1
answer
60
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 ‘’’...
1
vote
1
answer
250
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 ...
1
vote
1
answer
100
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.
5
votes
1
answer
73
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 ...
1
vote
1
answer
145
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 ...
1
vote
1
answer
58
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 ...
2
votes
1
answer
190
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 ...
2
votes
1
answer
96
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 ...
2
votes
1
answer
458
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 ...
1
vote
1
answer
320
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 ...
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 ...
1
vote
1
answer
307
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 ...
1
vote
1
answer
308
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 ...
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 ...
2
votes
1
answer
176
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 ...
1
vote
2
answers
109
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,
...
1
vote
1
answer
856
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,
...
1
vote
1
answer
42
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 ...
4
votes
1
answer
428
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 ...
1
vote
1
answer
147
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->...
1
vote
1
answer
44
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 ...
1
vote
1
answer
579
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 ...
1
vote
1
answer
86
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 ...
1
vote
1
answer
84
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 ...
1
vote
2
answers
390
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 ...
1
vote
1
answer
30
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 ...
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?
1
vote
1
answer
231
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 =...
1
vote
1
answer
487
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 ...
1
vote
1
answer
805
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,
...
1
vote
1
answer
68
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 ...
1
vote
1
answer
757
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,...
4
votes
0
answers
421
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 ...
3
votes
1
answer
410
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,...
5
votes
2
answers
2k
views
EVENT_AFTER_SAVE_ELEMENT triggered twice after saving an entry
I had this weird issue, not sure if that happens to you guys or not.
I'm trying to catch the 'after entry is saved' event, using the following code in my custom module's init() function (The module's ...
1
vote
1
answer
466
views
$event->isNew not working as expected after Craft 3.2 update
Pre Craft 3.2, you could do something like this if you wanted to perform an action in the event you just saved a new entry:
use craft\elements\Entry;
use craft\events\ModelEvent;
Event::on(
...
1
vote
1
answer
68
views
Delete event from front end
I am using Solspace Calendar plugin where front end user can add/edit events. Is there any functionality so that user can delete an event from front-end?