Skip to main content

Questions tagged [modules]

Questions related to Craft 3 Yii Module Development

Filter by
Sorted by
Tagged with
0 votes
1 answer
170 views

Create different types of Donation purchasable? (for Gift Aid etc)

The new donations purchasable looks super handy for charity websites, thank you for this :) In the UK we have a thing called Gift Aid that allows charities to claim an extra 25% on donations/...
James Greig's user avatar
1 vote
1 answer
576 views

How to pragmatically set registered user status to pending and then manually send activation email

I have 2 front end registration forms. One for normal users and one for admins. In each form I have a hidden input with a group value like so: <input type="hidden" name="group" value="ypo"> In ...
Lukigi's user avatar
  • 565
1 vote
0 answers
238 views

How do I use a relation field in an element?

Currently I have a field that extends BaseRelationField, and 2 types of elements. I want the field on elements A to be able to select from elements B. So far the field itself works, which I tested by ...
bastiaanwuisman's user avatar
2 votes
2 answers
203 views

Unable to register adjuster in module

Following https://docs.craftcms.com/commerce/v2/adjusters.html I am unable to register an adjuster in my module. in my Module.php file I have placed the following inside init() alongside other stuff ...
Stian Karlsen's user avatar
1 vote
1 answer
631 views

How can I load the templates from a module?

