Questions tagged [plugin-development]

Questions having to do with constructing plugins.

Filter by
Sorted by
Tagged with
23
votes
1answer
2k views

How can my plugin generate a generic modal window in the Control Panel?

I'm working on a plugin, and it requires a modal to be displayed when the user interacts with a field of my Field Type. When the user finishes interacting with the modal, they would click "Done". ...
16
votes
2answers
2k views

Are there any plugins for Craft 3?

Are there any Craft 3 plugins yet? They would be useful as examples for porting/writing other Craft 3 plugins.
15
votes
3answers
4k views

How to get absolute path to asset file?

I have some csv files uploaded as assets and now I need to fopen() them from my plugin. I have an AssetFileModel but I have not been able to work out how to construct a full path to the file. I can ...
15
votes
1answer
8k views

What's the recommended way to include vendor library dependencies in your plugins?

My plugin requires vendor library dependencies and api keys set. What is the recommended way to register an external library? I would also like to configure the public api keys separately for stage ...
15
votes
1answer
3k views

What is getContent() / the ContentModel, and how do I use it to get and set custom field values?

If I want to retrieve content on an element, should I be calling $entry->$fieldHandle or $entry->getContent()->$fieldHandle? What’s the difference? Likewise, if I’m setting new content on an ...
14
votes
2answers
4k views

How to save Matrix data programmatically in Craft 3

How can you programmatically save an entry that has a Matrix field in Craft 3? (Something like this gist for Craft 2)
13
votes
2answers
2k views

What is the best way to handle errors in plugins and templates?

What's the best way to prevent exceptions in my plugin from blowing up my entire page? try/catch and return null, and then check for null in the template? For example: my plugin fetches data from a ...
13
votes
2answers
2k views

How do we create a pre-defined Asset upload field in a plugin that integrates with the native Craft Assets file manager?

We've got a plugin. It doesn't have the ability to add custom field types. We're pre-defining all of the fields. One of the fields needs to be an Asset field. A user should be able to upload an ...
13
votes
1answer
2k views

The Definitive Guide to Extending Twig in Craft CMS

So Craft's implementation of Twig is already very powerful and suitable to most common tasks. The Craft Docs already provide a great intro into using Twig and the handy extensions provided by Craft: ...
12
votes
2answers
5k views

How to get data from a Global Set in a plugin?

I have a Global Set called "Settings" (handle = 'settings'); Within that I have a text field called "Address" (handle = 'address'). I have a function in my Plugin and I'd like to get the Address ...
11
votes
3answers
2k views

Programatically create a Matrix field

I'm developing a plugin which requires certain sections and fields to exist so I'm currently creating them in the onAfterInstall() method of the plugin. I can create individual fields, sections, ...
11
votes
3answers
3k views

How to search for a specific field using getCriteria()?

I'm looking at making a plugin and need to search news entries. I can use: $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->section = 'news'; $find = $criteria->...
11
votes
1answer
515 views

How can I utilize existing UI for my plugin's control panel views?

I'm new to building plugins and I need to make templates for the control panel. How can I use existing Craft UI components to keep things consistent and save myself from having to rebuild everything?
10
votes
5answers
6k views

What's the best way to skip CSRF for plugin controllers?

I'm working on a plugin that'll create a private API for content authors to post entries to Craft from desktop-based scripts. These scripts post data to plugin controller actions (anonymous-allowed), ...
10
votes
1answer
3k views

How to use plugin settings

