Questions tagged [plugin-development]

Questions having to do with constructing plugins.

Filter by
Sorted by
Tagged with
7
votes
3answers
2k views

Render generic message/error template from plugin

Basically, I'm trying to emulate show_error from EE/CI: http://ellislab.com/codeigniter/user-guide/general/errors.html I want to just use the generic Craft error template (/craft/app/templates/error....
7
votes
3answers
2k views

Craft Commerce: Validation on Address Fields

Can someone break down how I should validate empty address fields as a plugin for Craft Commerce and take the following answer further? The Craft Commerce documentation provides the following example ...
7
votes
2answers
692 views

How can I pre-raw a Model attribute for the Twig template? (ie. "myModel.myAttr" without requiring the raw filter)

I have a model that returns markup as part of a variable. To escape twig's encoding we have to include the raw filter, like so : {{ entry.customField | raw }} The encoded output of that field is ...
7
votes
1answer
1k views

How do I add a block to a matrix that already has content via a plugin?

I'm building a plugin that adds blocks to a matrix in an entry from the front end. I got it up and running by following the answer in this post: How to save a matrix content of a new entry in my ...
7
votes
2answers
645 views

How do I fix getTemplatesPath() / setTemplatesPath() deprecation errors?

After updating to Craft 2.6.2778, my plugin is causing these deprecation errors: PathService::getTemplatesPath() has been deprecated. Use TemplatesService::getTemplatesPath() or TemplatesService::...
7
votes
1answer
1k views

How can I do more complicated queries with an ElementCriteriaModel?

I need to join my 3rd party table with a standard ElementCriteriaModel (ECM). I'd like to start with an ordinary ECM, so my plugin will be compatible with any element type which may exist, now or in ...
7
votes
1answer
607 views

Hello World Craft Plugin

I am a Joomla developer who has been asked to start developing Craft plugins and I'm afraid my brain is so moulded to the joomla way of doing things that I cannot even see how the template links to ...
7
votes
3answers
2k views

Getting all content, including Matrix fields from an EntryModel

Initially I was doing $entry->getContent()->getAttributes(), but noticed my Matrix fields were all null. What is the right way to do this? I see that $entry->myMatrixField gives me the ...
7
votes
1answer
842 views

Updating an entry after an event action within onSaveEntry

I have written a plugin that checks if an entry has been saved and sends the user an email from within an onSaveEntry event. This works fine. But I now need to also update this entry to flag that an ...
7
votes
2answers
839 views

Best way to use custom enums in my plugin templates?

I am building a plugin that's uses an enum for custom statuses. The statuses are integrated within my plugin with the exception of changing the status in my template code. pluginname/enums/...
7
votes
1answer
142 views

In my element type index view, why is the first column always empty?

I am creating a simple Element Type to hold form submissions, but I have hit a wall with this one issue I am having. For some reason I cannot get anything to output in the first column of my element ...
6
votes
1answer
7k views

How to display a flash message in a template