I'm creating a module that contains some predefined templates. How can I load them directly out of the vendor folder? I've tried doing Event::on(View::class, View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS,...
Jorge Anzola's user avatar
1 vote
3 answers
2k views

How to change an entry's slug on EVENT_AFTER_SAVE_ELEMENT?

My entries' titles are auto-generated from several fields values on first save. When one of these fields values change, I would like to update the auto-generated slug also: Event::on( \craft\...
Romain P.'s user avatar
  • 1,852
2 votes
1 answer
446 views

Element API calling Module that integrates with third-party plugin

This is probably a bit niche but anyone especially au fait with the element api here? On project X I have a custom module within which I am referencing a service from another plugin (bolden/google-...
Cole Henley's user avatar
  • 1,741
1 vote
1 answer
523 views

How to duplicate a matrix field programatically in Craft 3.1?

Is there a "Craft" way of handling this in 3.1? Solutions to this question on SE are based on older versions of Craft which no longer work. Custom fields can be duplicated by doing: $newEntry->...
Warmbeat's user avatar
2 votes
2 answers
243 views

How do I prevent a controller from creating unwanted routes?

I have a custom module that is adding sections to the CP, like this: // Register CP routes Event::on( UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, function(craft\events\...
benface's user avatar
  • 226
1 vote
2 answers
98 views

TwigExtension added to Craft don’t work in emails

I added tomodomo/twig-pluralize-extension to my project composer, loaded with a custom module like that : if (Craft::$app->request->getIsSiteRequest()) { // Add in our Twig extension $...
Maxime Lafrenière's user avatar
1 vote
1 answer
1k views

Integrating Yii 2 modules and frontend widgets with Craft CMS 3

I'm experienced in Yii2 framework, but I just discovered Craft CMS and I already love it. I use to develop Yii 2 modules using their own DB tables, models, controllers and views. I usually use Yii ...
Alain Rollmann's user avatar
2 votes
1 answer
2k views

How do I create console commands for my module or plugin?

I would like to create a custom console command for my Craft 3 plugin. I've looked at the Yii docs and understand commands are defined using controllers extending \yii\console\Controller but cannot ...
Mike's user avatar
  • 277
1 vote
1 answer
750 views

Incorrectly setting module template variable

Getting error: Calling unknown method: craft\web\twig\variables\CraftVariable::markAsReadModule() Trying to use a template variable that I created in my Craft 3 module, I use this module for ...
Brad's user avatar
  • 487
1 vote
1 answer
1k views

How do I delete an asset with module or plugin

I'm trying to clean-up the assets in a specific folder that aren't being used at all, i.e. aren't related to anything. I got the list O.K. just using this $assets = Asset::find()->volume('artists'...
Keith Mancuso's user avatar
2 votes
1 answer
205 views

Some (but not all) controller action routes return 404 on staging server

I've created a module for a project that has several actions, all of which are called through AJAX. Each is a post request that sends over any required params plus the CSRF token using the method ...
slander's user avatar
  • 73
1 vote
0 answers
82 views

Installing module via composer

I followed this question like: ... "repositories": [{ "type": "vcs", "url": "[email protected]:jorgeanzola/mymodule.git" } ], ... "require": { "craftcms/cms": "^3.0.0", ... "...
Jorge Anzola's user avatar
1 vote
1 answer
230 views

List Modules in Craft System Report

Plugins and application information is detailed in the system report. Is it possible to get my module to list itself there? And if not, is there somewhere else in the CMS to see modules that a ...
Ian Nebbiolo's user avatar
1 vote
1 answer
380 views

How can I conditionally resave entries based on the value of an entry's field in a Craft 3 Module/Plugin?

Scenario: I want to programatically bulk resave entries in a certain Site in a certain Section of a certain Type. I have a Craft 3 Module with a Console Controller containing following code: public ...
Andrea DeMers's user avatar
3 votes
1 answer
361 views

Craft 3 Custom Field Type with a File Uploader

I have a custom field type I am porting from Craft 2 to Craft 3. This field type used prepValueFromPost to grab a reference to a just uploaded file and then saves said file to an appropriate place ...
Jeremy Daalder's user avatar
2 votes
1 answer
874 views

How can I set new user accounts to pending status in a Craft 3 module?

I have the following code in my site module: Event::on( User::class, User::EVENT_BEFORE_SAVE, function (ModelEvent $event) { /** @var User $user */ $user = $event->...
Andrea DeMers's user avatar
2 votes
1 answer
229 views

Module: EVENT_AFTER_SAVE_ELEMENT won't detect changed user group

Event::on(\craft\services\Elements::class, \craft\services\Elements::EVENT_AFTER_SAVE_ELEMENT, function(Event $event) { if ($event->element instanceof \craft\elements\User) { $user = ...
Stian Karlsen's user avatar
1 vote
1 answer
148 views

Demo repo for an Adjuster module for Commerce 2?

Would it be possible for someone to create a demo of a barebones Adjuster module, similar to https://github.com/cliveportman/craftcommerce-adjuster but for Commerce 2? I'm trying to follow the docs ...
James Greig's user avatar
1 vote
2 answers
301 views

Craft CMS module composer dependancy

After some research surrounding this I can't seem to fix this issue. So for a project I made a simple module with some variables that simply has to make an OAuth1 call and return some data. The ...
Stef Dg's user avatar
  • 43
2 votes
1 answer
753 views

How can I rename an asset file on upload when an entry is saved (Craft 3)?

I have an entry type that includes an Assets field. When this entry is created/saved via the CP or a front-end form, I want to rename the Asset file as follows: Entry's author id. E.g: 148 01, 02, 03 ...
Andrea DeMers's user avatar
0 votes
0 answers
318 views

How to exclude some fields from the searchindex using the RegisterElementSearchableAttributesEvent event?

Context I had big issues on a Craft 2 multilingual site with dozens of thousands of entries that were using Matrix fields. The site had become extremely slow (almost unusable), especially when ...
Romain P.'s user avatar
  • 1,852
1 vote
3 answers
970 views

How can I use the entry UID in the entry URI

The entries in my Craft app need a unique ‘non-guessable’ URL, so I figured I could use the UID in the URI of the entry. So in the section, where I need to provide the URI format I entered "section-...
Dries's user avatar
  • 35
1 vote
1 answer
145 views

How to enable changing the status of my own Element Type

So i have created my own Element Type and enabled statuses with the hasStatuses() method. In the ControlPanel its shown that each element has its own status, but it cant be changed. See image below: ...
Leonardo's user avatar
  • 471
1 vote
0 answers
72 views

Get fields of requested entry in module

Instead of writing a lot of logic in twig in my template, I tried to create a service and get the fields related to the requested entry in a module. I then want to create a new twig variable to output ...
mcoze's user avatar
  • 11
3 votes
2 answers
2k views

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 ...
MrMagicalBananaful's user avatar
0 votes
0 answers
42 views

Is there a callback for post Craft 3 CMS installation I can use?

I was hoping to have my module create a few fields, sections, and entries after the Craft 3 CMS has completed it's installation. Is there a callback I can listen to that triggers after the CMS is ...
Mark Notton's user avatar
  • 2,337
3 votes
2 answers
2k views

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 ...
Danny Valle's user avatar
0 votes
1 answer
762 views

Removing "action" from a module's route. Is it possible?

I have a module with a route that looks like this: http://localhost/actions/module/controller/action Is it possible to set up a custom route within my module so I can send people to: http://...
Tony DeStefano's user avatar
1 vote
1 answer
2k views

"Template Not Found" error when trying to access a module controller action

I'm a total Craft newbie, so I hope this question isn't ridiculous. I just want to see a controller / action work in my new module. I have src/controllers/ScrapeController.php as such: <?php ...
Tony DeStefano's user avatar
6 votes
1 answer
2k views

Running module migrations

I must be missing something or not understanding something. I'm trying to build a module for an install, and I'd like to run the initial migration. So the module initial install migration for the DB ...
jrothafer's user avatar
  • 305
3 votes
1 answer
3k views

How to render a template from within a module?

I'm currently developing a module that contains a custom field and I'd like to create a template to be used in the getInputHtml method. I try using the Craft::$app->view->renderTemplate method ...
kant312's user avatar
  • 496
1 vote
1 answer
328 views

How to develop plugin/module to build landingpage upon fetched JSON-data

I've developed an app which fetches data from an API based on Laravel 5.5. The marketing landingpage of the app is based on Craft CMS Version 3. The marketing website and the API and the databases of ...
rakete's user avatar
  • 91
5 votes
1 answer
1k views

How can I install modules with Composer?

Installing a Craft 3 plugin via Composer is pretty simple. You require the package, update Composer, and install it via the CMS. My circumstances require that our company use a private Module on all ...
Mark Notton's user avatar
  • 2,337
2 votes
1 answer
912 views

Craft 3 attachment email

I need to add an "attachment" to an email sent by Craft CMS 3. I used a custom "Module" for this with a "Model", "Service", "Record" and "Controller" I did some research but did not find any clear ...
Lofka's user avatar
  • 21
2 votes
1 answer
456 views

Yii Modules in Craft, samples?

Does anybody know of a collection or library of Yii Modules online? I'm trying to understand how easy they can be moved from one application to another, are we going to see something similar to the ...
cballenar's user avatar
  • 1,409
2 votes
1 answer
3k views

How to call Controller in Module?

I'm very new to craft and I'm having trouble finding an answer to my question (I've scoured the questions on here - but the only answers appear to be for plugins). Basically, I want to submit a form ...
matt's user avatar
  • 21
1 vote
1 answer
1k views

Return the contents of a template from a custom Twig function in a module?

I have a template that outputs some JSON formatted data. I've built a simple module that needs to get the contents of that template, decode the JSON data, and return it. I believe I need to use ...
Pete H's user avatar
  • 90
1 vote
1 answer
664 views

How do I load composer dependencies for a Yii module that's in my site repo?

I have a site-specific module in my modules directory that's being loaded in config/app.php. Since it won't be used elsewhere I am not storing the module in an external repository. When I added a ...
Jeremy Gimbel's user avatar

1 2 3
4