Questions tagged [plugin-development]

Questions having to do with constructing plugins.

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

Element type with 'baked-in' fields

I've created an element type and want to have a 'Categories' and 'Tags' field built-in (the sources for each will be selectable in settings), but can't figure out the best way to go about this whilst ...
1
vote
1answer
56 views

Creating a calendar event from within a plugin (stuck on saving)

I'm trying to create an event from within a plugin. I've come up with the following: $event = new Event(); // Solspace\Calendar\Elements\Event; $event->authorId = 1; $event->calendarId = 5; $...
1
vote
1answer
68 views

Eager load commerce order data in custom ElementExporter for Users

I have a custom ElementExporter for users and I'd like to include commerce order data. The below code works, but it's a ton of queries. I don't have a ton of experience with SQL queries, how can this ...
1
vote
1answer
23 views

Archiving custom element types

I am building a custom element type and want to have the ability to archive entries. I can create a custom status for 'archived' but I've noticed base elements already have an 'archived' status I ...
1
vote
0answers
59 views

Saving custom element types

i have created my first plugin and have hit a bit of a wall... its a plugin with a custom element type, i have it creating its own database table (migrations/install.php) and i have the form ...
1
vote
1answer
58 views

returning HTML in $event->sender->addErrors doesn't work

I have a plugin which is checking if there is a duplicate entry before save. I'm trying to give the user back an anchor to the entry which exists so my client can switch without searching for it in a ...
2
votes
1answer
38 views

Programatically setting dropdown options in a matrix