I have a plugin that accepts a form post. I need to return a notice or error, plus the original data. Starting with the notice/error first, I have tried this: if (craft()->broadbean_jobs->...
6
votes
4answers
8k views

Prescribed way to set cookies (from plugin or Twig)

From either a plugin or a Twig template, is there a prescribed way to set (and get) cookies? I've seen https://github.com/lewisjenkins/craft-lj-cookies/, which just uses PHP's setcookie. Also ...
6
votes
2answers
1k views

Can we define routes (non-CP) in plugins?

I don't suspect it's currently possible but I would be pleasantly surprised to find that it is. I'm going to use an example from Django because I've seen it used there and a similar implementation ...
6
votes
3answers
2k views

Tasks and Steps

I need to implement a bunch of background processes that do things like send emails, query 3rd pary api etc. I have the task in place, but i dont fully understand how steps work, docs are a little ...
6
votes
3answers
773 views

Fetch entries with special characters in title

When trying to fetch an entry with special characters in the title, it doesn't seem to match. $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->title = "Title,with,...
6
votes
2answers
1k views

How do I save a Plugin's date settings-field?

I've got a plugin with some custom settings, like this: protected function defineSettings() { return array( 'serviceendpoint' => array(AttributeType::String, 'required'=>...
6
votes
1answer
2k views

ActiveRecord defineAttributes()

I have just started to build my first plugin with Craft CMS. Im at the part where I want to defne my database table. http://buildwithcraft.com/docs/plugins/database For the method definedAttributes(...
6
votes
2answers
2k views

Custom Field Type with Multiple Values

I'd like to create a field type for my plugin called "location" with two text boxes: one that holds a coordinate for latitude, and one for longitude. I haven't figured out yet how to map those two ...
6
votes
1answer
196 views

Best practices for plugin service/controller/etc file names

When it comes to naming files within a plugin - is it preferable to follow PluginHandle_SomeController, or stuff everything inside a single PluginHandleController file? This is probably a subjective ...
6
votes
1answer
1k views

Adding a RESTful, OAuth API on top of Craft

I’m currently considering options for a project that will require a standard sales site, commerce features and a user database. The user database will require a web frontend and an API for ...
6
votes
1answer
966 views

Craft CMS plugin route redirects to login when not logged into Craft

I created a simple Craft plugin to allow for custom action URLs. Specifically, I have a path "actions/api/sendEmail" that hits a method in my plugin's controller. It sends an email from a contact form ...
6
votes
1answer
1k views

How can I add custom validation rules to my plugin settings?

I have a plugin that needs to perform some custom validation on one of its settings. How would I go about doing that?
6
votes
2answers
493 views

Suspended users who have never logged in

This may sound paradoxal but here it is. Membership based site. A new user starts as suspended. An admin unsuspends. The user uses the system. If a membership expires, a user gets suspended again ...
6
votes
1answer
2k 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 [...
6
votes
2answers
3k views

Is it possible to access Twig variables in a plugin variable using PHP?

I have a controller that returns route variables to the page: craft()->urlManager->setRouteVariables(array( 'errors' => $entry->getErrors() )); On the page that gets loaded, I can ...
6
votes
1answer
884 views

How does craft deal with Plugin databases when updating plugin versions?

Quick scenario. I build a plugin with a database. Few months down the line I want to upgrade this plugin which will alter the plugin DB. If installing an update to a plugin how does craft deal with ...
6
votes
1answer
494 views

Display thumbnail using defineTableAttributes for a custom Element Type

Hi, I'm new to Craft and VERY new to plugin development. I'd like to display a thumbnail image in my table list view and thought it would be possible to accomplish using a new Custom Element Type. ...
6
votes
1answer
1k views

How can I follow relations in ElementCriteriaModels from plugin code?

In Twig code you can use craft->entries->relatedTo to do all sorts of neat things. From plugin code I am not sure how this works? $c = craft()->elements->getCriteria(ElementType::Entry)...
6
votes
1answer
877 views

Craft ships with PHPUnit... How can we use it to test our plugins?

Since Craft ships with a copy of PHPUnit, is it possible to use that to run tests on a plugin? Or do we need to have a separate copy installed?
6
votes
1answer
1k views

What's the best way to clear cached JSON responses from a third-party API?

I'm building a plugin to browse store orders via a third-party API. I make various requests to URLs that can include query parameters: /customers /orders/e8b48e72-9c7f-4d6f-91aa-2f7238bdf936 /orders?...
6
votes
1answer
581 views

What are the best-practices for useful logging messages?

I'm currently adding messages to the log when an error occurs in my plugin. Now I'm wondering what such a message should contain, to provide useful information to developers and end-users? . ...
6
votes
1answer
878 views

Get related entry data within a plugin (ElementCriteriaModel) without extra queries

I have the following code: $criteria = craft()->elements->getCriteria(ElementType::Entry); $criteria->section = 'submissions'; // Loop foreach ($criteria as $entry) { echo $entry->id....
6
votes
1answer
440 views

Make dump() available when devMode is disabled

Is there a way to make the dump() function available in my plugin templates when devMode is disabled?
6
votes
1answer
661 views

Is it possible to setRouteVariables when redirecting after a successful form submission?

I have a form. It submits. It saves. I'd like to pass the newly-created, complete form object back to the 'thank you' page template so that I can display the values that were submitted. I do not ...
6
votes
1answer
974 views

PHPUnit testing for Craft plugins or controllers

Is it possible to implement PHPUnit into Craft CMS? If so, where can I find a good explanation or tutorial? I already tried a Github link for a plugin (testing the plugin). But I am new to both but ...
6
votes
2answers
337 views

Delete / change Status from CP via Ajax (trigger event)

In a plugin init function I'm listening to entries.saveEntry and entries.deleteEntry. This works perfectly if I'm editing entries from their detail view. If I 'bulk' change or delete entries, these ...
6
votes
1answer
505 views

Filtering and sorting lists in a plugin

Whats the recommended way to have javascript based filtering and sort table views in a plugin tab? Is is possible to use garnish to do that or should we be looking at external libraries like: http:...
6
votes
1answer
681 views

Allow anonymous submission on a custom element type?

I have a custom element type that I want to allow anonymous submission from the front-end. I have a solid concept on how the form data is passed but I seem to be missing something. I have the ...
6
votes
1answer
412 views

Any workarounds for image resizing in Craft 2.5 Redactor II?

Since imageResizable was deprecated for some apparent reason which I have no idea why they would do that. Does anyone know of a workaround or a plugin/config setting to enable this again?
6
votes
1answer
596 views

Using Yiic for plugin migration

I've been trying to follow the docs for creating a plugin migration (https://craftcms.com/docs/plugins/migrations) but any attempts to run yiic seem to die with: CDbConnection failed to open the DB ...
6
votes
1answer
427 views

Form input not being disabled

In the plugin I'm creating I've got a form that has inputs which are set as disabled if they are overridden in a conifg file. The problem that is occurring is that disabled class is added to the ...
5
votes
4answers
1k views

Memory issue when updating all entries from a channel (allowed memory size of X bytes exhausted (tried to allocate Y bytes))

I'm trying to do a stock update for all entries within a channel with a cronjob once a day, and I can't achieve it, because I always get Allowed memory size of X bytes exhausted (tried to allocate Y ...
5
votes
2answers
3k views

How to render plugin templates in Craft CMS 3?

I cannot find a way to render templates from a plugin controller in Craft 3. I feel as though I've tried every variation advised online but for some reason this still isn't working. <?php ...
5
votes
4answers
1k views

How can I set the HTTP status code?

I'm trying to set a 404 HTTP status response code for an ajax controller action in a plugin. Yii has a response object where the code can be set, but I can't find a way to access it from craft.
5
votes
2answers
3k views

User events in Craft 3

How do I capture user events in Craft 3? I looked at the documentation but couldn't figure it out. I need to capture after user registration events and after user save events. Here is what I tried, ...
5
votes
1answer
1k views

Where do I run validation before database insert?

I'm trying to wrap my head around when to use a Model and when to use a Record (or both?). I have both my Model and my Record. In my Controller I call my Service that creates my new Record instance ...
5
votes
1answer
1k views

How to programmatically update a plugin's settings?

Is there a way to programatically update a plugin's settings? I'm experimenting with setSettings() but not really getting anywhere - I'm still quite new to plugin development so there's a good chance ...
5
votes
1answer
555 views

Get the type of action and the elements(s) that an action is being performed on when listening to elements.onPerformAction?

I have a plugin that needs to do something when an entry is deleted. I've recently discovered that the entries.deleteEntry event is not fired when deleting bulk entries (the list view with checkboxes) ...
5
votes
1answer
1k views

How do I get elements using getCriteria from a specific date?

I'm trying to get elements in a section created on a specific date. How do I do that? This is what I've been trying with: $criteria = craft()->elements->getCriteria(ElementType::...

1
2
3 4 5
35