Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [modules]

Questions related to Craft 3 Yii Module Development

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

How to clear conditional field values when hidden?

In Craft CMS 5, I have several conditional fields that display or hide based on the value of a Category field (single selection). Depending on the selected category, different fields appear: Date, ...
Romain P.'s user avatar
  • 1,852
1 vote
1 answer
28 views

Save field value After Complete Order

I am using Craft Commerce and want to edit the order after it has been completed by the customer. For this I am using the EVENT_AFTER_COMPLETE_ORDER event. Event::on( Order::class, ...
Matthias's user avatar
  • 301
1 vote
2 answers
23 views

Error when calling renderPdfForOrder() in Module

The error I'm receiving is: Call to a member function getRenderLanguage() on null My Code (Edit - simplified): $mergeService = new Merger(); $batchFileName = 'VAT-' . $country . ( $date ? '-' . $...
cherrykoda's user avatar
  • 1,114
0 votes
0 answers
36 views

Save provisional changes in custom controller

I have added a button to the entry edit page, which runs a custom controller I user to copy data from field A into field B in a particular format. Here's a condensed version of that: public function ...
supazu's user avatar
  • 526
3 votes
2 answers
73 views

Unable to find custom template when using a console controller inside a module

I'm creating my first module. Inside this module, I check a few entries for some conditions, and if all conditions are met, I want to send out a personal email. Everything worked, but I wanted to ...
Arno Ramon's user avatar
0 votes
0 answers
20 views

Change layout of relations field in cp "Unable to find the template"

I've created a custom module that adds form submissions as relations to the entry they were submitted on. This functionality works, but I can't figure out how to change the template for the relations ...
Jane's user avatar
  • 11
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
26 views

Replace the value of a table cell (inside a Matrix field)

I have a Matrix field, and blocks have a Table field inside of them, with two columns: event and category. I want to now set anything with category 'A' to category 'B' via a module (listening to Entry:...
supazu's user avatar
  • 526
2 votes
1 answer
50 views

_layouts/cp.twig cannot be found

I have a module that's meant to add a section to the CP. class Reports extends Module { // Public Methods // ========================================================================= /** ...
cherrykoda's user avatar
  • 1,114
1 vote
1 answer
59 views

How to make AJAX request to controller inside module?

Created a new module to receive form values and process API in Craft CMS 4. How to make an AJAX request to access a controller in my module? module name - giftcard controller - GiftCardController ...
Gowri Shankar's user avatar
0 votes
0 answers
34 views

Is it possible to change built-in field like Table with a module?

Is it possible to change behavior of in-built field with a module? I am trying to change // Apply static translations part of _normalizeValueInternal function in Table.php https://github.com/craftcms/...
Foxtrot's user avatar
1 vote
1 answer
38 views

Is there a way to determine an element by its path or full url instead of the uri?

I'm using Craft in headless mode. It's a multisite setup different languages. I know that's it's possible to query an element by it's uri. Is there a way to check if a full path or an absolute url ...
user14370's user avatar
2 votes
1 answer
52 views

Add to an asset field from a queue job

I'm following this to generate social share images from entries: https://ghijk.co.uk/blog/generate-dynamic-social-share-images-in-craft-cms It's working well. But I'd like to add the generated image ...
supazu's user avatar
  • 526
1 vote
1 answer
153 views

Customer Controller and downloading a file (Apple Wallet - using PKPass library)

I'm trying to create a controller for a user to download a membership card as a pass in Apple Wallet. I'm looking to use the PKPass Library. I've got things set up and working using their example like ...
supazu's user avatar
  • 526
0 votes
0 answers
49 views

Class "modules\jobs\GenerateSocialCard" not found

Following this article, I'm trying to generate an image from html on Entry Save, but I'm getting an error when trying to push a job GenerateSocialCard to the Craft queue. I'm using the default Module. ...
Michal Bulla's user avatar
2 votes
2 answers
492 views

Get User ID before the user is created

I'm creating users programmatically, and in some cases, they won't have an email address. In these cases, I would like to just set the email address to [email protected] where 1234 is the User ID. It's ...
supazu's user avatar
  • 526
1 vote
2 answers
260 views

Sprig: how to redirect to a URL after submitting to a custom controller?

I have a multi-pages form which is submitting using Sprig plugin. The action is targeting a controller in a custom module. Each step of the form is loading using the current step stored in session. ...
Romain P.'s user avatar
  • 1,852
1 vote
1 answer
115 views

Commerce LineItem Option validation

I have Line Item options that I'm trying to validate in a module. I'm using the example code from the docs here on the front-end of the cart. Below that it says: Commerce does not validate the ...
supazu's user avatar
  • 526
1 vote
1 answer
87 views

Calculating loyalty from consecutive entries on a user

I'm trying to calculate a 'loyalty' score on Users. I have an Entries field history, with Entries like 2023, 2022, 2021 etc. I want to calculate the number of consecutive years, going backward from ...
supazu's user avatar
  • 526
1 vote
1 answer
136 views

Custom module controller: how to impersonate any user and start its session

From a custom module, I would like to impersonate and start any user session in the browser. This session will be based on a user query result got from a web controller. Something in a way like when ...
Romain P.'s user avatar
  • 1,852
1 vote
1 answer
77 views

Update user matrix field dropdown through module

Appreciate I may be asking for a lot here - I have an existing module that I use to fire events when a stripe order is completed. I would like to iterate through some User matrix blocks and update a ...
Mark's user avatar
  • 741
1 vote
1 answer
48 views

Reuse entry form layout in custom module

I'm currently developing a custom module. I created a section called "bookings" with an entry type containing some fields. I designed the form layout as i wanted. In the CP, the Entry ...
Mathias Marrillet's user avatar
1 vote
1 answer
60 views

Job queue always failed to sync data into api/graphql with Getting unknown property of service

i have build a module to send entry value into a graphql mutation. so far running and succesfully, now with craft 4 (actually as 4.4.0), i plan to use job queue of craft. i add into queue before sync ...
Arham's user avatar
  • 11
1 vote
1 answer
212 views

Call controller from controller passing arguments

new to CraftCMS - I'm building a website that has to handle two different APIs, where the user logs into API-1 and after succeeding the website has to call an other API checking for a status while ...
Luckyfella's user avatar
1 vote
2 answers
172 views

Send mail to admin on new user

I'm trying to make a craft module, which sends a mail to the admin whenever a new user registers. Somehow I'm not able to get this work, anyone knows how to solve this? The module is not able to send ...
aren's user avatar
  • 79
1 vote
1 answer
145 views

Creating a multiple choice quiz module

I'm trying to set up a simple quiz module. I'm using a Matrix field called quiz, with a plain text question field and an answers table field. In the table field, there's two columns, plain text answer ...
supazu's user avatar
  • 526
1 vote
1 answer
359 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
  • 526
1 vote
1 answer
825 views

Set "Access-Control-Allow-Origin: *" header in a controller action (CORS issues)

I send a POST request from a headless frontend to a craft controller action but the request is not going trough because of: Cross-Origin Request Blocked: The Same Origin Policy disallows reading the ...
Merc's user avatar
  • 211
1 vote
1 answer
157 views

Custom validation rules on user signup

I'm trying to add some rules for users signing up. The first two (fullName and email) work fine. However, the password rules are triggered no matter what. Even if the passwords match and are over 8 ...
supazu's user avatar
  • 526
1 vote
1 answer
177 views

Add rows to table field

I'm having some trouble adding a row to a table field programmatically. I'm iterating over a table inside a Matrix field and would like to save those values to another table (if that makes sense.) ...
supazu's user avatar
  • 526
1 vote
3 answers
420 views

Change asset title and filename on upload

I'm trying to rename files uploaded by users on the frontend. Changing the title is working, but I can't rename the file. Would appreciate some help! Event::on( Asset::class,Asset::...
supazu's user avatar
  • 526
1 vote
1 answer
337 views

How to access craft custom variable from PHP

We are using a custom variable initalized like this in our module: Event::on(CraftVariable::class, CraftVariable::EVENT_INIT, function (Event $event) { /** @var CraftVariable $...
Matthias Redl-Mann's user avatar
2 votes
1 answer
146 views

extending the Craft control panel templates are unstyled

First time building a custom control panel dashboard for a module. Template loads ok but is unstyled and not loading JS that the rest of the control panel screens do. {% extends "_layouts/cp"...
Steven Grant's user avatar
  • 1,855
1 vote
1 answer
110 views

Set asset volume dynamically via module depending on uploaded file kind

I'm trying to set the asset volume dynamically for new assets, using a module. I would like the volume to be based on the asset's file kind – in my case, automatically putting MP4s into a 'Videos' ...
Josh Harrison's user avatar
1 vote
2 answers
109 views

Add to / remove from user group

I have a profile form with a select menu for a user to choose their nearest location (a Category group.) A user will select their nearest location, it will add the category to their profile and then ...
supazu's user avatar
  • 526
1 vote
1 answer
43 views

Count consecutive years in Tag array in a module

I'm coming back to this question after some time because I feel like I have a bit more knowledge to be able to tackle it. Starting from Andy's pseudo-code, this is what I've got and it seems to be ...
supazu's user avatar
  • 526
0 votes
2 answers
346 views

Setting up and understanding a controller

I'm trying to set up a module with a controller as bit of a learning tool. The learning is not going well so far. Here is my setup: - modules - - site - - - playing - - - - Playing.php - - - - ...
supazu's user avatar
  • 526
1 vote
1 answer
367 views

502 Bad Gateway when updating expiry date via module

I'm guessing I'm doing something bad with my code and it's bringing down the server. Here is the full code: Event::on(Element::class, Element::EVENT_BEFORE_SAVE, function (ModelEvent $event) { if (...
supazu's user avatar
  • 526
1 vote
1 answer
61 views

Require Expiry Date

I'm trying to setup a module to require the Expiry Date on a specific Entry Type, borrowing from this question. Can anyone help me learn why my code is wrong? Event::on(Element::class, Element::...
supazu's user avatar
  • 526
1 vote
1 answer
174 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
2 votes
1 answer
859 views

$allowAnonymous must be array|int|bool

I'm using a module to add two actions to a form. When submitting the form I get this error. I have used pluginfactory to build this module. I am very new to modules/plugins, so if anyone knows more ...
aren's user avatar
  • 79
0 votes
1 answer
117 views

How to use twig macro inside controller?

I want to use the macro I defined in twig inside a controller or a module. Is that possible?
user's user avatar
  • 63
1 vote
1 answer
177 views

How to use twig function inside another module or plugin?

How to use twig function extensions inside another module or plugin? Say I created filterCats() twig function and it is already available in twig Is it possible to use it inside a module or plugin? ...
user's user avatar
  • 63
1 vote
1 answer
41 views

Reordering Matrix blocks by date in the control panel when saving an entry

I'm trying to reorder Matrix Blocks in date order when saving an entry in the control panel. I kind of have it working using the following code. My Matrix field is 'events'. Each block contains a date ...
Lewis Jenkins's user avatar
1 vote
1 answer
97 views

How do I allow a user to edit another users data via module?

I'm attempting to allow a user to edit other users via a front-end form. The "Edit users" permission has been checked in the admin but when I submit the form the data doesn't save. For this ...
Mike Niland's user avatar
3 votes
1 answer
189 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->...
Steven Grant's user avatar
  • 1,855
1 vote
1 answer
216 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 ...
Steven Grant's user avatar
  • 1,855
1 vote
2 answers
173 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 ...
Brimby's user avatar
  • 343
2 votes
1 answer
853 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 ...
iamkeir's user avatar
  • 468
1 vote
1 answer
104 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 ...
Mike Niland's user avatar