Hot answers tagged

7

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()) { $variables['year'] ... }


4

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 their response based on the $source that is passed in. In EntryElementType’s case, if an unrecognized $source is passed in, then no actions will be returned. ...


4

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 modifyEntryTableAttributes(&$attributes, $source) { if ($source == 'section:3') { // insert column in first position (using array_merge) $...


4

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 Builder to see how Yii/Craft handles MySQL queries. You can also look at examples Craft source code.


3

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 batch-deleting all of the selected elements. That functionality is provided by Element Action classes.


3

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 the entry list displayed at /admin/settings/entries), not relational fields (such as Entries, which is what you're using in your SuperTable). The easiest ...


3

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', function(Event $event) { // ... }); There's a nifty Craft plugin scaffold generator to get you started here, too.


3

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.


3

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 {% endcache %} tag. So, the results of the PHP-based query will be cached with the rest of whatever is between the tags only for use in that instance as HTML. If your ...


3

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 is a hangover from Craft 2 (and also ExpressionEngine), where "hooks" were used to inject custom back end code. In Craft 3 however, everything is ...


2

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 only time that your plugin can actually affect what is shown in the dropdown is the first time it’s called, on page load. Maybe a better way to go about this ...


2

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 to do this would be to write your own custom Craft plugin that listens to Contact Form's beforeSend event. When that event gets fired, you can make an AJAX ...


2

Currently, no. But it is on our radar and we've got some ideas on how we'd want to implement it.


2

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 ($source == 'section:3') { // unset all column attributes unset($attributes['title']); unset($attributes['uri']); unset($...


2

"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, but all elements (entries, tags, categories, users, etc.) have sources behind the scenes. See the CategorySources plugin for an example of how it might be used (...


2

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 between the {% cache %} and {% endcache %} tags), cache it for later, and output it. So I don't think you need to do anything special. Your hook will be run (...


2

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 the elements(s) that an action is being performed on when listening to elements.onPerformAction?


2

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 official documentation, you can access using the craft()->on() syntax, so I did this inside my plugin class : public function init() { parent::init(); ...


2

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 available after your hook tag. If you just need to return some text or an array, a variable will do the trick just fine!


2

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 entry just let it save. If it's an existing entry, check the dateCreated date against your window and see if it's still valid. If it's outside of your window you ...


2

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 other entries, leaving only the most recent inside the list. This code does work, without overwriting: parent::init(); craft()->on('entries.onSaveEntry', ...


2

Check out Craft::$app->getElements()->getElementByUri() -- or you might also use Craft::$app->getUrlManager()->getMatchedElement() depending on your use case. Your friendly neighborhood SEOmatic author :)


2

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] method. UPDATE: I'm not exactly sure what your setup is — but some variation on the following should work for you. In the CMS, add a field called 'invoiceID'...


2

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 point or use https://pluginfactory.io to generate boilerplate plugin code.


1

Have you already seen the workflow plugin? Maybe it could give you some inputs for your further development: https://github.com/engram-design/Workflow.


1

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 service // Import the event from the other plugin Craft::import('plugins.otherPluginHandle.events.OtherPluginEvent'); /Initialise the plugins event and pass ...


1

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 is for dealing with the form submissions. I had to simply change my listener to craft()->on('capture_submissions.onPost', function(Event $event){...}); and ...


1

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 index page of the Section, click on the settings icon found on the left side bar, ensure you are on the section to show/hide the columns. Hope this is useful for ...


1

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 you should be able to use the traditional Yii method, though. Something like this: $myRecord->onAfterDelete = function (Event $event) { // Do your thing. ...


1

If I understand correctly, the $context variable passed to my hook should be a reference to that summary object. Nope... $context is a reference to the entire Twig rendering context of which your bookings objects will be a part of. You can use xDebug or var_dump to see where your bookings objects are stored and loop though them as necessary from PHP.


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