Questions tagged [plugin-development]
Questions having to do with constructing plugins.
233
questions
5
votes
1
answer
3k
views
What is the proper way to fetch items from a custom db table and output them in twig?
My main issue is perhaps not totally understanding the unique idioms of Yii, but I need to output data from my custom data tables in a template. So obviously I have a MyPluginVariables class and a ...
5
votes
1
answer
1k
views
Save matrix block to new entry in plugin
I have been trying two separate methods to accomplish and both keep resulting in the same errors no matter what I try.
The entry I am saving has a few fields the last of which is a matrix block (I am ...
5
votes
1
answer
3k
views
Rendering templates from plugin controller
Right now I'm trying to accomplish routing users through a controller action before rendering the plugin's CP template...
[Plugin]Plugin.php
// ...
public function registerCpRoutes()
{
return [...
5
votes
1
answer
2k
views
Plugin Controller - Save Entry
I'm testing with the Foxycart Plugin to update the stock in my code.
In the FoxyCartController.php I'm able to filter through the XML feed ok and get the new Stock value but it's doesn't seem to be ...
5
votes
1
answer
1k
views
How can I implement advanced action routes (in routes.php)?
We want to mask specific action routes in our project's routes.php file. Currently what we have looks like this:
return array(
// /actions/api/element/section/name/{$name}/
'api/test/(?P<...
5
votes
1
answer
1k
views
Get entry by value from custom field
I have a field defined in my plugin called video with AttributeType::Mixed where I store a video_id and a title of a video. I need to look up the entry by the video_id (I can't do it via the the entry ...
4
votes
1
answer
1k
views
Is the "registerSiteRoutes" hook screwing up my template path?
This may be a bug...
I have a controller action which has been working great. It's a simple action with a single purpose... load a template with an internal value.
public function actionMyAction()
{
...
4
votes
2
answers
5k
views
How do I create a custom Twig extension which includes third party code?
I found several solutions to build a dynamic, complex navigation in craft. One is described here:
Adding active class to globally cached navigation. Now i would like to create a more powerfull twig ...
4
votes
1
answer
567
views
Plugin CP page causes white screen
I'll start off by saying my plugin is working perfectly locally. The problem is when I upload to my server. My plugin is for a contact form. It handles the submission, and logs the entry in the db.
I ...
4
votes
2
answers
1k
views
Inserting Relationship Into Entries Field - Plugin Not Saving Relation
I was hoping someone could shed some light on this issue I'm having. I'm trying to update a relationship field through a plugin, without much success, the entry looks like this:
I saw a post on here ...
4
votes
1
answer
235
views
Split-style button for "New" custom element
I've got a plugin with a custom element. It evolved based on the basics laid out in the P&T Events sample plugin.
On my element's index page, there's a big button to create a "New Element". When ...
4
votes
1
answer
697
views
Modify ElementCriteria and use it for paginate
First some context. I'm using Smart Map for Craft to display some location based events in a listing. My structure is as follows:
Events channel
Locations channel
Each event can occur multiple times,...
4
votes
1
answer
620
views
Mobile app authentication
We're trying to use Craft as a CMS for a mobile app and to accomplish this we need to convert entries to JSON. We use the Element API plugin for this and it works like a charm.
The problem is that ...
4
votes
1
answer
300
views
When developing plugins where should you store values that might not strictly be settings?
For instance I'm writing a plugin which is going to be periodically pulling stuff from Twitter, so I'd like to keep a hold of when the plugin was last run and maybe some Ids relevant to Twitter that ...
4
votes
1
answer
322
views
Is it possible to listen for Yii events?
I want to listen for Yii events like onBeginRequest and onEndRequest. I've tried the following but nothing happens :(
\Yii::app()->onBeginRequest = create_function('$event', 'die ("YO") ;');
and ...
4
votes
1
answer
865
views
How can I ensure using actionUrl in my template does not show script name in the generated URL?
I have an controller action in my custom plugin that processes Paypal IPN requests. How it works is that you provide a URL for Paypal to send it's notification requests to and then process them and ...
4
votes
3
answers
1k
views
How do you save a new Entry to be enabled on 2+ Sites?
I've made a plugin that let's you import Entries from a CSV file and I'm working through adding localization (Sites) support to it, but I can't figure out the right way to enable an Entry for a second ...
4
votes
1
answer
244
views
How to add/link an entry to an object using PHP?
I'm building a plugin to add users to the system with set properties (like company) and permissions. The user form works with an "Entries" field and works with connected source section entries and ...
4
votes
1
answer
762
views
Class 'Craft\stdClass' not found
Is there any way to initialize a stdClass?
Code is simple
$productOrCategory = new stdClass();
$productOrCategory->stockFutureDays = 0;
$productOrCategory->stockFutureDate = ...
4
votes
1
answer
6k
views
Getting info on the currently logged in user
Trying to get the currently logged in user's groups. Trying to get at that by using the user ID. I am currently testing as Admin - user number 1.
Craft::$app->getUser()->id
Returns a user ID (...
4
votes
1
answer
1k
views
How to use the native datepicker ui in custom fieldTypes?
I would like to impliment the native craft datepicker ui in my custom fieldType. From looking at the native date template (craft/app/templates/_includes/form/date.html) I can see that it inserts ...
4
votes
1
answer
3k
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 ...
4
votes
3
answers
5k
views
How to identify the logged in user inside a plugin?
I have a public registration form and a plugin which needs to create an entry for a user when that user is activated. That part works. Because I want to force an Admin to activate the user, I am using ...
4
votes
2
answers
757
views
Where and how should you listen for entry delete in plugin?
When an entry is created with my plugin's field type, data is saved to a separate table with entries id for reference. I need to delete that data if the entry that is associated with the data is ...
4
votes
1
answer
4k
views
Call plugin controller from frontend with ajax
I want to send an automatic back office email when user click on a button (to request support) on frontend. Then I just display a confirmation message (we ll get back to you shortly).
So I made a ...
4
votes
1
answer
860
views
How do you raise/fake an event so that you can test handlers listening for it?
We use event integration (native and custom) in a lot of the plugins we build and I was wondering if anyone has come up with a simple way to raise those events at will, without having to follow a ...
4
votes
2
answers
2k
views
Best way to programmatically create categories?
We're working on an XML import plugin to migrate content from another CMS.
What's the best way to create a new category (with a name, slug etc.) and assign it to the entry when running
$entryModel = ...
3
votes
1
answer
2k
views
How to save Asset field of an Entry programmatically in Craft 3
Using this answer on how to save data on Craft 3, I want to save also an asset field, but I cannot find out how.
It works for a Category field using the ids of the categories but not with ids of ...
3
votes
1
answer
722
views
Writing a plugin that triggers on a Control Panel Template Hook?
I want to do something similar to this answer but for Craft 3 (eg. render some custom HTML in the Entry editing screen). I can't work out how to do this with the changed Craft 3 hooks.
Should this ...
3
votes
2
answers
4k
views
How do I access current site handle in Craft 3 controllers
When my multisite is set up as @web/site, I cannot access the current site handle from my controllers.
Craft::$app->getSites()->currentSite->handle
I think this is because my form action ...
3
votes
1
answer
181
views
Get the related entry from an Entries field in a Matrix block within a plugin craft 3
So I've got this which accurately gives me the desired relation block within my matrix, but how do I actually get the Entry object from a relation field?
$project = Entry::find()->id($projectId)-&...
3
votes
1
answer
987
views
Add custom element criteria attribute without a field type?
Is a custom field type and making use of modifyElementsQuery the only way to add my own craft.entries element criteria model attribute to modify the elements query?
What if I do not want to add a new ...
3
votes
1
answer
406
views
Programatically change a lightswitch value on an entry on save
I have a simple plugin that fires some events entries.onSaveEntry based on if a lightswitch is turned on with that entry. What I would like to do as the last event in my plugin would be updating the ...
3
votes
1
answer
353
views
Is there a fallback when a Twig extension is not enabled?
So I have a plugin with a Twig Extension that does it's thing. If I were to disable my plugin I will get the expected error:
The "extensionName" extension is not enabled.
Whenever I'm referring to ...
3
votes
1
answer
287
views
Get entries whose title has a keyword or related to a category's title
I am trying to get entries that either their title has the keyword or their category field title. I am getting them from my plugin, not twig.
I tried like this:
$keywordCategory= Category::find()->...
3
votes
1
answer
208
views
Localized ElementTypes in a plugin
My question is re: localization of ElementTypes in a plugin. I have the records all working fine in multiple locales.
The part that I'm not "getting" is I think there should be one Element in ...
3
votes
2
answers
1k
views
Craft 3: Preventing Element from Saving in Plugin
I had a simple Password Confirmation validation function in Craft 2. In porting the function to Craft 3, I'm struggling to figure out how to handle the same thing. In Craft 2, all events were ...
3
votes
3
answers
425
views
Duplicate an existing Order as a new Cart in Commerce
Orders can not be edited in Commerce. Makes sense.
What we want to do however is make it very easy for someone to re-order a previous order. So for example they've had an order that contains "two ...
3
votes
1
answer
699
views
Filtering Matrix through field value and multiple relations
I've the following situation:
Accommodations (entry)
title
description (textfield)
...
linkedTo (matrix block)
Sport (category)
targetGroup (category)
minimumAge (number)
maximumAge (number)
What ...
3
votes
2
answers
250
views
How do you customize what value a Custom FieldType returns to a template
Is it possible to control what gets output in the template a custom fieldtype?
For example im working on a eventbrite plugin and it saves the id in the database but I want the field in the template ...
3
votes
1
answer
606
views
How do I create a plugin to create and save multiple entries from one front-end form?
I need to create several entries in different channels from a single front-end form. I realise that to do this I will need to create a plugin to handle the request.
Can I just to iterate over the ...
3
votes
1
answer
112
views
Flushing logs halfway through a request?
Sometimes I have long running requests that do imports or similar.
Currently logging using MyPlugin::log is only actually written to file once the request is done.
Is there a way to trigger log-...
3
votes
1
answer
1k
views
Can You Make a Custom Field with multiple columns?
I have a custom field where I'm defining AttributeType::Mixed in order to achieve the affect of saving multiple pieces of data for a single field. The data gets stored as JSON as expected. Quick ...
3
votes
2
answers
380
views
How to change the display order of columns in Entry List view?
When adding a custom column to an Entry List view using the modifyEntryTableAttributes hook, how would you also set the display order of columns?
3
votes
1
answer
487
views
Set custom sort order for index pages in the CP?
Good chance this is more of a feature request than a question you can help out. But as I am new to Craft plugin development and might oversee something I ask it anyways:
Now that it is possible to ...
3
votes
1
answer
273
views
How can I set up sources based on my custom field data?
Now that I have my custom field displaying in the Entries Table, how can I set up sources to view entries containing specific data from my custom field? My custom field holds several different values, ...
3
votes
1
answer
531
views
Is it possible to disable `requireUserAgentAndIpForSession` for specific instances?
I'm working on building a post-receive hook and a third party service's attempt to post data to a webhook keeps 302ing to the Craft login page when I attempt to use EmailModel and sendEmail().
The ...
3
votes
2
answers
727
views
Access add and remove events with the Craft Element Selector?
Is there any way to access an event, and trigger some function, when an element is added / removed with the Craft Element Selector logic available in Garnish?
I am working on a custom field type and ...
3
votes
1
answer
1k
views
Running out of memory in my Task-based plugin
I am writing a plugin that imports a large amount of data form an API into some custom element types. I have it all set up and working nicely with Tasks however I am running into a fairly big issue ...
3
votes
1
answer
125
views
Detect currently selected source of custom elements
I have a split-style + New Element button for my custom element type. Thanks to this previous thread, the right-side dropdown menu is working perfectly!
My question now is, how do I get the + New ...