Hot answers tagged

15

I haven't used Venti, so I can't comment on it. However, I have tried out both Calendars from Top Shelf Craft and Solspace Calendar on a recent project. I started out using Top Shelf Craft Calendars (Solspace Calendar hadn't been released at this point). However, during the project, I switched to Solpsace Calendar which has ended up being used on the final ...


12

If you re-save the section(s) that your entries are in, it should re-trigger a save of all of the entries. Hope that helps!


11

We did something similar with Charge when we were accepting payments for a Craft Virtual Training course. It does involve writing a plugin, but thankfully all of the heavy lifting for saving entries and charging credit cards is handled by the services provided by Craft and Charge, so the only thing the plugin has to worry about is collecting post data and ...


8

There aren't specific User element save events in Craft 3, but you can listen to EVENT_AFTER_SAVE_ELEMENT and check if the element is a user like so: Event::on(\craft\services\Elements::class, \craft\services\Elements::EVENT_AFTER_SAVE_ELEMENT, function(Event $event) { if ($event->element instanceof \craft\elements\User) { // Do your thing. ...


7

Whilst Doug's answer is useful for knowing the ins and outs of a particular event once you've found it, actually finding which events are available in Craft 3 in the current docs is not straight-forward. After a bit of digging, you'll find that most events are part of Craft's services - so head to the Class Reference and choose the most relevant service from ...


6

I believe what you asking about are Hooks and Events. Craft has several of them listed in the Hooks Reference and Events Reference. And Craft also allows us to add Hooks and Events in our plugins, which other plugins can leverage. In the case of Sprout Forms, as of this post, we don't have any documented events yet, but there are a couple in there and we'...


6

Yes there is, craft()->request->isCpRequest() returns whether the request is from the CP or not.


6

If anyone comes here looking for this answer for Craft 3 the function you are looking for is Craft::$app->getRequest()->getIsCpRequest()


6

Here's a list of Event classes and the "Public Properties" that you can get or set: https://docs.craftcms.com/api/v3/craft-events-assetevent.html An example of getting event data: Event::on( Users::class, Users::EVENT_BEFORE_ACTIVATE_USER, function (UserEvent $event) { $userElement = $event->user; } ); Class reference: https://...


5

Yes. It's not documented, but by instantiating the Event class (which is just a thin wrapper for Yii's CEvent) you can create and raise your own events. Obviously you could extend the Event class as well, if need be. See Aaron Berkowitz' excellent answer to a similar question for details -> https://craftcms.stackexchange.com/a/6941/1098 Also, check out the ...


5

I am not really clear on what you are trying to do. My guess is you are trying to add your own validation to saving an element and trying to block that with your own custom checking of content values etc? I don't think listening to the event will help as you cannot send a message to say this element is not valid from an event listener - the event does pass ...


5

I believe events can be raised programmatically by calling them from services. You could mimic this behavior by creating an Event object ($event) and calling calling craft()->entries->onBeforeSaveEntry($event) yourself, for example. You would need to set up the event context and create a new Event object as the code does in the Entries Service below. $...


5

