Questions tagged [modules]

Questions related to Craft 3 Yii Module Development

Filter by
Sorted by
Tagged with
1
vote
1answer
25 views

Use sidebar nav icons in modules and plugins

When adding a navigation item, there is the option to specify an icon, but it seems to have to be a path to an SVG. I can see that Craft has its own icon library, and it has an icon I want to use. I ...
0
votes
0answers
17 views

Save and log in a user from event callback

I'm trying to build a plugin wherein after a user is created via the normal means via a front end template, the user is immediately logged in. My module is watching for the after save event on ...
1
vote
0answers
12 views

Conditionally attach behaviors to craft\elements\Entry by section

I'm trying to conditionally attach behaviors based on an entries section. The following code works fine, but I'm trying to clarify one bit: To avoid a yii\base\InvalidConfigException on the CP ...
2
votes
2answers
52 views

Trigger FeedMe import from plugin

I'm importing Real Estate properties every 30 minutes into my website. I have a controller action that triggers this but the import is extremely slow and blocks the entire site. Right now I'm ...
3
votes
1answer
63 views

Restrict Sources on element select field

I'm building a module with a form that includes an element select field that I want to restrict to specific volume. So far this is what I have: {{ forms.elementSelectField({ label: "Asset"|t('app'...
0
votes
0answers
19 views

Craft 3 match all categories using relatedTo in a module controller

I am trying to perform an entry query using relatedTo to get entries that match all categories. I know how to achieve this with 'and' in twig but I can't seem to find the correct syntax to use in a ...
1
vote
1answer
39 views

Redirect to template from controller and pass data

I am building a custom login process which follow these steps: Request user email (submits to custom controller) Check if user has an account If they have an account, show a form requesting their ...
1
vote
1answer
27 views

Accessing named parameter in custom route from within a controller