I'm building a Matrix field from within a module's migration. I can get all fields setup correctly except the options of either a Dropdown or Checkboxes field. $field = new \craft\fields\Matrix([ '...
1
vote
1answer
141 views

How to add a custom panel to the debug bar?

I'm working on porting a Yii2 component to Craft CMS as a plugin. This Yii2 component provides a debug bar custom panel that I'd like to enable in Craft CMS too. In classic Yii2 applications, this is ...
2
votes
2answers
140 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 ...
4
votes
1answer
507 views

Craft 3 Custom Plugin: model validation

Struggling a bit here - have created a custom plugin where I want to validate form submission against a predefined model before saving to the database. All pretty straightforward so far … However, if ...
1
vote
1answer
265 views

Rendering a template from a controller - unable to find template

Once again going out of my mind trying to figure something out... I have a custom controller which I want to return a rendered template. The template should, ideally, reside in my front end templates ...
2
votes
1answer
47 views

unsucessful setFieldValues after programatically creating field on a migration

as part of a migration script I'm trying to: create 2 new fields, add them to a field group add the new fields to a specific tab on an entry type Update the values of the new fields What I have so ...
2
votes
1answer
32 views

Licence error and update issue cause of same plugin name / handle

We developed a plugin with the name "poll" (composer.json: webhub/poll) for one single project. Now we get the licence error in the control panel, cause there is a plugin to buy which has ...
1
vote
1answer
30 views

Craft 2: possible to control plugin triggering order?

I have a Craft site which has 2 different plugins listening to the same event (the Contact Form beforeSend event). The outcome is one is being triggered before the other and this is causing issues. Is ...
1
vote
2answers
165 views

What is the best way to handle HTTP requests within a plugin using Yii or Craft?

I have a custom module which is moderating content before entry save, I am looking to use a Microsoft Azure API to handle the moderation, in their documentation they use a HTTP library to make the ...
0
votes
0answers
30 views

Saving to db with devMode true works, but not when false

// Upload and save as temp file $request = Craft::$app->request; $file = UploadedFile::getInstanceByName('file'); $tempPath = $file->saveAsTempFile(); // Create as permanent asset $folder = ...
0
votes
0answers
28 views

Timezone in Craft different from timezone in plugin

In general.php I've set 'timezone' => 'Europe/Oslo'. When saving entries through the CP they are saved with the correct time. Also, date_default_timezone_get() from my plugin returns Europe/Oslo. ...
1
vote
1answer
148 views

Tax validation in Craft Commerce

We have a single page checkout where the items are selected and addressed added before going to a cart summary page showing amount owed and tax due. Was confused as to why certain codes were not ...
1
vote
1answer
55 views

Looking to create a dropdown field to select an icon

I use the same icons across most of my projects, and typically just list them in Dropdown fields. However, this quickly becomes difficult to manage, so I'm looking to create a simple plugin that I can ...
2
votes
2answers
575 views

How to validate a unique field in Craft 3 element?

I'm trying to validate a custom Element in my Craft 3 plugin. Where should I be putting my validation rules? I have two classes: one for the Element, one for the ActiveRecord (e.g. Invoice and ...
1
vote
1answer
24 views

Craftnet API package query

Does querying composer packages via the Craftnet API need authentication? Ref https://docs.api.craftcms.com/packages.html Querying the Craft CMS package itself is fine, eg https://api.craftcms.com/v1/...
7
votes
2answers
1k views

How do you create a custom Twig tag?

Say I'm building a plugin that adds user memberships to the website. I want to check on my front end templates that user's membership is active and I have built the functionality inside the plugin to ...
2
votes
1answer
37 views

Dynamic postCpLoginRedirect based on user permissions

I'm wondering if it's possible to set the postCpLoginRedirect config setting dynamically during plugin initialization. Seems like that's a no-go, but wanted to confirm. Ideally, I'd like to ID users ...
1
vote
1answer
227 views

Equivalent of Records in Craft 3?

Trying to convert a plugin from Craft 2 to Craft 3, not sure what's the Records equivalent in Craft 3. How do I get this to work in C3? class SearchRelationshipRecord extends BaseRecord { public ...
1
vote
2answers
237 views

Commerce: Remove tax adjuster from line item in plugin

I need to remove adjusters from each line item if a certain condition is not met. I see that in the CP you can manually remove them by editing the line item but hunting down this code in Commerce's ...
1
vote
1answer
37 views

How to get my craft projectConfig settings inside JS on the front end

So I am trying to work with twig templates and I want to inject my project configuration in my js so I can use it. I can do this {% set admin_email = craft.app.projectConfig.get.email.fromEmail %} ...
1
vote
1answer
411 views

Register custom REST routes while building a plugin for Craft 3

I am building a custom plugin for Craft and I am hitting some REST APIs in my backend service to fetch some data using Ajax calls in JS. What I would like to do when the AJAX calls complete and come ...
1
vote
1answer
71 views

How to reset matrix field to have NO blocks in plugin?

I want to reset a matrix field to have no blocks in it. In a plugin, I would normally set a matrix field by doing something like this: $blocks = []; $i = 1; foreach ($itemsArray as $item) { $...
1
vote
3answers
130 views

How to add content to pages using a plugin?

I am developing a plugin for Craft 3. And I am trying to add some content to all pages in the CMS using this plugin. How can I do that? Is there a method or class call I can use for this? I am not ...
1
vote
1answer
258 views

Images not showing even after bundling them with asset bundle

So I am trying to build a simple plugin for Craft CMS and I am wish to use my assets in the twig template like css, js, images etc. From what I have read and understood from Asset Bundles, I have ...
1
vote
2answers
138 views

How to show flash message for Commerce order when changing status on listing page?

If I change an order's status to "Cancelled" (my custom order status I created), I want to ensure that the CP editors provide a "Cancellation Reason" from a dropdown field in the order. I've set up a ...
1
vote
1answer
43 views

Craft plugin or external application

My question is more conceptual than technical; I have a website who have two big topics, on is purely editorial (pages, articles, faq, ...), the other is basically a comparator based on user input ...
1
vote
1answer
104 views

How to use assets while building Craft CMS plugins?

I am trying to build a basic plugin, when installed has a single nav bar item, and of course a twig template which shows up on clicking on that navbar item. I have used the basic template to extend ...
1
vote
1answer
131 views

how to create Super Table field programmatically

i am trying to create a super table field programmatically. this is the code i tried. i see super table field in field list but i can see fields inside of super table. how can i do this? //...
1
vote
1answer
183 views

How to overwrite base controller beforeAction method

How do you override the beforeAction method of Craft's base controller? I'm disabling CSRF for a specific route. public function beforeAction($action): bool { $requestOrigin = \Craft::$app->...
1
vote
1answer
26 views

Assign a category group to a category field via migration

I am writing a plugin that sets up Craft in a particular way and have created a category field, but can't figure out how to assign a category group to the field, I have the following: protected ...
1
vote
1answer
158 views

Paypal IPN controller logic? [closed]

Has anybody got a controller (or whatever plugin aparatus is needed) to process Paypal IPN? Edit: Years later, I have accomplished this, and have some information which could be helpful if someone ...
4
votes
1answer
917 views

Can't get setFieldValue to work

I've got this // Creating users through frontend Event::on(Users::class, Users::EVENT_BEFORE_ACTIVATE_USER, function(UserEvent $event) { $userId = $event->user->id; // ...
1
vote
1answer
82 views

Get all elements (entries) where a field exists

I'm developing a plugin and I'm searching a way to get all entries where a field exists (by id or handle). I'm trying to get all the entries even if the value of the field is null, empty or text. I ...
0
votes
0answers
46 views

Load Entries after click (AJAX)

I try to load a entry after a button is clicked, currently my code looks like this: This is generating a 404 error. Dunno why? <?php /** * PopUp plugin for Craft CMS 3.x * * test * * @link ...
1
vote
1answer
219 views

How to work getFieldValue for assets

I have been implementing my own PHP plugin code. In that, I need to get an asset field in user info. If I can get if the asset is set on the field or not, it is enough. I can get the values of text ...
1
vote
0answers
166 views

Passing variables to email template not working

I am building a Craft plugin which sends emails to users of a subscribed list. I'm trying to get Craft to send the email with a Twig template and pass in variables to that template. So far I've been ...
1
vote
1answer
34 views

Do something on save of an entry

if that entry is in a particular section, then I want to do some task. I can't really find the event docs I need to do that. Everything I've come across has been for Craft 2. Any steps for a hint?
1
vote
3answers
363 views

How to create a new Entry model in Craft 3?

I want to create a new entry for a section named 'drinks'(having section id= 6). The namespace of the file having this code is namespace putyourlightson\userguide\controllers;.I copied this code from ...
8
votes
2answers
5k views

Can you save a variable in session?

Is there any way to save a variable in the Craft session inside a controller? I'm running a cron job and I need to store a variable as a session for every run to see if a condition matches.
1
vote
1answer
84 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 ...
1
vote
2answers
307 views

Parse variables into twig email template from custom module

I'm trying to send an email from my module and am trying to pass some vars into my module template that I can render using twig. Please note that this is a module template not a front end template. $...
1
vote
1answer
67 views

CSRF in plugin dashboard widget 400 error

Yes, it's another csrf question, the standard, 400 Error - Bad Request: Unable to verify your data submission. If in config/general.php I set 'enableCsrfProtection' => false, then everything works ...
1
vote
1answer
76 views

How do I store and retrieve elements for ElementSelectField? Getting error "Call to a member function getUiLabel() on array"

I have a field that allows a user to select multiple products and save them to the database for a plugin, but when I try to retrieve these values and have them selected in my form I get the error ...
2
votes
0answers
157 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 ...

1 2
3
4 5
35