Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [modules]

Questions related to Craft 3 Yii Module Development

0
votes
0answers
18 views

How do I correctly send an external request to a module controller? runAction() is returning null

Craft 3.1.18 I have a simple controller VeteransController made using the updated Business Logic module. The purpose of this controller is to create a very simple endpoint for an external Vue ...
1
vote
1answer
39 views

Custom module that can define and have settings referenced (Craft 3)

I'm currently working on migrating a Craft 2 project which has a bunch of bespoke custom plugins that provided various bits of additional functionality that's tailored to this project only. I've been ...
0
votes
1answer
31 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/...
1
vote
1answer
33 views

Modules - CP Template not found

I've used this tool to generate a module: https://pluginfactory.io/ So in my constructor, I have Event::on(View::class, View::EVENT_REGISTER_CP_TEMPLATE_ROOTS, function (RegisterTemplateRootsEvent $...
0
votes
0answers
21 views

Looping over categories, product variants, and subsequently applying adjuster(s)?

Using the Craft 3 and Commerce 2 APIs, how would one go about looping through products in the cart to apply adjusters, looking at the following example; A category, "Product Packs" is set up where ...
1
vote
1answer
48 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 ...
1
vote
0answers
21 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 ...
2
votes
0answers
33 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 ...
1
vote
1answer
32 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,...
3
votes
1answer
52 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-...
1
vote
1answer
37 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: <?php Event::on( \...
2
votes
2answers
37 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\...
2
votes
2answers
240 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 ...
1
vote
1answer
38 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->...
1
vote
2answers
23 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 $...
1
vote
1answer
102 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 ...
1
vote
1answer
163 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 ...
0
votes
0answers
37 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 ...
1
vote
1answer
45 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'...
2
votes
1answer
31 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 ...
2
votes
1answer
69 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 ...
1
vote
1answer
59 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 ...
1
vote
0answers
28 views

Installing module via composer

I followed this question like: ... "repositories": [{ "type": "vcs", "url": "git@bitbucket.org:jorgeanzola/mymodule.git" } ], ... "require": { "craftcms/cms": "^3.0.0", ... "...
0
votes
0answers
12 views

How to prevent Craft Admin from displaying “Leave site?” message for custom fields

I'm using custom fields provided by a Craft 3 Module to provide some Javascript-based functionality in the Craft Admin, and it includes some form elements, but the values of those form elements are ...
1
vote
1answer
36 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 ...
1
vote
1answer
39 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 = ...
2
votes
1answer
108 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->...
1
vote
1answer
110 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 ...
1
vote
1answer
61 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 ...
1
vote
2answers
35 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 ...
0
votes
0answers
57 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 ...
1
vote
2answers
124 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-...
1
vote
1answer
37 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: ...
1
vote
0answers
31 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 ...
0
votes
0answers
29 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 ...
1
vote
1answer
298 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 ...
0
votes
1answer
64 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://...
1
vote
1answer
329 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 ...
2
votes
1answer
325 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 ...
1
vote
1answer
483 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 ...
1
vote
1answer
97 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 ...
3
votes
1answer
300 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 ...
1
vote
1answer
86 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 ...
2
votes
1answer
235 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 ...
1
vote
1answer
771 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 ...
1
vote
1answer
226 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 ...
1
vote
1answer
275 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 ...