Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [plugin-development]

Questions having to do with constructing plugins.

1
vote
1answer
14 views

Connect to an external database from a Craft 2.x plugin

I recently saw a very helpful post about how to connect to an external database from a Craft plugin and I wanted to confirm I understood the implementation correctly. On this response the author ...
2
votes
1answer
19 views

Call function from plugin in template

In craft 2 I had a simple plugin that I used to run some php code. I could call the function like this. {{ craft.pluginname.functionname }} However I have been unable to do the same thing in craft 3....
1
vote
0answers
19 views

Element type vs. Field type - or: Element type without database storage?

I have already searched for information on this topic but I did not find much. I hope I did not overlook something. My problem is the following: I want to try to write a plugin that lists entries ...
1
vote
1answer
18 views

Added custom entry details fields

I'm looking to add a custom fields to the details section on the right of the entry edit view in the control panel. I know that in Craft 2 this was possible using: Craft::$app->view->hook('cp....
1
vote
1answer
15 views

Closure in plugin class/ saving and passing a public property

I am struggling with closure and saving a variable. In my class somePlugin i do have a public var $customerId , which should be updated after i execute my setUser() function. To do so i have a setter ...
1
vote
0answers
12 views

Can't set structured entry parentId in BEFORE_SAVE event using field data

I have created an event that is called on beforeSave within my plugin. Code below: Event::on( Entry::class, Entry::EVENT_BEFORE_SAVE, function(ModelEvent $event){ /...
1
vote
2answers
60 views

Craft 3 Plugin Development: Add CSS and JS File to Frontend Templates

How do I add js and css files to frontend page loads via a plugin? I did reference this issue: Can a plugin add JS or CSS to the control panel? but that is for Craft 2. Reading the docs here: https:/...
1
vote
0answers
25 views

How to add sources for Entries

The documentation indicates it is possible to add sources for entries like this: use craft\base\Element; use craft\elements\Entry; use craft\events\RegisterElementSourcesEvent; use yii\base\Event; ...
1
vote
1answer
28 views

Pass Controller Variables into a Model

I am using a Controller to get Variables from a field in my Plugin. How and what would be the best way to pass and use them in other classes or my main plugin file. I thought about using Sessions or ...
1
vote
2answers
28 views

Action URLs from CP to a Craft 3 plugin controller

I'm working on my first Craft 3 plugin and want to add some buttons to my plugin's control panel section which post form data to a controller. My plugin is called 'myplugin', the controller I wish to ...
1
vote
1answer
11 views

Error running any Composer command

I am working on a project with multiple developers and another member of the team is getting on with a Plugin to assist with some CraftCommerce integrations. As it's not a publicly available plugin, ...
1
vote
1answer
26 views

How to store custom data into a user

I need some direction in how to store (complex) data into users (best practice) I'm working on a project for a fitness app. I created a structure with 2 levels for workouts where level 1 entries are ...
1
vote
0answers
16 views

Updating Field from plugin

So i'm trying to update a checkbox field using a custom plugin i built. I have three tiers on my site, tier one that you only get access to certain items, tier two you get access to tier one and other ...
0
votes
0answers
15 views

Update Checkbox on User fields

I'm trying to figure out how to update a checkbox field on my user backend from a plugin.
1
vote
1answer
34 views

Add settings to plugins cp section instead of settings page

I've setup a plugin like so http://domain/admin/plugin-handle (cp section) and a settings page here http://domain/admin/settings/plugins/plugin-handle I can edit my plugin settings under the latter ...
1
vote
2answers
55 views

Saving Custom Field Values to User Profile

I have a custom user field 'myuserfield' How do I save a value to this field via a plugin in Craft3? Here is my current attempt. $myvar = '12345'; Craft::$app->getUser()->getIdentity()...
0
votes
0answers
21 views

EVENT_AFTER_SAVE_ELEMENT fires twice for some weird reason

Any idea why this code is always fired 2 times every time I save my entry? I get the same thing with Elements::EVENT_BEFORE_SAVE_ELEMENT (only for test purposes as I need to trigger AFTER), same thing ...
1
vote
1answer
24 views

Check for whole cart adjustment and apply line item discount

I'm writing a custom plugin for a customer that does 2 things. Uses prices from Pricing Categories. There are 10,000 digital products, so adjusting prices for large quantities is cumbersome on a per-...
1
vote
1answer
19 views

How can I pass a variable defined in a Controller to my variables?

In my Craft 3 plugin I would like to pass a variable defined in my Controller to my PluginVariable.php file. Is this possible?
1
vote
1answer
18 views

Loading a plugin template via ajax

I'm trying to load a plugin template via ajax inside another plugin template like so: $("#modal").load("/mypluginname/myplugintemplatefolder/myplugintemplate.html?queryvar="+var); but it keeps ...
0
votes
0answers
11 views

How to prevent Craft Admin from displaying “Leave site?” message for custom fields

I'm using custom fields provided by a Craft 3 Module to provide some Javascript-based functionality in the Craft Admin, and it includes some form elements, but the values of those form elements are ...
2
votes
1answer
15 views

Programatically Changing Entry Types?

I have a people channel that historically has used another field to decide if they're a "featured" person or not. The field set for "featured" people has now diverged from what a normal person has, ...
0
votes
1answer
45 views

Craft 3 - Save new Entry with Relations (Categories/Assets)

i simply can not get my "job" done. I try to create a plugin for Craft, a simple one. It reads some date and should create new entries out of this data. First i stuck on a stupid save-mistake, someone ...
-1
votes
0answers
20 views

Hide some Channel entries via custom plugin

I'm developing a plugin that will give an ability to restrict access to some entries from a channel. So the logic is: I have a Usergroup - Channel and User - Entry relation table in my database. ...
0
votes
0answers
25 views

How to redirect the page with params?

In the front-end, I create a form and submit the data to backend. In the controller, if got some errors, I would like to redirect to the previous page with some information. I tried like this: return ...
1
vote
1answer
22 views

Craft 3 plugin to import channel entries

I try to finish a plugin which imports data into my craftcms project. I already created a console based method/service, which I trigger/run in my shell. Inside my method(s) I receive data (XML or JSON)...
2
votes
1answer
60 views

Is it possible to pass a variable to an event in a plugin?

I need to find out if any changes have been made to the entry on successful save. Using events entries.onBeforeSaveEntry and entries.onSaveEntry seems to be a way to do it. Maybe. Can I pass some ...
2
votes
1answer
25 views

Set a route for all requests within a plugin

I’m trying to use a plugin to set up a site route that will direct every page request to a special template. This is what I’ve set up in my plugin file. public function registerSiteRoutes() { ...
2
votes
1answer
20 views

How to get a Super Table relation in PHP?

The following code works great in a template. {% set priceProduct = currentUser.priceTable.relatedTo({ targetElement: product.id, field: 'product' }).one() %} {{ priceProduct.price }} ...
1
vote
1answer
31 views

Save and login user in a Plugin?

How can I register and login a user in my Controller? I have tried something like this: $newUser = new User($userName, $userPassword, $userEmail); Craft::$app->elements->saveUser($newUser);
1
vote
1answer
34 views

Loading email templates in a Craft 3 plugin

I've been struggling to make this work within a plugin. I have a html file in my templates folder called _email.html. I try to load it in my plugin but then I get an error. This is my code: Craft::$...
1
vote
1answer
22 views

Log in User (Craft 3)

How can I log in a user in Craft 3 and redirect to a url? This doesn't work: $username = $user->username; $userCode = $user->teamCode; Craft::$app->user->login($username, $userCode); ...
1
vote
1answer
57 views

Plugin init order issue

I have a plugin, which is using another plugin. The issue is that, I am calling some other plugin information in the init function, and I do receive sometimes this error: 2018-11-07 11:44:57 [-][-][...
1
vote
1answer
21 views

Can plugins in the Plugin Store require development versions of libraries via Composer?

I recently put together a basic Constant Contact plugin for a project, and I'd like to clean it up and improve it for a public release. The problem is that it requires a development version of the ...
1
vote
0answers
39 views

How can I create a Module/Plugin to edit multiple entries via a single front-end form in Craft 3?

Scenario: I have a Structure section called Competitions that allows users to submit one or more (usually three maximum) entries to judged photo competitions. However, they can only submit one or two ...
1
vote
1answer
19 views

Sideloading an image from a function in a plugin

I need to be able to side load an image and attach to an entry. My image is coming from an external url... such as http://someplace.com/image.jpg - i can store this in a temporary file so its locally ...
1
vote
1answer
23 views

How can I use asset select modal in utility?

I created a custom utility template. Inside the template, I would like to use the built-in asset select modal for the "Add image" button. Any way to do this please?
2
votes
2answers
37 views

Craft 3 Custom Field Type with a File Uploader

I have a custom field type I am porting from Craft 2 to Craft 3. This field type used prepValueFromPost to grab a reference to a just uploaded file and then saves said file to an appropriate place ...
1
vote
1answer
17 views

Add a method to an existing element

Trying to get my head around plugin development. Sorry if this is a super basic question. How do you add a method to an existing element? I’m trying to get any active Commerce 2 subscriptions for a ...
1
vote
1answer
32 views

How to validate entry in Craft 3

An entry could be validated by the following code in craft 2: craft()->content->validateContent($entry); How could be the same done in Craft 3 ?
1
vote
1answer
22 views

Update field setting value using getFieldByHandle

I need to update the limit setting for Images allowed to be empty, so as to allow for no limit. How do I go about updating the 'limit' setting? $fieldsService = Craft::$app->getFields(); $field = $...
0
votes
0answers
27 views

How to exclude some fields from the searchindex using the RegisterElementSearchableAttributesEvent event?

Context I had big issues on a Craft 2 multilingual site with dozens of thousands of entries that were using Matrix fields. The site had become extremely slow (almost unusable), especially when ...
1
vote
1answer
50 views

where command sql query not working

My problem is that I can't update the specific $userId. have the values I've selected. I also get an error: Call to a member function where() on integer I just started to learn Craft. It can be ...
1
vote
1answer
30 views

Reducing memory usage?

I have a relatively simple task which is exposing an issue with efficiency. In that it isn't very efficient and the server cries and quits. Here's the high level overview: There's a category called "...
1
vote
1answer
32 views

Craft 3 validate new password in change password

I'm trying to validate user's new password and confirm password in my custom plugin init(). Event::on(User::class, User::EVENT_BEFORE_SAVE, function(Event $event) { $formData = $_POST; $...
1
vote
1answer
20 views

Tasks runs only after admin is logged in

I have a plugin which runs a task on order complete. The tasks runs successfully without any errors. But the problem is the task is only completed when admin is logged in. So if someone has completed ...
1
vote
2answers
33 views

How to disable plugin Disable and Uninstall?

I am developing a site with a customer logged in area. I don't want anyone to access the section if they are logged out and instead redirect them to the login form. I could just add {% requireLogin %...
2
votes
0answers
23 views

Add custom column to the orders list page

Does anybody know if it is possible to add a column to the orders list page? I can choose the 'Foo' label, but when the page want to show the orders list I get the following error: "{"error":"An ...
1
vote
2answers
28 views

Sending Error Message to Template With No Logged In User - Craft 2

I'm working at getting error messages sent from my plugin to my template (on the front end), when there is no session (no logged in user). The plugin is for LDAP authentication. Edit: For ...
1
vote
0answers
8 views

Excluding entries based on a tag across whole site

I'm trying to exclude entries that are tagged "DO NOT PROMOTE" on any page where craft.entries is used minus their actual entry page. What I've come up with so far is this: public function init() { ...