You can set the value and save like so: craft()->on('entries.onSaveEntry', function(Event $event) { $entry = $event->params['entry']; if ($entry->section == 'mySection') { if ($entry->getContent()->myLightSwitchField == 1) { $entry->getContent()->setAttributes(array( 'myLightSwitchField' => ...


5

Add a init() method to your plugin and as long as it's installed and enabled, it'll be called on every request. public function init() { parent::init(); /* Do your stuff */ } If you want it to only happen on front-end requests, you can use: if (craft()->request->isSiteRequest()) { ... }


5

Not really – there's no priority system built into events for Craft or Yii. The easy way out is taking advantage of the fact that Craft actually loads plugins alphabetically, by name (i.e. the string returned by the plugins' getName() method). This means that if your plugins are in fact named "Plugin A" and "Plugin B", then Plugin A will be loaded before ...


5

I started using Solspace a couple weeks ago. The GUI is wonderful for content editors that will make use of it. ICS export so you could use it as the primary calendar manager and import the ICS into gcal or ical. The template integration is super easy and there are a number of bootstrapped demo calendar templates included that make extending, learning and ...


5

Depending on your sites' actual event handling needs, building your own plugin similar to Solspace Calendar or Venti to handle this (specifically features like recurrences - the CP UI as well as rendering in front end) could easily take you hundreds of hours to build properly. Unless you need something very different or custom from what either of these ...


4

This should get it sorted. There were 2 issues with yours. First is you were using the wrong 'and' syntax in the craft.entries call and second you need to use the Y-m-d pattern so MySQL understands to convert it a proper DateTime field instead of the m/d/Y format you had. {% set currMonth = now|date('m') %} {% set currMonthFirst = now|date('Y') ~ '-' ~ ...


4

craft()->on('amForms_submissions.saveSubmission', function(Event $event) { BusinessLogicPlugin::log(print_r($event, true)); }); Pay attention to the casing Craft\AmForms_SubmissionsService → amForms_submissions https://craftcms.com/docs/plugins/hooks-and-events#listening-for-events


4

Adding an event handler is not something you do through the control panel. What you need to do is create a plugin (pluginfactory.io makes this fairly easy), and in your plugin's main class, you have an init() function that looks like this: public function init() { craft()->on('sproutForms.onSaveEntry', function (Event $event) { $entry = $...


4

You can change the value in the DB directly instead of using the Elements service $entry = $event->element; $elementId = $entry->id; $siteId = $entry->siteId; Craft::$app->getDb()->createCommand() ->update( '{{%elements_sites}}', ['slug' => ElementHelper::createSlug('new-slug')], [ 'elementId' =&...


4

You can find out what the stack trace is (who is calling you) by putting something like this in your anonymous function: try { throw new \Exception(); } catch (\Exception $e) { Craft::debug( 'EVENT_AFTER_SAVE_ELEMENT '.$e->getTraceAsString(), ...


4

After using Andrew's debugging tip, I found out one event was triggered by saving the element itself, and the other was triggered by saving the revision of the element. So I modified my event listener to be like the following, and it solved the double-up issue: Event::on( \craft\services\Elements::class, \craft\services\Elements::...


3

There are two ways you could get something like this to work: If the other plugin fires an event when at a point in the code where your plugin wants to do something, you can just listen for that. (You will have to look through the plugin’s source code to be sure, if they haven’t documented it.) This is the cleanest route, so even if the event doesn’t exist, ...


3

When you are setting nextEvent, you can limit only events that are upcoming and only output the first result you get back like so: .startDate('>= ' ~ now).first() So you can take that and update your code like so: {% set nextEvent = craft.entries.section('events').order('startDate').startDate('>= ' ~ now).first() %} {% if nextEvent %} foo {% ...


3

Had a response from Pixel & Tonic on this. Which explains the process. The problem you're seeing is caused by returnJson() as that also ends the process after outputting the JSON data. Most likely onSaveUser (without Before) is a better place for this code; that ensures the user has been saved to the database before running the event code.


3

Events don’t get pre-registered anywhere in Craft, so there’s no way to easily fetch a definitive list of all events that will ever get called, but with a little PHP we can get a pretty good idea of what they all are. You’d start by getting a list of all the components on WebApp (what craft() returns) by calling its getComponents() method, loop through each ...


3

Within the context of that event, you will have access to: $event->params['user'] ... which is: A UserModel instance representing the user that has just been activated. Once you've got your user model, you can do something like this: $event->params['user']->isInGroup('artists') On a separate note, I believe the correct syntax is: craft()-&...


3

After wasting all of Brad's time (sorry brad!) by sending him an incomplete plugin file with a missing line, I have discovered why I wasn't seeing logs in the console as expected. Craft::log('...') or MyPlugin::log('...') function calls within onSaveEntry or onSaveUser events are in fact properly saved to the log files (craft/app/storage/runtime/logs/). ...


3

Have you tried?: {% set upcoming = craft.entries.section('gigEntry').status('pending', 'live').gigDate('>= ' ~midnight) %}


Only top voted, non community-wiki answers of a minimum length are eligible