Questions tagged [modules]
Questions related to Craft 3 Yii Module Development
171
questions
0
votes
1
answer
30
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 ...
1
vote
1
answer
29
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 ...
1
vote
2
answers
53
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 ...
1
vote
1
answer
53
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 ...
1
vote
1
answer
94
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
15
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 ...
0
votes
0
answers
36
views
Programmatically change value of plaintextfield in matrixblock on Entry presave Event
I'm new to craft cms and try to write a module which should hook into the EVENT_BEFORE_SAVE and change the value of a plaintext field within a matrix block. Therefore I've set up the Module just like ...
0
votes
0
answers
23
views
API get asset field handle after upload
I'v written a little module that renames an asset once uploaded, but I am struggling to figure out how to find the handle of the field it was uploaded from.
This so I can limit this renaming to a ...
0
votes
0
answers
25
views
Programmatically enable an entry for all sites if Enabled in one site
In a multi-sites setup, I have a Channel where Entries are not enabled by default.
When a CP user review them, I would like that they are automatically enabled in all sites without having to enable ...
1
vote
1
answer
39
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 ...
1
vote
1
answer
65
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.)
...
1
vote
3
answers
106
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::...
1
vote
1
answer
102
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 $...
2
votes
1
answer
79
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"...
0
votes
0
answers
14
views
Execute GraphQL query from module on full schema
I know Craft adds a gql function to twig that enables us to load data from the cms in json format into our templates. What is the best way of achieving the same thing in the context of a module?
I am ...
1
vote
1
answer
33
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' ...
1
vote
2
answers
90
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 ...
1
vote
1
answer
39
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 ...
0
votes
2
answers
78
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
- - - - ...
0
votes
1
answer
111
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 (...
0
votes
1
answer
22
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::...
1
vote
1
answer
47
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
387
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 ...
0
votes
1
answer
49
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?
1
vote
1
answer
61
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? ...
1
vote
1
answer
25
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 ...
1
vote
1
answer
72
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 ...
2
votes
1
answer
103
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->...
1
vote
1
answer
102
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 ...
1
vote
2
answers
91
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 ...
2
votes
1
answer
372
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 ...
1
vote
1
answer
59
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 ...
1
vote
1
answer
34
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 ...
1
vote
1
answer
150
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 ...
1
vote
1
answer
135
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 ...
0
votes
0
answers
51
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
...
1
vote
1
answer
488
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. ...
1
vote
1
answer
64
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, ...
1
vote
1
answer
60
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 ...
1
vote
1
answer
40
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/...
1
vote
1
answer
306
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 ...
0
votes
0
answers
221
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. ...
2
votes
1
answer
118
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 ...
2
votes
2
answers
97
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 ...
0
votes
0
answers
123
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 ...
0
votes
1
answer
231
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 ...
0
votes
2
answers
272
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 ...
0
votes
0
answers
191
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 ...
2
votes
2
answers
736
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 ...
2
votes
1
answer
145
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 ...