Questions tagged [modules]

Questions related to Craft 3 Yii Module Development

Filter by
Sorted by
Tagged with
2 votes
1 answer
26 views

Create a pending user from plugin

I'm trying to create a pending user account when an event occurs $newUser = new User([ 'firstName' => $submission->firstName->getValue(), 'lastName' => $submission->lastName->...
user avatar
  • 1,793
1 vote
1 answer
40 views

Attach file to Freeform submission

I'm building a form that allows a user the ability to attach their authored assets onto the form submission. I have a custom module that's hooking into MailerService in Freeform and looking up the ...
user avatar
  • 1,793
1 vote
2 answers
39 views

Catching queue fail event

I have a queue that runs from a cron tab and I'd like to know immediately if it ever fails. Is there an event that fires or any other kind of way to hook into the queue behavior in a module when it ...
user avatar
  • 273
2 votes
1 answer
80 views

How to run custom module controller actions from console?

I have built a custom module with some custom controller actions - some of which I would like to run via console, but I am not sure what the path/command should be for running these actions? In my ...
user avatar
  • 438
1 vote
1 answer
48 views

Front-End user registration dynamic usernames - duplicate check

I have a front-end user registration form that generates a username automatically based on the first and last name inputs. This works as intended but on the off chance that two people have the same ...
user avatar
1 vote
1 answer
29 views

`SetElementTableAttributeHtmlEvent` with an array

Second to my other question about adding a column to the orders index, I would now like to add a column looping over the products in the order. How can I do that when then ...
user avatar
  • 337
1 vote
1 answer
30 views

Creating an asset from an API using a module

I'm currently making a module that I'm hoping is going to create entries and assets from an API. I've got the entries part working and now I'm trying to create an asset from a URI of an image. I've ...
user avatar
0 votes
0 answers
22 views

Module Action URL always throws 404 on Nitro

I am building a module and for some reason the action URLs are throwing an invalid route error locally (in both Nitro and Laravel Homestead) but not on my production server. I know all of the old case ...
user avatar
  • 103
1 vote
1 answer
55 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 ...
user avatar
  • 115
0 votes
0 answers
31 views

Check if element 'status' has changed on EVENT_BEFORE_SAVE

In a custom module, I am listening to EVENT_BEFORE_SAVE and then using isAttributeDirty/isFieldDirty to identify which entry fields that have changed, to decide on which further action to take. ...
user avatar
  • 438
0 votes
0 answers
33 views

How to save the selected assets in custom module

I am trying to create a custom module where I have created an asset uploader field. Images are getting uploaded with that field but not saved. class Settings extends Model { // Public Properties ...
user avatar
  • 1
1 vote
1 answer
108 views

How to create custom utility/helper functions for use in Twig templates?

So when using Drupal or Wordpress -- obviously you can write as much PHP in a template as you need, or in Wordpress for example, you can abstract that functionality away to the functions.php file. ...
user avatar
1 vote
1 answer
28 views

Difficulties to setup a Filter class

This question is following this one: Where to implement Craft Webhook FilterInterface. I'm trying to implement a Craft Webhook FilterInterface but failed to load it. Below is the content of my setup, ...
user avatar
1 vote
1 answer
39 views

Where to implement Craft Webhook FilterInterface

I have a custom Module and I would like to implement the craft\webhooks\filters\FilterInterface as seen on the doc. I understand that the event Webhooks::EVENT_REGISTER_FILTER_TYPES should be added in ...
user avatar
1 vote
1 answer
26 views

Craft 3 paginate not working when fetched with a controller

I'm loading a paginate via Craft::$app->getView()->renderTemplate(), this is being executed within a controller. But my pageInfo.nextUrl is now the url of my controller (/actions/controllername/...
user avatar
  • 160
1 vote
1 answer
96 views

How can I see what fields changed on EVENT_BOEFORE_SAVE and or EVENT_AFTER_SAVE

I want to see what data is changing whenever someone is updating an element to act on the difference between the states. In this particular case a User, but more abstractly speaking, an element. In ...
user avatar
0 votes
0 answers
45 views

Form with controller action, not working on Safari only (!)

Got a problem with a module. It functions in Firefox and Chrome, but not in Safari. It seems that the action fired from the form doesn't even call the controller, the page just reloads. ...
user avatar
  • 157
2 votes
1 answer
70 views

How to make custom element types restorable?

In Craft CMS 3, custom element types support soft-deletion out of the box. But once soft-deleted, there is now way to restore elements that are now listed in the Trashed status, the only available ...
user avatar
  • 1,130
2 votes
2 answers
59 views

How to reliably determine if an entry is being duplicated?

On a Craft 3.7 site, I need to make some changes when duplicating an element: set the dateCreated, dateUpdate & postDate to the current date ensure the entry is disabled clear the value of an ...
user avatar
  • 1,130
0 votes
0 answers
53 views

getDirtyFields returning more results than expected

I have a module that sends an email whenever a specific entry field is updated. Everything is working fine except that the field is being passed to the dirtyFields array even if it has not been ...
user avatar
0 votes
1 answer
95 views

CP Module: saving, editing, and reading a form

I read the docs multiple times but I'm stuck. I need to create a module that shows a form in the CP where an admin can input and save answers to 2 questions. It will always be just one single form. I ...
user avatar
  • 157
0 votes
2 answers
152 views

How to access 'setRouteParams' model in form validation

I created a module that adds a password protection to a site I'm testing craft on (I'm new to Craft and Yii, so please bear with me). In the front end there's a form where users enter a password and ...
user avatar
  • 157
