Questions tagged [modules]

Questions related to Craft 3 Yii Module Development

186 questions
3
votes
3 answers

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 be working fine. Except Craft throws a "Invalid…
Mark Lloyd
  • 93
  • 3
3
votes
3 answers

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 ExampleController.php: public function…
Dan Madoni
  • 121
  • 7
3
votes
2 answers

Getting a 'ReflectionException' error, "Class modules\Module does not exist' when I change the namespace of my module in Craft 3

First attempt at making a module. So far all I've done is try to change the namespace of the template that was included with my freshly installed craft 3.0.23.1 project. Was following the official docs…
3
votes
2 answers

Basic Module Tutorial or Example

I am having a difficult time understanding how to output even a simple variable using a module. Ultimately I have PHP code that I need to execute to generate a PDF. I managed to do this in V2.5. I'm following all the tutorials that I can find, bu…
2
votes
2 answers

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 1234@mysite.com where 1234 is the User ID. It's completely illogical, but is it possible to get…
supazu
  • 576
  • 4
  • 12
2
votes
1 answer

$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 about this that would be very helpfull. Thanks in…
aren
  • 79
  • 5
2
votes
1 answer

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\ExifReturn", even though the update did actually…
Tyssen
  • 653
  • 5
  • 12
2
votes
1 answer

Module not loading unless bootstrapped

I'm expanding my Craft website with a small Module, internal to this project. The module currently only defines a new input-field (extending craft\base\Field). I have dumped the autoloader from composer and my config/app.php only contains the…
Lukas Knuth
  • 131
  • 4
1
vote
1 answer

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 this: $pass = new…
supazu
  • 576
  • 4
  • 12
1
vote
1 answer

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 the current year. So for example, a user with 2023,…
supazu
  • 576
  • 4
  • 12
1
vote
2 answers

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 an email. I used the command line craft commands…
aren
  • 79
  • 5
1
vote
1 answer

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 and checkbox correct. See image: The idea being…
supazu
  • 576
  • 4
  • 12
1
vote
1 answer

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 characters, it still fails. Event::on(User::class,…
supazu
  • 576
  • 4
  • 12
1
vote
2 answers

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 add them to the corresponding User group. I would…
supazu
  • 576
  • 4
  • 12
1
vote
1 answer

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 working ok, but I wonder if there's a better way to…
supazu
  • 576
  • 4
  • 12
1
2