Questions tagged [plugin-development]
Questions having to do with constructing plugins.
1,757
questions
1
vote
1
answer
48
views
Tables not created when plugin installed
I've got a plugin that works on Craft 4.5. It's been installed a long time, upgraded from 2.x to 3.x.
Now trying to use it on a new install of Craft 4.5.10, installing it does not create any tables. ...
1
vote
1
answer
34
views
Calling a Function From Private Plugin
Writing my first plugin. Scaffolded with Generator and is active (appearing in admin). This is where most tutorials leave you on your own so hoping to get some help calling a simple function in my ...
1
vote
1
answer
30
views
Can plugins have their own routes?
I'm writing a plugin. I'd like it so that a request to view the page is processed via a Controller rather than goes straight to a template (following an MVC pattern).
So a GET request to the URL of ...
1
vote
1
answer
91
views
In Craft CMS CP plugin, how can I intercept the lightswitch.php getTableAttributeHtml?
I'm trying to make a basic plugin that intercepts Lightswitch.php and edits getTableAttributeHtml
Here is the current way:
public function getTableAttributeHtml(mixed $value, ElementInterface $element)...
0
votes
0
answers
35
views
In Craft CMS CP plugin, how can I get the current entries relevant to the view I'm on? Trying to edit the Lightswitch field for all entries
In Craft CMS CP plugin development, How can I get the current entries relevant to the view I'm on?
Event::on(
View::class,
View::EVENT_BEFORE_RENDER,
function ($context) {
$entries = ...
0
votes
0
answers
17
views
Whats is the correct way to save and retrieve an entry or assets in a custom record?
Let's say i have a custom ActiveRecord and want to save a single Asset or an Entry relation (one to one) inside one of it's columns, what's the correct way to do this?
1
vote
1
answer
52
views
Custom Element Type Documentation not working or confusing
Following the docs on the offical CraftCMS website i'm not able to get "Native Layout Elements" saved. My field body is always empty. Any idea what i'm missing here?
Relevant Part of Plugin ...
0
votes
2
answers
24
views
Craft 2 Caching RESTful API Results Displayed On Page
I have made a php plugin in Craft 2 which calls a RESTful API and displays the results on the template. The data is returned at about 8 seconds. I've surrounded the call to the plugin on the ...
1
vote
1
answer
25
views
Is there a way to determine an element by its path or full url instead of the uri?
I'm using Craft in headless mode. It's a multisite setup different languages. I know that's it's possible to query an element by it's uri. Is there a way to check if a full path or an absolute url ...
1
vote
1
answer
27
views
Plugin migration - how to handle count in php8.1
I am trying to migrate a plugin from Craft 3 to Craft4 .
The plugin basically checks the entry for a pdf asset and create a thumbnail asset from the PDF using Imagick to save with the entry.
I use to ...
1
vote
1
answer
45
views
Craft CMS 2 - Exporting entity issue
I installed this https://github.com/boboldehampsink/export plugin but getting error during exporting entities regarding to "count(): Parameter must be an array or an object that implements ...
1
vote
2
answers
70
views
Entry url in console action doesn't return absolute URL
In an e-mail template in a custom plugin I want to render a link to an entry. This needs to be an absolute URL.
I need this to work both when triggering the action from the control panel, and when ...
1
vote
1
answer
33
views
How to make checkboxSelectField sortable?
i am trying to make checkboxSelectField sortable so far i have only managed with inclusion of third party scripts (sortable in jquery.ui).
The code looks like this:
Twig:
{% import "_includes/...
1
vote
1
answer
113
views
Craft 4 Building a Plugin not saving all properties
After following the "How to build a plugin" from the official CraftCMS docs, I've started extending the Control Panel Template from 1 to multiple fields, all are of the same type string and ...
0
votes
0
answers
22
views
What happened to preferredLocale in craft3
I upgraded to craft 3 from craft 2. My users don't have access to the control panel so I created a plugin where they can select from the front end their preferredLocale to determine which language to ...
0
votes
0
answers
22
views
Issue with custom field plugin - conversion from Craft 2 to 3
I have a custom field I created for Craft 2. It is a usergroup field where it will show a variety of checkboxes where an entry can be apart of multiple usergroups. The plugin has worked fine in ...
1
vote
1
answer
43
views
How to check read-only mode in plugin?
I have written a plugin and it listens to different events to run some tasks. Now if the app is in "read-only mode", I do not want some of these events to run:
class MyPlugin extends Plugin
{...
1
vote
1
answer
24
views
Editing users preferredLocale from a plugin controller
Recently upgrade from Craft 2 to Craft 3. Also had to update all the custom plugins. Once of them is to run a daily import of users from a file. In that file we try to set the preferredLocal of that ...
1
vote
0
answers
32
views
How to detect when a custom Field's element is being hard deleted?
With a custom Field how do you detect before the element associated with the field is hard deleted not just before it is soft deleted (beforeElementDelete) and added to the trash.
0
votes
1
answer
43
views
Deleting a matrix block type that was copied in code
I'm somewhat new to Craft, and struggling a bit with copying matrix block types. Any help would be greatly appreciated.
So, I have some code that copies a matrix block and its fields, but when I go to ...
1
vote
1
answer
40
views
Entry Query: How to load an entry with the full URL as only criterion
From PHP (Plugin), how can I load a certain entry if only the full URL is provided?
I can not find Craft's logic in PHP to split the full URL into the site's baseUrl and the entry's URI.
Please note ...
1
vote
1
answer
49
views
Create a template for front end when plugin install
I have a plugin which embed a forum to front end website. For that i need a .twig template file to be created when craft admin install my plugin.
The template file will have html code <div id="...
1
vote
1
answer
604
views
Using EventStream doesn't work because MimeType from Controller Action is always text/html
I'm trying to listen to SSE events from a controller action.
I am setting the headers in the controller action with:
Craft::$app->response->headers
->set('Content-Type: text/event-...
1
vote
1
answer
294
views
Updating to Craft 4 breaks plugin settings: must not be accessed before initialization
I maintain a plugin. Inside this plugin's composer.json, extra>handle is set to pizza (not the real name).
In one of the controllers, the following code is executed:
$apiKey = Plugin::$plugin->...
1
vote
1
answer
131
views
How to programmatically create category groups and categories in Craft 3/4
I am struggling to create a new category group and category programmatically. I've found a few examples for creating an entry, and one for creating categories in Craft 2, but I can't get it working in ...
1
vote
1
answer
118
views
Best way to create forum using CraftCMS 4
I'm currently develop a website using CraftCMS 4 and one part of it is forum, where users can ask and answer questions. What is the best way to create it? I've found a plugin "Website Toolbox ...
0
votes
1
answer
174
views
How to update Craft 3 version of plugin when Craft 4 version is already released?
I have a plugin that initially was created for version 3.x of Craft, but was updated to be compatible with Craft 4. How can I update the plugin with some new features for Craft 3?
2
votes
2
answers
40
views
Plugin 'editableTable' settings field returns incorrect type when empty
My plugin uses a {{ forms.editableTable({...}) }} field within the settings.twig. When the field has row items it will save just fine, but when the table is empty it attempts to save it as an empty ...
0
votes
0
answers
136
views
How to send e-mail on an event
I was wondering how to send an E-mail after an event.
In this example I'm using stripe payments and I want a mail to be send after a transaction was completed.
Below I have tried to send a mail when a ...
1
vote
1
answer
80
views
How to set up webhooks individually for each site in multi-site configuration with many customers?
The current issue is that I have multi-site setup, where are many different sites in a single Craft instance, e.g., I have 10 websites from 10 customers, when one customer updates his website I want ...
2
votes
1
answer
103
views
Adding section to Graphql "View - Public Schema" programatically
So, I am creating new section called "My Section" with handle "mySection" via plugin. All good there.
I want to be able for my section to be Viewable via Public Schema each time it ...
1
vote
1
answer
31
views
Reordering Matrix blocks by date in the control panel when saving an entry
I'm trying to reorder Matrix Blocks in date order when saving an entry in the control panel. I kind of have it working using the following code.
My Matrix field is 'events'. Each block contains a date ...
1
vote
1
answer
229
views
How to add and run migration from plugin root folder?
I'm trying to add a new table to an existing plugin.
I can't add it to the Install migration as I want existing installations to pull the change.
The problems I ran into:
I can't run Craft CLI (php ...
1
vote
1
answer
96
views
Craft 4 - Upgrading Plugin to support Condition Fields
I've got a plugin that uses field layouts.
I was asked about Craft 4 Conditional Field support so I went away to investigate. From what I gathered so far, the toggling of conditional fields happens ...
2
votes
1
answer
369
views
Craft 4: How to programmatically attach fields to entry type tab
I'm in the process of upgrading a plugin from Craft 3 to Craft 4.
When the plugin is installed it creates some fields and attaches them to an entry type.
The way it was done in Craft 3 is:
Get the ...
1
vote
1
answer
326
views
Getting column not found when using 'Entry::find()' to find the matching channel entry in custom plugin
We are building a plugin to perform some custom operations with an ERP system.
We created a section for managing the users from ERP. We are able to create new users as channel entries and update them ...
1
vote
1
answer
286
views
What's the correct way to check that an asset file exists?
If I have an asset resource, loaded successfully from the database, whose corresponding file no longer exists on its Volume (irrespective of Volume type), what is the best way to find out if the file ...
1
vote
1
answer
86
views
Can't access Cookie from controller in plugin
In the frontend my website sets a cookie wich i need during a controller action. When calling the controller action from my plugin this Cookie gets duplicated and the value is replaced with an ...
1
vote
1
answer
60
views
Feed Me Plugin - Prevent Feed from Being Triggered Multiple Times in Quick Succession
I’d like to prevent a feedme feed from running more than once when multiple requests are received within a few seconds of each other.
My first guess is that I would want to target an event such as ‘’’...
1
vote
1
answer
27
views
User profile - if user logs out after saving an Asset - Invalid subpath “profile/{{currentUser.id}}” - SSO Login fails
Having tested this error only occurs while using the SAML Service provider plugin: I have tested in multiple versioning env and experienced the same issue.
I can save an asset file Image or doc while ...
1
vote
1
answer
45
views
Can't change author and dateCreated/postDate on duplicate entry action in Control Panel
We have a Craft-based email campaign builder that is up to date with Craft 3.7.x and plugins. I have a business logic plugin that works for a lot of custom functions but I can't seem to get this going....
1
vote
1
answer
35
views
Is there a way to trigger a user account creation from a different CMS?
I'm a junior web developer working with Craft CMS.
I was wondering if there was a way to trigger a controller I have for my Craft CMS from an outside CMS. We have more than one website that offers ...
1
vote
1
answer
44
views
Custom plugin - show popup before element save
I've got a plugin that's got element types. I've got a Transaction element that I need the user to confirm before saving.
I've tried to use the jQuery that comes with craft:
$('form').submit(function(...
1
vote
1
answer
76
views
Get field settings of custom field via ElementInterface
It is possible to get the field settings via ElementInterface in normalizeValue Method ?
I need these settings of my custom field from my plugin :
how i can get now these values inside normalizeValue ...
0
votes
0
answers
90
views
How to save the selected assets in custom module
I am trying to create a custom module where I have created an asset uploader field. Images are getting uploaded with that field but not saved.
class Settings extends Model
{
// Public Properties
...
1
vote
1
answer
100
views
Event triggered when Craft sends email
Is there an event that would be triggered every time email is being sent by Craft? So email message can be intercepted.
-1
votes
1
answer
90
views
how to create a custom plugin if the user enables plugin settings then it will replace the website home page to my custom design? [duplicate]
I am trying to create a plugin if the user enables plugin settings then it will replace the homepage of the website with my custom designed template
0
votes
1
answer
122
views
How to override homepage content through plugin?
Want to override index.twig content through a custom plugin. I want to create a plugin that appends some content on website homepage. How to Achieve this any reference will be helpful
1
vote
1
answer
34
views
Make plugin permission appear on permission list, without defining control panel section
How can i make plugin permission appear on permissions list, without setting public $hasCpSection = true; in main plugin class?
For now i set this variable to true and then removed section link like ...
0
votes
1
answer
251
views
Want to use assets field my template settings in custom plugin craftcms
I am creating a plugin that is based on images the admin will upload some sort of images in plugin settings not sure how to creat image field setting in plugin