I am learning craft and trying add settings page for my plugin. I read that need to define settings like, class CocktailRecipesPlugin extends BasePlugin { // ... protected function ...
10
votes
2answers
1k views

Booking paid-for events: How?

First off, I appreciate this is open ended and SE isn't the best place for it. For a lack of a better place to ask though, here we are: I've just built a system for a client where users could sign up ...
10
votes
1answer
355 views

Best way to implement my own statuses on my custom element type?

I'm working on a plugin with its own element type, I'm trying to add custom statuses to the element type. What is the best way to proceed? I have hasStatuses set to true and getStatuses is where I ...
10
votes
2answers
1k views

Update Asset Index in Batches

I have 80,000+ files on S3 that need to be added to Craft. The Update Asset Indexes works, but takes over 24 hours and cannot be interrupted. Does anybody have a way to programmatically index assets ...
10
votes
1answer
591 views

How does the Craft Grid System work?

Plugins are able to extend Craft and embrace the existing UI nicely. While I'm comfortable extending it in many ways, I don't feel like I could clearly explain to somebody else how the grid system ...
9
votes
3answers
6k views

Plugin logging in Craft 3

How is logging handled in Craft 3? There's nothing mentioned in the docs at all. None of the below exist. Craft::log() MyPlugin::log() MyPlugin::$plugin->log() I'm not seeing any logging in any of ...
9
votes
3answers
4k views

Any good tutorial for plugin developement? I am entirely lost

I understand Craft Templating pretty well, but when it comes to programmation I am entirely lost, I don't get how it works. I used to use CodeIgniter a lot, which is a MVC as you guys may know. In ...
9
votes
2answers
1k views

Plugin Dev - Load third party library

What is the preferred way of loading a third party library in a plugin? I'm trying to develop a plugin to extend SproutForms so that users get signed up to Campaign Monitor. So far I've got an ...
9
votes
2answers
8k views

Does Craft CMS have an API?

Does Craft CMS have an API that third-party webapps can access? Maybe a REST API which you can log in to and send GET, PUT, POST, DELETE commands to, from a third-party app? It seems like it should ...
9
votes
1answer
772 views

How can I add a RichText-Field to my plugin's CP-section?

I'm trying to add a redactor richtext field to one of my plugin templates in the CP. I found macros for every field in craft/app/templates/_includes/forms, but a richtext macro is missing. I assume ...
9
votes
1answer
2k views

How to iterate over matrix field from a plugin

I'm writing a plugin where I have the id of an entry, that entry has a matrix field, and I want to iterate over the blocks of the matrix field. In php. How do I do that? Pointers to good documentation ...
9
votes
2answers
515 views

How to integrate custom statuses in a workflow style custom element type?

I made a lot of progress on my custom element type from this post and with the help of @selvinortiz: Best way to implement my own statuses on my custom element type? I know have custom statuses that ...
9
votes
1answer
546 views

How can I best extend TagModel to add a `count` property?

I'm attempting to write a plugin to extend tags by adding a count property that'd be useful identifying popular tags, making a tag cloud, and anything else where a count would be useful. The Goal ...
9
votes
1answer
977 views

How do I save a Matrix field with an asset block programmatically? [closed]

I'm trying to submit an Entry programmatically from the front end. Everything works flawlessly, except, the asset fields never save. I've dug and dug through the Entries, Elements, and Content ...
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 ...
8
votes
2answers
5k views

Can you save a variable in session?

Is there any way to save a variable in the Craft session inside a controller? I'm running a cron job and I need to store a variable as a session for every run to see if a condition matches.
8
votes
3answers
2k views

Craft 3 plugins - Logging in a separate *.log file

In Craft 2, it was possible to have your plugin log to a separate file. For example, it would record items to a myplugin.log file. You would simply be able to do it like this... MyPlugin::log('Lorem ...
8
votes
2answers
2k views

How does a plugin include it's own config options?

When building a plugin, how does one define user editable config files? Would it be better to create a settings UI in the plugin and have the user edit those variables in the CP? Or is there a way to ...
8
votes
1answer
814 views

How do I maintain the on value with a lightswitch-field as a plugin setting?

I'm trying to use a lightswitch-field in a plugin-config. But for some reason it won't get saved. The lightswitch-field is always off. protected function defineSettings() { return array( ....
8
votes
1answer
3k views

Get all entries from a channel

Is there any known way to get all the entries from a certain channel? I dont want to do this in a view but in PHP since i need to do a bulk update of an attribute to all the entries in a certain ...
8
votes
1answer
417 views

Using Commerce to pay for posting entry

I'm trying to figure out how to do the following: Person registers as new user User creates a new entry with a front-end entry form Entry is saved as disabled so it's not publicly visible User has ...
8
votes
1answer
1k views

How to make use of Element Types

I am building a plugin in Craft, I want to use the Element Types, the documentation seems so hard to grasp. Can you give an example or a template code?
8
votes
1answer
504 views

Console script tags garbling up non-html output (e.g. json) when in devMode

I have a plugin returning json from a controller action using $this->returnJson(...). Works great in production, but when devMode = true, the json is invalidated because Craft is still dumping the ...
8
votes
1answer
1k views

How do I handle named route variables passed to a controller?

I'm writing a plugin that uses the registerSiteRoutes hook to create some new routes, and passes those routes to some controllers. In these routes, I have a few pieces of the URL that I'm capturing as ...
8
votes
2answers
2k views

How do I get model/record attributes in their proper types, and not just strings?

Here's my record (model is nearly identical): namespace Craft; class Recurly_PlanRecord extends BaseRecord { public function getTableName() { return 'recurly_plans'; } protected ...
8
votes
1answer
3k views

Documentation on creating tasks

I'm looking to integrate tasks into a plugin I'm building. Whilst I know that the Craft documentation shows the Tasks Service/Model properties/methods in the full class reference, I can't find ...
8
votes
1answer
673 views

Is it possible to hook into image transforms?

I have a somewhat unique thumbnail need for a certain site. I need to watermark images with custom text (per image, not globally across the site). Is there a way to hook into the Craft image transform ...
7
votes
2answers
3k views

How do I reference the settings of my plugin?

In the main Plugin.php file of my plugin, I can retrieve the plugin's settings like this: $this->getSettings() How do I retrieve those same settings from elsewhere in the plugin? I want to ...
7
votes
2answers
3k views

How to redirect from plugin?

My plugin init function: function init(){ craft()->entries->onSaveEntry = function(Event $event) { //redirect to wanted url }; } Is there a fancy way to redirect to my ...
7
votes
4answers
4k views

Has anyone been able to get auto-complete working with plugins + PHPStorm?

It would make my day to be able to have PHPStorm recognize third-party services. Has anyone figured out how to get this working yet?
7
votes
3answers
4k views

How to retrieve Site Url and Site Name in Plugin

I'm having an exceedingly difficult time trying to retrieve the Site URL and Name in a custom plugin I am developing. My research has led me to believe this would work: $envVar = craft()->config-&...
7
votes
2answers
3k views

How to add a custom button at the right section of an entry?

I would like to add a custom button in the right section of a channels entry form in the CMS. The this button needs to go to a custom url of the plugin that I have created. The link should contain ...
7
votes
1answer
3k views

Custom Log in Craft

Is there any way to create a custom log in Craft? I need to log some actions inside a controller/service in a custom plugin.
7
votes
1answer
1k views

Is it possible to use the ElementType Modal UI for a custom Field Type Plugin?

So I'm writing a plugin to try and create a relationship between two entry sections that is a two way street (Many to Many). I would love to co-opt the UI and functionality of the ElementType modal ...
7
votes
2answers
1k views

How do you create a custom Twig tag?

Say I'm building a plugin that adds user memberships to the website. I want to check on my front end templates that user's membership is active and I have built the functionality inside the plugin to ...
7
votes
3answers
16k views

How do I prevent Twig from encoding HTML?

I've created a field type that stores its value as a model. That model’s __toString() method returns the result of a craft()->templates->render() call: public function render() { $render = ...

1
2 3 4 5
35