Questions tagged [plugin-development]

Questions having to do with constructing plugins.

Filter by
Sorted by
Tagged with
1
vote
2answers
32 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
12 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
12 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
11 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
25 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
1answer
44 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
22 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
18 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
17 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
6 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 ...
0
votes
0answers
16 views

How do I get the site from the dropdown in the control panel?

Is there an easy way to fetch the selected site of the dropdown (the one an editor would use to switch the site) in control panel in a plugin? The only way I found so far is to get the last segment ...
0
votes
0answers
11 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
12 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
35 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
16 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
27 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
55 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
37 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
156 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
28 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
18 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
6 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
21 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
13 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
31 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
27 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
15 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
30 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
19 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
28 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
97 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 ...
1
vote
1answer
26 views

Merge trashed element with existing one

Is there any way to merge trashed elements with an existing element? I'm creating a custom restore action so you can merge a trashed (commerce) Product with an existing one. The mergeElementsByIds ...
0
votes
0answers
44 views

How to hook into root controller to redirect any route based on some criteria?

We have a use case where if our user account has a certain flag that they are redirected to a specific page. Is there a way to hook into the root controller or some sort of router mechanism such that ...
1
vote
1answer
24 views

Craft 3 Plugin Index No Template Found

I'm looking to have a basic index page for my plugin, yet I can't seem to get index.html working for my plugin. But when I head to site.local/admin/plugin it displays 404 Template Not Found I have ...
0
votes
0answers
16 views

How to access controller method from a plugin script?

I have created a custom TwigParser which needs to execute some controller logic in a similar way to how CraftCMS's {% requirePermissionNode %} Twig parser does. Their implementation accesses the ...
1
vote
0answers
20 views

Query element api (output) via plugin

Is there a way to fetch the content generated by the Element API via a plugin. For example, if we have created an ingredients/<slug:{slug}>.json endpoint, can the data for a specific page (eg ...
1
vote
1answer
33 views

Changing some letters in entry's uri before save it

I need to replace some characters in my entry's URI because we have some letters which do not exist in English like "ş" or "ç". It is a problem for SEO and we have to change each time manually. I ...
0
votes
0answers
45 views

Category select field in custom plugin settings not saving

I am trying to show a list of categories on my plugin's settings page so an admin can select multiple categories. I am doing this with a Craft form macro: {{ forms.elementSelectField({ label: '...
1
vote
0answers
39 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
0answers
27 views

Custom field value doesn't get saved

I have the following code: $fieldHandle = 'contentLead'; $entryTitle = $event->element; $entryQuery = \craft\elements\Entry::find(); $entries = $entryQuery->title($entryTitle)->limit(1); ...
0
votes
0answers
38 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 ...
0
votes
0answers
8 views

How do you access craft()->runController variables within the action?

I have a plugin that runs craft()->runController($actionUrl); This runs the action Controller of a separate plugin. The actionUrl contains a variables array: $actionUrl = UrlHelper::...
1
vote
2answers
32 views

Get all available fields in plugin setting page

I am trying to get all the fields created by admin in my custom plugin setting page. As we can get entries , in same way can we have option to get the available fields. {{ forms.elementSelectField({...
1
vote
1answer
27 views

Draft from front-end form with limited field set

I have a front-end form which sends a limited selection of the fields to the action entryRevisions/saveDraft (actually a custom plugin action, but in the it end up there). I expected it to take the ...
0
votes
0answers
27 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
32 views

Batch saving a custom field to multiple users via controller

I have to build a custom plugin for an internal user management system/data export that needs to be able to get triggered from the CP. I basically have to sort a big amount of users (1500+) in a ...
0
votes
0answers
22 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
23 views

How can I overwrite the search page within a plugin?

My first day with Craft. I want to create a plugin that will provide a Product Query (collection, Craft Commerce) based on some 3rd party search (like Algolia). How can I overwrite the route search?...