Questions tagged [plugin-development]

Questions having to do with constructing plugins.

159 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
9
votes
0answers
842 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
515 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 ...
5
votes
0answers
356 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\...
3
votes
0answers
320 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
77 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
100 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
135 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
676 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
204 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
184 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
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 ...
2
votes
0answers
45 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 ...
2
votes
0answers
212 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
112 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 ...
2
votes
0answers
77 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
107 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
89 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
149 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
64 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
391 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
87 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
703 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
50 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
210 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
149 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
65 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
80 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
62 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
523 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
46 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
26 views

Best practice for plugin upgrade on major Craft releases

With Craft 4 looming in the horizon I was wondering what is the best way to upgrade plugins for major releases. I see two possible options: Option 1 Building from scratch (or copying the code) on a ...
1
vote
0answers
23 views

Removing or hiding certain fields from the CP new entry for a specific user group

I'm trying to make some fields unavailable for a certain user group when they create or edit a new entry. These fields should only be available to admin users. I had implemented this by extending the ...
1
vote
0answers
33 views

Is there a way to prompt for confirmation in cp?

I have a custom plugin that checks for assets filename, and I'd like to prompt for confirmation like in the example below. Is there a way to do that in Cp? If user clicks No then $event->isValid = ...
1
vote
0answers
105 views

Craft warning: Tried to release a savepoint, but it does not exist

I'm working on a plug-in for Craft 3. For this plug-in is a migration is needed. When this migration runs and adds the entries, fields, and groups then the following warning occurs in the logs. [...
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
69 views

How to auto enable a plugin after install?

I am developing a plugin for craft 3 and the plugin just got published to the store. I can browse through the store and install the plugin but it stays disabled. The user will have to goto Settings -&...
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
0answers
54 views

How do I allow partial payments?

The closest thing I found to what I need is here, the problem is, even though it's only 8 months old, it appears outdated. I see there is an "outstanding balance" in the PayController, but I have no ...
1
vote
0answers
72 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
47 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
90 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
142 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 ...
1
vote
0answers
53 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
27 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
38 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
185 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
56 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
99 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
102 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
52 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 ...