A message from our CEO about the future of Stack Overflow and Stack Exchange. Read now.

Questions tagged [plugin-development]

Questions having to do with constructing plugins.

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

After calling the controller method error from template. Craft CMS 3

https://prnt.sc/qqs50o I use the base plugin template from plugin factory.
2
votes
1answer
38 views

How can I write a PHP script to zip and download an Assets subfolder?

I've searched everywhere but can't seem to get a straight answer. I want to write a php script to zip and download an entire subfolder in my assets directory. The subfolders are named based on a ...
0
votes
0answers
22 views

Get the current Entry data in PHP

I need to get the current page entry data in PHP just like twig {{ entry.fieldHandle }} or {{ entry.id }} . I will be using this in a custom module function like in the example below. // Example ...
1
vote
1answer
14 views

How can I access the Gateways services?

I have been trying to access craft\commerce\services\Gateways; from a plugin but I can't figure out how I need to access it. I've used the following: $gateways = Commerce::getInstance()->commerce-&...
1
vote
1answer
13 views

Updating global set from controller

This is my code: $giveaway = Craft::$app->globals->getSetByHandle('promotions'); $giveaway->giveawayName = "New Name"; $success = Craft::$app->globals->saveSet($giveaway); return($...
1
vote
1answer
20 views

\ns\prefix\Plugin::getInstance() returns null from another plugin in Craft 3

I'm building a plugin that extends the functionality of the Contact Form Tuner plugin and customize the email recipients based on different scenarios. The email addresses need to be managed in the ...
1
vote
1answer
32 views

Choose not to save an element on EVENT_BEFORE_SAVE_ELEMENT

I want to do some server side checks to see if the entry should be saved or not. In my plugin I have something like that Event::on( Elements::class, Elements::EVENT_BEFORE_SAVE_ELEMENT, ...
0
votes
0answers
16 views

Craft3 DateTime is updating todays date on element save

I have an issue where my new element is saving with the current date and time. I won't want it to save with any kind of date/timestamp. Does craft just automatically put in the current date and time ...
1
vote
1answer
11 views

Craft 3 replacement for the Craft 2 fileCache component?

I'm upgrading a plugin from Craft 2 to Craft 3 and it looks like the fileCache component is no more. What has replaced it in Craft 3?
1
vote
1answer
29 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
21 views

ElementAPI: How to trigger the Custom service php file when a endpoint is loaded

I am Using Craft 3.3.11 version I have a php file in plugin/elementapi/src/services/EapiServices.php and the same file within vendor/craftcms/element-api/src/services/EapiServices.php When ...
0
votes
0answers
19 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
1answer
40 views

Frontend form validation

I need to validate the form submitted at the frontend by applying additional validation rules. For that I have created the plugin that listens to "EVENT_BEFORE_SAVE_ENTRY" event and should validate ...
0
votes
0answers
17 views

Create an entry type on plugin install

When a user installs my plugin, I would like the plugin to create an entry type on install. First of all, is this possible? If so, can someone point me in the direction of where I would find ...
1
vote
1answer
21 views

Craft 3 plugin - how to update entry with field of Entries type

Using PHP, I want to update a field of Entries type of an existing entry. Fields of type Text and Number will update with the following code: $entry = Entry::find()->id($entryId)->one(); $...
0
votes
0answers
13 views

Cannot declare class TwigTransformer, because the name is already in use

Within the source code of my plugin I needed to check if another plugin was installed. To do that, I needed to access plugins class. What is the difference between: class Something{ public ...
1
vote
0answers
16 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 ...
0
votes
0answers
27 views

Contact form plugin ajax submit URL not working

I am using contact form plugin for forms in my craft website. For avoiding page redirection, I followed ajax submit for the form, but it is not redirected to controller code. My form is as below:- ...
1
vote
0answers
16 views

Modify preview targets and save them

I'm using the following Event hook : Event::on(Entry::class, Entry::EVENT_REGISTER_PREVIEW_TARGETS, function ($event) { } The $event variable contains an array with the current $previewTargets as ...
0
votes
1answer
33 views

How to identify the recurring payments that happen after the initial subs creation payment the in Commerce Subs

I've got a custom module that I have written to inject data into various places in my site when events happen with Commerce Subs. As per the question title, I need to update an entry when a recurring ...
2
votes
2answers
59 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 ...
1
vote
1answer
37 views

Craft 3 - Plugin - Override Control Panel column values for field or field types

How can I override the column value for a plugin in the Craft CMS control panel? For example: Append "Hello " in front of a particular column value, or add hyperlink HTML markup to a value, in each ...
2
votes
1answer
37 views

Craft 2 FormBuilder 2 equivalent plugin in Craft 3

Is there any plugin equivalent to Craft 2 FormBuilder 2 plugin in Craft 3? My Craft 2 website forms are built with FormBuilder 2. I upgraded the website to Craft 3, but FormBuilder 2 is not working. I ...
2
votes
1answer
36 views

Finding the correct actions url

struggling to decipher how to link a plugins controller to an action route. The docs say to use "https://pluginfactory.io/" to scaffold one, but what it generates is a different structure to what the ...
1
vote
1answer
34 views

“Redactor plugin not found” – How to properly implement Craft plugins providing Redactor plugins?

TL;DR What is the correct/recommended way to implement a Redactor plugin within a Craft plugin? My intention I'd like to implement a Craft CMS 3 plugin that adds a new Reactor plugin. Normally (...
3
votes
1answer
65 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
20 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 ...
0
votes
0answers
9 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
44 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
36 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
45 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
30 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
2answers
47 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
27 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
32 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
29 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
24 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
29 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
21 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
49 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
81 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
18 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
31 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
43 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
19 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
28 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
29 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
42 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
86 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 ...