I have a custom module in which I am setting a front end route that routes through to a controller. Like so: Event::on( UrlManager::class, UrlManager::EVENT_REGISTER_SITE_URL_RULES, ...
1
vote
0answers
25 views

How can I override the Response status text from a controller?

I'm trying to set the statusText in a response, from a module controller. E.g.: <?php namespace modules\appmodule\controllers; use Craft; use craft\web\Response; class StatusController extends ...
1
vote
1answer
13 views

PS-4 Autloading custom module

I have created a module in modules/Core.php which works great and I can reference it using modules\Core::class. But I want to re-organise my modules. I'm not super familiar with PSR-4 loading but I ...
1
vote
1answer
20 views

How to set field values for the table field type in Craft 3

I'm trying to insert an entry along with values for a table field. According to the docs, the setFieldValues method takes an array of values in the format handle => value, but it doesn't specify ...
1
vote
0answers
46 views

Craft Commerce Adjuster API/PHP questions

I've got a module set up to add discounts based on criteria defined in a category group (handle 'productPacks') -> category (which is a "pack"). Now, everything works great for one type of pack, and ...
0
votes
0answers
37 views

Set field value of table field within matrix in a module?

I have a matrix called 'Election' with the structure: Block: role - Text field: roleName - Table field: candidates -- Text field: fullName -- Number field: votes My module can edit the roleName ...
2
votes
2answers
92 views

Trouble parsing JSON with getBodyParams()

I'm trying to use getBodyParams() to parse a JSON posted to a module controller action from an API. The incoming headers have content-type set as application/json; charset=utf-8, and I've tested to ...
1
vote
2answers
89 views

How do I access the checkbox field column value as a PHP array?

I have a checkbox field for dining cuisine types and I see that the checked options are stored as a JSON-encoded array in the content table. If I have an element that uses this field, is there a way I ...
1
vote
1answer
31 views

Saving a SuperTable field within a Matrix Field

I am trying to save a SuperTable field that sits within a Matrix field. I have followed the docs as far as I can but for some reason the SuperTable data is not getting saved. My steps are as follows:...
1
vote
1answer
15 views

How can I set the isCompleted status of an order from within a custom module?

The default behaviour for commerce is to mark the isCompleted flag on an order to true once the order has been paid for. I have need to alter this behaviour and only want to mark an order as Complete ...
1
vote
1answer
94 views

Render template from Module in twig template

I have been searching around SE and the web in general for an answer to this. There seems to be plenty of solutions but none appear to be working for me. I have a simple module that has a variable ...
0
votes
0answers
19 views

Twig Include is displaying empty modules on page

I have a twig file called "Abilities.twig" inside abilities I have the below code: <p>{{ module.Ability }}</p> In the CMS I have a field set named "modals" with the field block "...
1
vote
1answer
52 views

Add rows to editableTableField via custom javascript

I am making a custom field via a module. I have an editableTableField that will hold the actual field values saved to an entry and I have other HTML elements that are used to grab data from a ...
1
vote
1answer
106 views

Modifying Slug on FeedMe Import

I have the following Module loaded into my system, following the Event's on the FeedMe documentation I've implemented the following to change the slug per entry import but unfortunately, it's ...
1
vote
1answer
63 views

Trouble calling service methods from primary module class

I created a module for Craft 3 using pluginfactory.io, and am unable to call services from the primary module class using $this->orders->method() as shown in the documentation. The services ...
2
votes
1answer
36 views

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 ...
1
vote
1answer
32 views

Is it possible to create this type of custom field?

We need a field that holds assigned postal codes. Each Location entry will have this field and I'd like to have the following: Buttons to assign postals by city, state, county (data grabbed from ...
0
votes
0answers
35 views

How do you register template paths from a module or plugin when a console controller action is called?

When developing Craft 3 plugins/modules, we usually tie into the View::EVENT_REGISTER_CP_TEMPLATE_ROOTS or View::EVENT_REGISTER_SITE_TEMPLATE_ROOTS RegisterTemplateRootsEvent events to register custom ...
0
votes
0answers
22 views

Rename files uploaded to certain sources in Craft 3

I have an event written for Craft 2 which renames files, which are uploaded to certain sources, to have a 35 character random string, plus its original extension. I am looking to update this for ...
0
votes
0answers
37 views

Hooking Event After Record Save

I have a custom module that is receiving data from an external API. I need to save some of that data into a record and return a success response, so far all is good. Along side this I want to set up ...
2
votes
1answer
43 views

Create Matrix Block via Module

I'm having an issue creating a matrix block from a module. I'm currently doing the following: Calling an API using Guzzle Getting that request and iterating over a media block. Trying to create a new ...
2
votes
1answer
515 views

“Failed to instantiate component or class” when calling Craft module

I created a module with the pluginfactory generator. The module is used for generating a zip file with all the files belonging to a project. In the composer.json file, I added the following: "...
1
vote
0answers
44 views

How do I correctly upload a new Asset from a temp file I generated from a service method?

Preamble Craft 3.1.26 PHP 7.2.8 on Mamp Pro 5.1.1 I browsed to my storage/reports folder and made sure in Finder than full read/write privileges are granted. What's goin on I have a module with a ...
0
votes
1answer
53 views

Call Module Function from Front End

I'm looking to call the following Module function from a front end form. I've looked through numerous answers but I can't seem to find a definitive answer on this. Here's my Module's code, but ...
0
votes
0answers
41 views

Change Dropdown Value via Module

I'm looking to change a dropdown field within an entry, then save it. I currently have a lightswitch which works perfectly, but now I need to change a dropdown field. I have the following for the ...
1
vote
2answers
155 views

Simple Module in Craft CMS 3

How do I create a simple module for one website in Craft?. I don't have much experience in Craft CMS. I have tried from 3 days but I cannot get an answer. I'm following all the tutorials that I can ...
0
votes
0answers
39 views

What's the difference between `checkboxGroupField` and `checkboxSelectField` in Craft 3?

Short: What exactly is the checkboxGroupField used for? And why not just using the checkboxSelectField? Long: I am building a library that's gonna be required by a couple of my future Craft plugins ...
1
vote
1answer
30 views

Add field to /settings/sites/new (multi-site)

I would like to add some fields to the site creation on the control panel settings. I know you can add globals for each site, but I think it would be a better process if I could add additional fields. ...
0
votes
0answers
26 views

How can I search for entries with precision in my module?

I'm working on an autocomplete Vue component for one of my Craft projects. It's very simple at the moment, all I am trying to do is have my component send a search value from the user to a controller. ...
0
votes
0answers
47 views

Get transformed asset URL in controller of module, while using Eager Loading

I created a module, in my controller I want to return the entries with the assets in JSON format. Here is my code. File: In service class, I am getting the data. public function getData($...
1
vote
1answer
233 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
190 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 ...
1
vote
1answer
205 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 $...
1
vote
0answers
41 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 ...
0
votes
1answer
74 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
112 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
61 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
1answer
51 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
134 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,...
1
vote
3answers
271 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\...
2
votes
1answer
203 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
85 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->...
2
votes
2answers
65 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\...