Questions tagged [plugin-development]

Questions having to do with constructing plugins.

168 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
9
votes
0answers
702 views

How do I upload images programmatically?

I'm working on a plugin that creates auto crops of a selected image, but I am unsure of the proper steps to create and upload an image programatically. I am hoping that Local asset sources and Remote ...
5
votes
0answers
277 views

How to load components into Craft 3 plugin?

what is the correct way to load third-party components into Craft 3 plugin I'm developing? I tried adding $this->setComponents([ 'authClientCollection' => [ 'class' => '\yii\...
4
votes
1answer
359 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 ...
4
votes
0answers
239 views

Using plugin template on front end

I'm working on a plugin called modelselector and I want to use a template stored in the plugin templates folder but it should be shown on the front-end of the website. Currently the following direct ...
3
votes
0answers
248 views

How can I create a dropdown field programmatically with a plugin?

I'm trying to create a Dropdown field and add it to the User field layout. I've successfully created an empty dropdown field (no options) and added it to the User field layout. Here is my current ...
3
votes
0answers
61 views

Set default order of Custom Fields inside Layout Tab

I'm writing a custom plugin, and I want to specify a custom order of the Fields in a tab. My plugin installs several fields, and I want the user to be able to simply add the tab that contains my ...
3
votes
0answers
97 views

Responsive control panel styles

I have a plugin that extends various Craft templates and styles, however, in one area it requires some custom Control Panel styles that Craft has not already created. As the Craft Control Panel is ...
3
votes
0answers
121 views

How can my plugin use Craft's native dragdrop support

I am using a generic Garnish modal from Craft like so: $container = $('.upload-modal'); $modal = new Garnish.Modal($container, { autoShow: false }); I would like to have craft's native drag&...
3
votes
0answers
622 views

What's the easiest way to update an entry from the front end as a guest user and only post the data that needs to be updated?

I'm creating a multi-page form on the front end of a site where different data is added to the entry depending on the page they are on. Originally I was going to create the entries using P&T's ...
3
votes
0answers
203 views

How do I traverse relationships when populating models from queries?

I have three models / records - Journals, Issues, and Articles. Articles each BELONG_TO an Issue. Issues each BELONG_TO a journal. Issues have a date on which they've been published, and I am trying ...
3
votes
1answer
147 views

Using setTemplateMode on the frontend

I'm trying to access a CP template from the frontend, and i'm doing something like this in my plugin: <?php ... $oldMode = craft()->templates->getTemplateMode(); craft()->templates->...
2
votes
0answers
103 views

Creating multiple plan subscriptions

Versions: - Craft CMS (3.1.21) - Craft Commerce (2.1.2) - Stripe for Craft Commerce (1.2.0) Problem: - My website offers user's ability to subscribe to several subscriptions at the same time. ...
2
votes
0answers
56 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 ...
2
votes
0answers
92 views

Commerce 2 Multi-site Support

I'm currently working on a multi-market Craft3 project with Commerce2. Each product can and will have a different fixed price on each page. Product A project.tld/de-de - € 120 project.tld/en-gb - £ ...
2
votes
0answers
47 views

Recommendations on integrating Craft 3 and FormAssembly

I was wondering if anyone could give me some advice. We have a client that we are in the process of moving away from a Drupal build to a new Craft build, however, they have a large number of forms ...
2
votes
0answers
366 views

Autocomplete for Visual Studio Code for plugin development

How to achieve autocompletion for Craft 3 for PHP inside Visual Studio Code? I mean, what is required (like installing PHP locally, folder structure etc.) if at all possible? I assume many people who ...
2
votes
0answers
97 views

Add CP Tab content into include file

I am making a plugin where I have about 10 tabs at the top. Depending on the admin users privileges they may see a subset of 1-5 or 6-10 and super admins can see all 10. The issue I am running into ...
2
votes
0answers
62 views

How can I add fields to my Sprout Form plugin?

I am not sure what I have done wrong, I am working with a fresh install of Sprout Forms. When I create a new form and then click "Add Field" in the layout designer, this is what I am seeing. Any ...
2
votes
0answers
331 views

Klarna Checkout - Omnipay

I am trying to create a custom payment gateway by extending / adding it to Omnipay which is already implemented in Craft. I have used the Ogone and other plugins as base, but I cant seem to get it ...
2
votes
0answers
79 views

Custom fieldtype to add text field to dropdown, radiobuttons and checkboxes

In my plugin I need to create a fieldtype of a dropdown, radiobutton or checkbox combined with a textfield. I've gone ahead and created a custom field type using the description here https://craftcms....
2
votes
0answers
594 views

