The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [plugin-development]

Questions having to do with constructing plugins.

Filter by
Sorted by
Tagged with
0
votes
0answers
7 views

Commerce preferred currency - user/customer setting

Is there a way for users/customers to set a custom/preferred currency that would be applied to any future carts (assuming more than one currency was available)? Was looking at whether could do this ...
1
vote
1answer
28 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 ...
0
votes
0answers
30 views

How to get current site (locale) api / plugin

For my form plugin I'm using a global set of fields. These can be set in 2 languages default and en. Problem is whenever I try to output them I cant dynamically make them use the current site locale/...
1
vote
1answer
23 views

Calling Craft Console Commands from Plugin?

I am in the process of building a plugin that has a controller that accepts a HTTP request. If the token and request are valid, I would like to call a Craft Console Command from within the plugin (e.g....
1
vote
1answer
22 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, ...
0
votes
1answer
30 views

Eager loading category data from a Matrix block

How might I eager load category data in a plugin? I can't seem to figure out why I can't access a category in this way: locationOffers is a matrix block name, category is the handle of a related ...
1
vote
0answers
19 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 ...
0
votes
0answers
25 views

V3 Plugin to check user is new and skip email activation

I am new to craft development. I have a client looking to whitelabel their existing site but have new users added to a group and then be directed to a sub site of theirs. So, I am looking for a way ...
2
votes
1answer
23 views

How to get users with birthday today in plugin/module?

How does one retrieve users from Craft3 DB whose birthday is today? Birthdate field type is Date/Time. Have a working PHP/MySQL example, but unsure how to port this to Craft3 syntax. $sql = '...
1
vote
2answers
28 views

Doing something with the success response from a Webhook

Craft Webhooks is great for sending one POST to a service... but if you need to parse the response from that hook... is there a way to do that? I can't see it as any option in the plugin, and I can't ...
1
vote
1answer
14 views

Programatically add lines to a Super Table field

I am trying to add new lines into a SuperTable field of an entry from my plugin. Following the Developper sample, I am able to change set lines to this SuperTable field. But it is replacing the ...
0
votes
1answer
12 views

Plugin RegisterUrlRulesEvent - cannot find Controller aciton -> 404

The error I'm getting: HTTP 404 – Not Found – yii\web\NotFoundHttpException Page not found. ↵ Caused by: Invalid Route – yii\base\InvalidRouteException Unable to resolve the request "Expedweather/...
0
votes
0answers
18 views

Better way to manage local plugin in git

Not 100% Craft only, but I have a question on how best to manage code in git. I have a site and a plugin (only for my use), and I've just been doing some major revamp to the plugin, more or less a new ...
1
vote
1answer
22 views

Plugin RegisterUrlRulesEvent - Regex URL-Routing gives 404

I'm updating a Craft 2 plugin to Craft 3 and I'm having difficulties getting the Regex URLs working correctly. The eocs I'm using: Craft3 Docs I used pluginfactory.io to create the basic craft3 ...
1
vote
1answer
57 views

Headless Craft CSRF

I have a site that is using Craft CMS headless and React. There are a few forms that need to post to controllers but I'm not sure how to set up the CSRF tokens and keep it secure. Can anyone advise ...
0
votes
0answers
13 views

Sort entries by related element in plugin

I am using a plugin to fetch Entry elements based on various criteria (eg to produce an array based on \craft\elements\Entry::find()). The section I am querying features a number of related ...
0
votes
0answers
25 views

Custom plugin - how to save settings featuring array?

I'm developing a custom plugin but hitting an issue when I want to save a settings that uses the multiSelect, checkboxSelect or checkboxGroup fields (essentially any field that saves values as an ...
1
vote
2answers
39 views

In a plugin, how to get entry status?

This seems like it should be simple to find, but where does Craft store the status of entries (lightswitch for enabled/disabled)? It doesn't seem to be a column in the entries table, and I can't ...
0
votes
0answers
18 views

EntryModel as model attribute doesn't get populated as model

I've created this custom plugin with a CP interface for a website running latest version of Craft 2. Each record in my custom table relates to an entry using an entryId. I've set up all the records ...
1
vote
1answer
21 views

Custom field plugin: Unable to find template / General custom field plugin information

I am still relatively new to Craft CMS. I am trying to make a custom field plugin for Craft 3 but I am struggling to understand why I can't render my form template. The fieldtype should render a map ...
1
vote
1answer
15 views

What is the appropriate way to query and Hard Delete existing Soft Deleted Elements for a Custom Element?

I have a Custom Element where the Soft Delete functionality is not necessary. Right now, existing users of this plugin may have thousands of Soft Deleted Elements in their Elements table that don't ...
3
votes
1answer
35 views

Entry element query missing user field data when user is suspended

I have a channel in which each channel entry has a "users" field type that is limited to one user. My code below works fine when the user is not suspended, however if I suspend the user, the then $...
1
vote
2answers
70 views

Send email with dedicated SMTP settings from a Craft 2 plugin

I have looked a lot for this but cannot find any dedicated solution. Basically I want to do this: How to send email from Craft 3 custom plugin? … but for a Craft 2 plugin. A how-to for the global ...
0
votes
0answers
23 views

Geocode address when saving custom field type in plugin

I've got a Craft CMS 3 plugin that has a custom field type for entering an address. When saving that field I'd like to take that address and geocode it using Google's Geocode API and save the latitude ...
0
votes
0answers
22 views

Is it possible to send Solspace Freeform mail with custom module?

I'd like to send mails from my custom module for Craft. But instead of Craft I want to use Solspace Freeforms plugin. Is it possible to send mails with this plugin outside of frontend?
0
votes
0answers
26 views

How to use a table field in custom plugin's settings (Craft 3)

I need a table field in my plugin's settings, but when I make 2 rows and save the settings, only the first row is shown when I go back to the settings page. When I dump the values, my second setting ...
0
votes
0answers
8 views

AssetBundle-related when installing a plugin via console and not via Cp

I have a plugin which registers an AssetBundle. The asset bundle itself is quite basic and only includes one JS-File. In the init() method of my plugin, I register the bundle: // registering the ...
2
votes
0answers
62 views

How do I get the Site/Revision/Draft in a field in the control panel?

Is there an easy way to fetch the selected Site, Revision and Draft of the dropdown (the one an editor would use to switch the Site/Revision/Draft) in control panel in a plugin? The only way I found ...
1
vote
1answer
21 views

Module Development - Get ID of a field within a Matrix field

I have a matrix field that has a Supertable matrix within it. I need to programatically get the ID of the field that is nested in the Matrix. I have the code below: $matrixField = Craft::$app->...
0
votes
0answers
13 views

Fetch the entries based on local time zone

I am trying to fetch the entries based on the local timezone. $entries = Entry::find(); $entries->section('news'); $timezone = new \DateTimeZone(Craft::$app->getTimeZone()); // current site ...
1
vote
1answer
49 views

$event->isNew not working as expected after Craft 3.2 update

Pre Craft 3.2, you could do something like this if you wanted to perform an action in the event you just saved a new entry: use craft\elements\Entry; use craft\events\ModelEvent; Event::on( ...
1
vote
1answer
18 views

Modify a field value before the element is saved

I have a simple plugin with a field that extends the Craft PlainText field. Is there some kind of function I can use to modify the field's submitted value before the element is saved? class myField ...
1
vote
1answer
28 views

Craft criteria for asset folders

In my plugin, I would like to search a folder. However, I cannot find any information about the criteria for folders. Are there any documentation or something? $n = Craft::$app->assets->...
0
votes
0answers
59 views

Setting “enabled for site” from a plugin

I have entries that propagate across multiple sites. Default value is enabled in general but disabled for all sites. I want it to be enabled for the site to which it was originally added (while ...
1
vote
0answers
33 views

Custom element from plugin in structure-like hierarchy

I'm working on a plugin that would require a custom element to have a hierarchy, as in, possibly have a parent set or not. Much like entries have when used in a structure. I've got my element set up ...
1
vote
1answer
40 views

User query in PHP does not work

I would like to get user query in my custom PHP plugin. According to this document, the code would be like this. https://docs.craftcms.com/v3/dev/element-queries/user-queries.html#example $...
2
votes
1answer
188 views

What are the different scenarios to plan for when using $allowAnonymous in a controller?

Craft 3.2 updates how the allowAnonymous behavior works. I have things working in our plugins but I don't understand the different syntaxes needed across our different allowAnonymous use cases. For ...
1
vote
1answer
37 views

HTML Email Template setting not working for reset password email

I'm on the latest release of craft 3.x. I have the HTML Email Template setting set to a twig file in my templates folder. When sending a test email the template is used to send the test email, however ...
1
vote
0answers
19 views

Storing complex field content (plugin)

I'm trying to work through some issues with the field content for our Maps plugin, but I'm not sure about the best way to go about it. Currently the value for each map field is stored as an element ...
0
votes
0answers
7 views

Unable to create new category groups in plugin

So, I'm writing a plugin to assist with a content migration which will be creating new category groups. I'm able to successfully run the plugin, and what's strange is that the category group does get ...
0
votes
0answers
23 views

Is it possible to know which fields have been changed when a user save an entry?

Event::on(Entry::class, Entry::EVENT_BEFORE_SAVE, function (ModelEvent $event) {}); What I can found in docs is EVENT_BEFORE_SAVE hook. But I can only get the updating entry from the params. Is it ...
0
votes
0answers
14 views

Entries are being saved even when I try to upload files with the wrong extension

My Image service function throws an exception and sends it to the Craft logger that the extension is invalid. But my entry is being saved even though the field is set to only allow images. I am ...
1
vote
1answer
35 views

Filter and sort Commerce products based on Matrix blocks

We have a website that uses Craft CMS v3.1.28 and Commerce v2.1.6.1. The below logic is implemented within a plugin and we're prepared to do custom implementations aka. prepared to go deep! I would ...
2
votes
1answer
33 views

How to run function after plugin installed?

How can I run a function when my plugin is installed? I tried SafeUp in migrations but it doesn't work.
1
vote
0answers
19 views

How to fire flash messages when using Event::on()?

I'm looking to hook into an Asset::EVENT_BEFORE_HANDLE_FILE event and toss up a JS flash error if it's above a certain file size. However, the registerJs() function never runs and I assume it's ...
1
vote
1answer
38 views

Get entries based on multiple fields in controller

I am trying to get the entries based on multiple fields. Fields can be of type tags, checkbox, radio box, and number. In my controller currently what I tried is. $extrafilter will be like Array ( ...
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 ...
1
vote
1answer
29 views

Loop through all created fields and get the field type

I want to show some input fields on frontend template form. Type of input is dependent on the type of fields selected on the backend. For example, if the text field is selected in the backend I ...
4
votes
1answer
111 views

How to order or filter entries by their author's custom field?

Is it possible to order and/or filter all entries from a section whose author has a custom field value that is set to "X"? Below is the starting code. in Twig: {% set elementQuery = craft.entries()...
0
votes
0answers
35 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 ...