Questions tagged [plugin-development]

Questions having to do with constructing plugins.

Filter by
Sorted by
Tagged with
5
votes
2answers
1k views

Output array to Plugin::log

Just wondering if its possible to output an array to the Plugin::log call? Would be really handy to see if an error occurs, what a data object's values are! Tried the following: Plugin::log(array('...
5
votes
2answers
1k views

Best way to include attachments using EmailService [Craft Plugin]?

I've got Email Service working correctly (http://buildwithcraft.com/docs/apis/emailservice) but what's the best way to include attachments when using this service? Here's what I've got so far: $...
5
votes
2answers
2k views

How to save a matrix content of a new entry in my plugin?

I have a section of type channel with a matrix field. I want to know how I would save the matrix content while I save the entry as well. I know I can save the entry as follows: $entry = new ...
5
votes
2answers
1k views

Using a plugin, how can I manipulate entry data?

I am trying to develop a plugin and what I want to do in this plugin is to be able to access the contents table that is already defined in the database and get and update entries in this table. What ...
5
votes
2answers
600 views

List of reserved field handles

Is there somewhere documented on what field handles are reserved? Would be great to have this as a resource here, especially for plugin development. Edit: A good place to start would be https://...
5
votes
1answer
1k views

Get entry field data via a plugin. ( For specific image assets )