0 votes
0 answers
77 views

Passing variables, and reading them, to Module template

I'm trying to pass an array to a module's twig template (on the front end). I have tried many solutions I've seen here, but I'm not able to read the passed variables inside the twig template. In my ...
user avatar
  • 157
1 vote
2 answers
235 views

Unable to find the template

I know this question has been asked multiple times. I have read all the post on this topic, and craft's docs. But still, I haven't figure out what I'm doing wrong. I would really appreciate a hand ...
user avatar
  • 157
0 votes
0 answers
20 views

How can I programmatically remove an attachment from a Commerce email?

I use the EVENT_BEFORE_SEND_MAIL event (in Craft Commerce) to check if an order meets certain conditions. If true, the attachment that Commerce adds to the email should be removed. Is there a way to ...
user avatar
  • 6,288
2 votes
1 answer
77 views

Where can a module safely store Project Config settings?

I can add a custom setting to the Project Config like so: Craft::$app->getProjectConfig()->set('modules.module-name.settingName', true); In the project.yaml file that would get saved at the top ...
user avatar
  • 13.2k
1 vote
0 answers
116 views

Invalid Route in module

I'm new to craft and slowly learning how to use more advanced features. I'm trying to write a module with a controller. When the route is invoked on a fetch call I get the following error: HTTP 404 – ...
user avatar
  • 157
2 votes
1 answer
31 views

Querying media asset in module

I'm learning to write my own modules, so there's a lot that I still don't know. I have looked at other modules/plugins, videos, but I arrived at a dead end. I'm writing a module that generates ...
user avatar
  • 157
1 vote
1 answer
144 views

How to update a User's Entries custom field only once just after save?

From a custom module, I'm listening to EVENT_AFTER_SAVE_ELEMENT events, to be sure to get the Entry ID after save: Event::on( Elements::class, Elements::EVENT_AFTER_SAVE_ELEMENT, function (...
user avatar
3 votes
1 answer
95 views

How to loop through specific entries in plugin and edit and save

I want to update some custom field values on my Entries with data from a third-party API, via a Plugin or Module. How do I load the relevant Entries, and one-by-one set and save the new data in my ...
user avatar
  • 1,888
2 votes
1 answer
55 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 ...
user avatar
2 votes
1 answer
99 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 ...
user avatar
  • 419
1 vote
1 answer
119 views

Module: adding amounts to total item price, based on chosen option (e.g. giftWrapped)

I made a module, which should add an amount to an item, based on the chosen option. For example, if user checks "gift wrapped" 5$ gets added, if "Gift wrapped with Card" is chosen, ...
user avatar
  • 319