Custom plugin - cannot save record

I have a service which am passing a model and an identifier (optional) to. The model contains new data and the aim is that if an existing record exists then we merge the two responses into a ...
2
votes
0answers
47 views

How do I modify the entries table to add a new column?

I've been going through the Craft EntryCount plugin on Mijingo and I've hit a bit of a problem, the way the tutorial shows how to modify the entries table to include the pageviews count doesn't seem ...
2
votes
0answers
182 views

Setting template mode to CP doesn't let me load plugin templates

Setting template mode to CP with craft()->templates->setTemplateMode(TemplateMode::CP) only lets me load templates from app/templates. If i load app/templates/entries/_fields.html and I use ...
2
votes
0answers
132 views

Craft.createElementSelectorModal in a tooltip is causing field to disappear

Problem: In a plugin for a custom field I want to have an Element Selection Modal so I'm calling: Craft.createElementSelectorModal() On an Element Detail page this is no problem. But, in a tooltip (...
2
votes
0answers
62 views

Allow CP sorting on an added EntryTableAttribute

I am adding a column to the entry table with links to reverse related entries: public function defineAdditionalEntryTableAttributes() { return array( 'blockParent' => ...
2
votes
0answers
75 views

Unable to get relatedTo working on an ElementCriteriaModel

In a plugin I am trying to get Users related to other Users: $criteria = craft()->elements->getCriteria(ElementType::User); $criteria->group = 'partners'; $criteria->relatedTo = [ '...
2
votes
0answers
56 views

Can plugins add functions to AssetFileModel?

I am currently working on a Craft CMS plugin, which adds functionality on top of assets, that should be callable in templates. I have come up with a Twig Extension that allows templates to call it ...
2
votes
0answers
481 views

Updating a single custom field within an Entry

I've got the beginnings of a simple plugin to track views of an article page, just an entry with custom fields including 'dataViews' used below. Within Twig: {% do craft.demoPlugin.incrementView(...
2
votes
0answers
44 views

JavaScript equivalent to “namespaceInputName”?

Is there a JavaScript equivalent to namespaceInputName? My fieldtype settings are doing some interesting JavaScript gymnastics. Part of the process involves creating an array on the fly (so when the ...
1
vote
0answers
30 views

How to save dynamically created checkbox values in plugin settings?

I am in the early stages of developing a plugin for Craft 3. In its settings it should have a checkbox for each section the user has defined that enables the admin to select or unselect each section ...
1
vote
0answers
30 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
vote
0answers
25 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 ...
1
vote
0answers
30 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 ...
1
vote
0answers
37 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
0answers
25 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 ...
1
vote
0answers
23 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
0answers
31 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
0answers
48 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 ...
1
vote
0answers
41 views

Sprout plugin: Send information in AJAX success response

I'm using Sprout for registering to events, I want to be able to send a code in the AJAX response when EVENT_AFTER_SAVE occurs. At the moment, I get {success: true} back, but I want to be able to get {...
1
vote
0answers
55 views

What's the most performant way to get reverse related entries within an Element Query?

What's the most performant way to get reverse related entries within an Element Query? Here's a contrived example of this. I have thousands of "book" entries and thousands of "collection" entries. I ...
1
vote
0answers
53 views

Custom plugin: Creating new fields will delete the field group they're being created in

I have a simple plugin which reads in a CSV file, and based on the first row of data will create a new field group, and then create fields within that group. The first time I run it everything goes ...
1
vote
1answer
55 views

Updating private repo plugins from admin?

Is it possible to update private repo plugins from the admin at all? Would love that functionality, especially for smaller projects that are installed where there's no CLI access.
1
vote
0answers
40 views

Custom Element Reference Tags

I have created a custom element type and cant get the reference tags to parse correctly, I've set the refHandle and the action to copy reference tag which seems to be correct format when I copy a ...
1
vote
0answers
22 views

How to modifyPaymentRequest() in Commerce 2?

Looks that I really used every functionality in my plugin that changed or has been removed in Commerce 2. :( I need to modify paypal transactionId and description what i did as follows in Commerce 1: ...
1
vote
0answers
43 views

Display Stripe card error in Craft 3 front-end entry form template

I have a custom plugin set up to speak to Stripe's API and process a card charge. The code triggers in a craft\elements\Entry::EVENT_AFTER_SAVE event because I want to pass along certain data about ...
1
vote
0answers
83 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
0answers
54 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
0answers
73 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
0answers
33 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 ...
1
vote
0answers
88 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 ...