Hot answers tagged

7 votes
Accepted

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

To quote @Brandon from here: Yep you just need to include a $variables argument in your controller function, typeset to an array: public function actionArchive(array $variables = array()) { $...
user avatar
4 votes
Accepted

Element Actions for Entries being viewed from modifyEntrySources

The checkboxes will only show up if there is at least one available element action for the current source. Element actions are defined by element types’ getAvailableActions() methods, which will vary ...
user avatar
4 votes
Accepted

How to change the display order of columns in Entry List view?

You need to reorder the $attributes array to do this. You can do this in various ways, here is how I would do it depending on the position you wanted for the new column: public function ...
user avatar
  • 6,326
4 votes
Accepted

Incorporating data from an external database into Craft pages

That solution makes sense! I have used a similar strategy. You should absolutely cache around the template hook, or cache the database calls in the plugin itself. Take a look at the Yii Query ...
user avatar
3 votes
Accepted

How to create custom option/action for backend entry lists

Indeed there is! You're looking for Element Actions... When you select elements on their index pages, the regular toolbar options get replaced with new ones that will trigger various actions, like ...
user avatar
  • 23.6k
3 votes
Accepted

How to show details on linked entry in CP (another field inside related entry)

Basically, what you want to do isn't possible – there's no hook for modifying the content in a relational field's input HTML. The getEntryTableAttributeHtml hook is meant for element indexes (such as ...
user avatar
3 votes
Accepted

Where do I put code to use hooks and events from Squarebit's 'Charge' plugin?

You'd listen to Charge's onCharge event just like you'd listen to any of Craft's own events, using a plugin. Your plugin's init() method, for example could do this: craft()->on('charge.onCharge', ...
user avatar
  • 66.5k
3 votes
Accepted

Add custom column to Entry Type index page

Unfortunately, that's not possible currently. If you feel that a hook for customizing the Entry Type listing/index should exist, you can add a feature request.
user avatar
3 votes
Accepted

Template Hook + Caching

Yes, sort of. As soon as the rendering template hits a {% cache %} tag, Craft grabs the outputted content from the cache table in the database and ignores all other template logic until the {% ...
user avatar
3 votes

Help understanding hooks

First I think it helps to clear up some terminology... I've seen a few devs (myself included sometimes!) using the word "hooks" when they really mean "events". For me at least this ...
user avatar
  • 3,959
2 votes
Accepted

Updating index tables' sortable attributes on AJAX

The modifyEntrySortableAttributes technically gets called each time you load new elements on the index page, just so that the controller can confirm that the posted order attribute is valid. But the ...
user avatar
2 votes

Pixel & Tonic's Contact Form Plugin - POST submissions to Zapier Webhook URL?

By putting the webhook URL in the action field, you're completely bypassing the Contact Form's processing of the POST request and getting back a JSON response from Zapier. I believe the correct way ...
user avatar
  • 66.5k
2 votes

Hook into rendered templates?

Currently, no. But it is on our radar and we've got some ideas on how we'd want to implement it.
user avatar
  • 66.5k
2 votes

How to change the display order of columns in Entry List view?

As far as I can tell, you would need to unset all of the native columns and then reset them in the desired order. public function modifyEntryTableAttributes(&$attributes, $source) { if ($...
user avatar
2 votes
Accepted

What does the 'modifyEntrySources' hook do?

"Source" is in the context of "where an element is pulling its data from". The easiest example is with Assets, because they have easily defined Asset Sources settings portion of the control panel, ...
user avatar
  • 66.5k
2 votes

Template Hook + Caching

My understanding is that the {% cache %} tag operates like a conditional. If it succeeds (cache hit), then output the cached value. If it fails (cache miss), then calculate the value (run everything ...
user avatar
2 votes
Accepted

How to use onDeleteEntry?

I recently found that if your deleting an entry on the entries list, you need to use the onBeforePerformAction event. Then break this down, like J Thomas states on this - Get the type of action and ...
user avatar
2 votes
Accepted

Plugin add options to entry edition

Well I found the way lurking into source code. You can see a {# Give plugins a chance to add other panes here #} {% hook "cp.entries.edit.right-pane" %} Even though this hook is not listed in ...
user avatar
  • 271
2 votes
Accepted

Displaying an array returned from a hook

Template hooks are useful if you need to change the current twig context array somewhere inside of a template. If you make any changes to $context inside of your hook's function, those changes will be ...
user avatar
2 votes

Close entry editing after set time (for certain a user group)

Seems like you'd just need to write a plugin that listened to the onBeforeSaveEntry event. That plugin would check if the entry author is in the user group you're interested in, and if it's a new ...
user avatar
  • 66.5k
2 votes

Insert entry into article field (elementselect?) on a user, with the "onBeforeSaveEntry" hook

Sweet, solved it. Changed the line array_push($focusList, $entry); to array_push($focusList, $entry->id); and it worked! :D EDIT: NOPE, it did not fully work. This hook overwrites all the ...
user avatar
  • 245
2 votes
Accepted

Getting current entry element via plugin in Craft 3 without a hook

Check out Craft::$app->getElements()->getElementByUri() -- or you might also use Craft::$app->getUrlManager()->getMatchedElement() depending on your use case. Your friendly neighborhood ...
user avatar
2 votes
Accepted

How do I edit a dropdown field in the charge.onCharge hook?

In your current example, you are not actually saving an entry. You are just setting up an onSaveEntry event listener. To save the entry you will need to actually save the entry using the [saveEntry][1]...
user avatar
2 votes
Accepted

Where to call hook modifyImportRow?

You'd do it from another plugin, just as if you were latching onto any of Craft's native hooks. https://craftcms.com/docs/plugins/hooks-and-events You can use the businessLogic plugin as a starting ...
user avatar
  • 66.5k
2 votes
Accepted

Apply custom filter on the entries in admin control panel using custom plugin in craft cms 3.5

Found it!!! Used ElementQuery::EVENT_AFTER_PREPARE
user avatar
  • 41
1 vote

How should a multi-stage editorial process be implemented in Craft?

Have you already seen the workflow plugin? Maybe it could give you some inputs for your further development: https://github.com/engram-design/Workflow.
user avatar
  • 1,317
1 vote
Accepted

Can a plugin manually raise another plugin's Event?

I've built a plugin which uses it's own events before, I guess the way to do it would be the same for separate plugins, however this is untested for your use case. This should go in your plugin ...
user avatar
  • 4,519
1 vote
Accepted

How do I hook into Capture form onPost event?

I found the answer in a bit of a clumsy way, but the capture plugin has two services, capture_forms and capture_submissions. The first deals with saving the forms within the CraftCMS admin, the latter ...
user avatar
1 vote

Add custom column to Entry Type index page

If I understand your question correctly, you are looking to see your custom field in under the Entries index page of the Section. This is what I know from Craft CMS ver. 2.5 or 2.6 On the Entries ...
user avatar
  • 131
1 vote
Accepted

Hooking into event when record deleted from custom plugin

Because that's a Yii event, it doesn't follow the same component.eventName syntax that the other Craft events use and you can't use craft->on() to register to listen to it. Completely untested, but ...
user avatar
  • 66.5k

Only top scored, non community-wiki answers of a minimum length are eligible