1 vote
2 answers
90 views

Get System Activation email link

On my site a type of user can add new clients and I wanted to automate the activation email, so that when a new user is added then the client will get the activation email. But I'm getting an error ...
user avatar
1 vote
1 answer
124 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 ...
user avatar
3 votes
2 answers
222 views

Check if a FieldHandle exists in Module without throwing 'Invalid field handle' exceptions

I've been pulling my hair out trying to work this one out. I'm building a module to auto-populate a super-table on EVENT_BEFORE_SAVE, the module works exactly the way I want it to, everything seems to ...
user avatar
1 vote
1 answer
28 views

Class '...SiteModuleService' not found when used inside scout.php

I have a custom SiteModule that is used inside scout.php to deliver indexing data to Algolia. I have followed CraftQuest's tutorial on creating a custom SiteModule for handling the indicies. The setup ...
user avatar
  • 617
0 votes
1 answer
29 views

Add a form field into the details bar on the entry edit screen and do something with the value

I'd like to add a form field into the details bar on the entry edit page, so that when the entry gets submitted, the form field value gets passed into the data payload so that I can pick it up from ...
user avatar
  • 912
1 vote
1 answer
47 views

How to remove category link from redactor links but leave assets and entry link

This is a follow up from How to remove Link To Category from Redactor. I've been able to setup the module and remove all links with this: Event::on( RedactorField::class, RedactorField::...
user avatar
  • 1,032
2 votes
3 answers
307 views

What is the correct way to format a module controller action URL?

Consider the following Craft 3 example module structure: modules/ businesslogic/ controllers/ExampleController.php BusinessLogic.php ...and consider the following action in ...
user avatar
0 votes
0 answers
43 views

How to convert custom plugins to custom modules

I have 3 custom plugins that we had someone develop for us a while ago and I would like to convert them to custom modules. Since plugins are based upon modules, I was hoping there might be a cookbook ...
user avatar
1 vote
1 answer
102 views

getDirtyAttributes() not showing changes

I've got an event listener in a custom plugin where I want to check to see if the users email updated, but it doesnt show that attribute as dirty, even though I know it should be: Event::on(User::...
user avatar
0 votes
0 answers
196 views

Request didn’t meet the user agent and IP requirement for maintaining a user session when website posts to our action URL

We have a module that has an action controller method that a third party website posts data to. We can see that often, we can't save the data and there is an error "Request didn’t meet the user ...
user avatar
  • 912
1 vote
1 answer
33 views

Removing the Save button based on some condition

I want to remove the Create button of an entry based on some condition (review states) for some users. Is there a way to hook in within a module?
user avatar
  • 235
2 votes
1 answer
369 views

Failed to instantiate component or class error

I have a site with a custom module that was working fine until just recently but I tried to do a plugin update via CLI and it returned Failed to instantiate component or class "modules\exifreturn\...
user avatar
  • 509
1 vote
1 answer
35 views

Craft commerce 3 - Module - Lineitem - Get usergroup

I have the following code working. The only thing i have to do is to check which usergroup is the customer in. Is there a simple way to check what usergroup is the customer in? This is my first custom ...
user avatar
  • 13
1 vote
1 answer
335 views

Custom Module: new element type index page access

Hello I've created a new element type in a module (a web app within Craft) that I'm developing. I have initially created my models to be craft\db\ActiveRecord and save directly to their tables, but ...
user avatar
1 vote
1 answer
261 views

How do I get the siteName in a module (Craft 3)

In templates I can do something like {{siteName}}. But how do I retrieve this in a module? I've tried: Craft::$app->config->siteName I can grab my custom globals via Craft::$app->globals, but ...
user avatar
1 vote
1 answer
38 views

After signup action

I'm trying to add an action after user signup so that we can post the clients external system so we can retrieve a customer number that we require. My question is does EVENT_BEFORE_VERIFY_EMAIL run as ...
user avatar
  • 33
4 votes
1 answer
290 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 ...
user avatar
  • 273