I've got an asset field on a channel entry called "thumbnail". I'm using it to return a singular image, specifically for an image transform called "thumb". Looks a little like this: {{ entry....
5
votes
1answer
2k views

How to create a simple widget?

I have limited knowledge of PHP but I would like to try and create a widget. Basically all it needs to do is provide some text and a link to the user profile page as you can't route directly to that ...
5
votes
2answers
408 views

Possible to change locale in PHP?

I've got a plugin which is defaulting to English during AJAX calls, but I need it to stick to whatever the current language is. I can send the current locale through via AJAX data, but I'm not sure ...
5
votes
2answers
109 views

How to prevent select user groups from reordering structures

I need to create a plugin that prevents select user groups from reordering a Structure content type in the Entries listing. I could quickly do this by just hiding the a.move.icon element, but I worry ...
5
votes
1answer
3k views

Create entry with newly-uploaded asset programatically

I'm trying to do something very simple - but I've yet to find documentation to cover this basic scenario. I'm writing a plugin. In a controller, I want to create a new entry, and assign an uploaded ...
5
votes
1answer
479 views

Saving related entry in a Matrix block programmaticially

I'm trying to add entries to a Matrix block with one field type of 'entry' using the following: $block = new MatrixBlockModel(); $block->fieldId = 9; // Matrix field's ID $block->...
5
votes
1answer
389 views

How to add a subTask to an already running Task?

I have a plugin which creates a task every time a specify form is submited. Now I want to create a WrapperTask and run each of those tasks as a subTask: I know that I can create a sub-task within the ...
5
votes
1answer
707 views

How do I find the path to the public folder?

Within my Craft plugin code, how do I find the path to Craft's public/ folder? There doesn't seem to be a constant listed in Craft Docs: PHP Constants like there is for all the other key folders.
5
votes
1answer
521 views

Researching Craft CMS but we are a .NET Shop

I am involved with researching various CMS solutions and Craft CMS is one of the options for our organization as an Enterprise soluton, so not just for development use cases. When it comes to ...
5
votes
1answer
146 views

Getting Entries that were updated after a certain day?

I need to get all the entries that were updated after a certain date, I tried a couple things, but it doesn't seem to work, does anyone know how I can accomplish this? This seems wrong to me, but it ...
5
votes
1answer
222 views

Are there callbacks for elementSelect macro?

I am writing a custom field type that makes use of Craft's asset selector, and saw that there is an elementSelector macro (in includes/_forms). I want to be able to do some things onSelect, but I ...
5
votes
2answers
764 views

Categories field is losing its value when programmatically updating other fields’ values

I have a webhook that fetches an entry, modifies one of its custom Text field values and then saves the entry. However there is also a required Categories field on the entry, and when I do this, I get ...
5
votes
1answer
1k views

Is it possible to add a custom field to User model from a plugin?

Within a plugin I'm working on, I'll be adding user synchronisation with a third-party database to enable SSO, so will be creating users within Craft based on an interaction from this other service. ...
5
votes
1answer
444 views

How to access Craft classes within plugin?

I'm working with dates and want to use Craft's Class reference to speed things along but am struggling to figure out how to use them. For example, this works as expected and returns the siteUrl: ...
5
votes
3answers
759 views

Template Hook + Caching

A portion of my template is being cached, using the standard cache tag: {% cache %} Within that cached section of the template, I'm using a template hook: {% hook 'myTemplateHook' %} Within that ...
5
votes
1answer
738 views

Can a plugin fire a custom event?

I have PluginA that needs to listen for something that PluginB does. PluginB needs to include a Model in the event data so that PluginA (and any other subscriber) can pick that up and do whatever it ...
5
votes
1answer
2k views

How to return errors from a model back to the template?

I'm working on validation with Craft. I have a custom plugin that allows public submission. However, I want to make sure I can pass errors back to the template. The key is trying to make my code as "...
5
votes
2answers
1k views

How to retrieve entries from two entry-types ordered by different date-fields?

I have two entry-types, 'Events' and 'Reports'. 'Events' have a matrix-field ('eventMultiDate') that allows authors to assign multiple dates to an event (recurring). 'Reports' have the default '...
5
votes
1answer
953 views

How to reference the current entry element in custom Control Panel templates?

This might provide it's own answer, but I thought I would ask to be sure. How do you reference the current entry in custom fieldType or CP templates? I have tried {{ entry.id }}, {{ element.id }} but ...
5
votes
1answer
771 views

How can I expand on a normal Craft query to sort by a column in a custom table?

I have a plugin which contains a Record. My record contains a foreign key of the related element ID. The only other column in my custom table is the value I'd like to sort by. In Twig syntax, how can ...
5
votes
1answer
2k views

Plugin Variable can't find template

I'm new to Craft template development and one of the first things I'm trying to do is create a Variable that renders a template into the template its called from. My directory structure looks like ...
5
votes
1answer
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
1answer
989 views

Should my controllers actions 'return' when rendering templates?

When developing a plugin, I am registering routes to controller actions. Other frameworks, read that as Laravel, typically return the controllers response. public function showProfile($id) { $...
5
votes
1answer
788 views

Plugin settings multiline input field

I created a plugin settings page following the example shown here but my entries need to include multilines (they are email bodies). My Twig template for the settings page is like this: {% import "...
5
votes
1answer
586 views

filtering elements between 2 dates

I'm sure there must be an easy way to do this, but I can't work it out... I'm trying to add date filters to the formerly submission export, but I can't work out how to filter out the submissions ...
5
votes
1answer
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
1answer
2k 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
2answers
2k views

Populate a record with a model?

In a follow up to my earlier question, I'm focusing on cleaning up my code to keep it incredibly simple. I've moved on from the Controller and Model to the Model and Service. Typically you would have ...
5
votes
1answer
669 views

Use a custom Element Type without sources?

I want to create a custom plugin (element type) that does not allow custom fields. Therefore, when digging through existing element types, do I really need to have the getSources method? If this is ...
5
votes
1answer
795 views

Is there a way to generate a url to an image in the craft/storage/myplugin directory?

I am generating dynamic images to a directory in craft/storage. I need to be able to use these generated images on the front-end inside templates. Is there a helper method for this, or some way to use ...
5
votes
1answer
633 views

Programmatically entering data into a table field for an entry

I now know that you can enter data into an entry's field by using $event->params['entry']->getContent()->handle But let's say I have a foreach loop and I want to enter each line into an ...
5
votes
1answer
461 views

How can I create a template macro within my plugin for use within front end templates?

I have a plugin that I am writing and I want to make available a macro that can be used within the front end sites templates. What is the best way to do that?
5
votes
1answer
3k views

How to route to a controller action in Craft3?

Before I get tagged as a duplicate I have already tried everything in the 'duplicate' issues on here to no avail so I'm posting my exact config to see what I'm doing wrong. Here is my plugin code and ...
5
votes
1answer
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
1answer
223 views

Does Craft have a styleguide for the admin, like Bootstrap?

Does Craft have a styleguide for the admin, like Bootstrap? I'd like to know how to create plugin interfaces that match with Craft
5
votes
1answer
145 views

How to use Class Reference Classes within the Craft framework for plugin development

I am attempting to lean how to write a plugin but am having trouble knowing how to work with the Class Reference documentation. I understand all of the theory and how object oriented programs work. ...
5
votes
1answer
214 views

"Custom" validation for plugin settings page

I have a plugin that has a few settings. One of which is a start date and and end date. Everything is set up and working fine. I'd like to validate the start/end dates a a bit though. I am able to ...
5
votes
1answer
1k views

Where should a plugin create temporary files

I have a plugin which needs to create a temporary file. Where should I put it?
5
votes
1answer
264 views

Plugin routing casing: camel, lower, Pascal

Recently got tripped up with plugin routing due to casing. It seems when you're in the control panel, your "plugin handle" is lower-cased in routes, though both seem to work: /cp/settings/plugins/...
5
votes
2answers
3k views

Craft 3 Plugin Routing Problems

So I am working on converting a previously-standalone Yii 2 app into a Craft module and am having some issues with routing. I wish to keep my old URL structure as much as possible. As such, I ...
5
votes
1answer
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 ...
5
votes
1answer
609 views

Is there a good way to eager load Craft's Element Relations through a plugin?

For a specific entry in a specific section I would like to eager load all associated data from the related elements. Say that I know the related elements are from the following field types: An ...
5
votes
1answer
2k views

Trouble running a plugin console command

I'm trying to get a basic console command for my plugin to run but not having much luck. I have created a folder called consolecommands inside my plugin directory and have created a file called ...
5
votes
0answers
519 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
357 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\...

1 2
3
4 5
35