Hot answers tagged

19

So, when I'm doing BR related add-ons - I work in isolation a lot of the time only hitting BR once and then using Action ID's to perform the development test work. So, first thing you're going to need to do is create your hook as normal and install an empty add-on. You'll need to do this anyway, so it makes sense to do it. You also want to register the ...


18

Hooks are rather abstract and require you to have a working plugin/module with your own hooks setup. So before you go any further I would be sure you have a good grasp on how to use the most basic forms of hooks. It might be wise to even write a simple extension just to go through the process. Postmaster extends ExpressionEngine's native handling of hooks. ...


17

That should work fine, but you can also check the REQ constant (docs) which has the following possible values: CP - Control panel requests PAGE - Frontend template requests ACTION - Module actions, e.g. mysite.com/?ACT=123 For example: if (REQ == 'CP') { return FALSE; }


10

Yes. For example.... $hooks = array( "template_fetch_template" => "template_fetch_template", "typography_parse_type_end" => "typography_parse_type_end" ); foreach ($hooks as $hook => $method) { $data = array( 'class' => __CLASS__, 'method' => $method, 'hook' => $hook, ...


9

Yip. You're looking for: ee()->session->userdata('member_id'); It's in the session class: http://ellislab.com/expressionengine/user-guide/development/usage/session.html


8

This is array_keys($row): Array ( [0] => template_id [1] => site_id [2] => group_id [3] => template_name [4] => save_template_file [5] => template_type [6] => template_data [7] => template_notes [8] => edit_date [9] => last_author_id [10] => cache [11] => refresh [12] =&...


6

I worked through this with Justin and wanted to post this so others can use it. Basically I have a mod file with a custom function that logs when an image is downloaded. My variables are all logged after being set up. Here's the variables: $my_download = array(); $my_download["size"] = $image_size; $my_download["entry_id"] = $entry_id; $...


5

I would assume so. Instead of asking yourself what hook replaces what hook, ask yourself if this describes the hook you need: Additional processing after entry submission, after all processing, prior to redirect. If so, entry_submission_absolute_end should be the hook you want :-) You'll get the _entry_id, an array of meta data and an array of actual ...


5

I got it working.... silly, silly, silly me.... Initially I used entry_submission_end($entry_id, $meta, $data), but realised I needed entry_submission_ready. I overlooked the fact entry_submission_ready uses different arguments, its ($meta, $data, $autosave) and not ($entry_id, $meta, $data)! Now it works fine with the correct arguments. RTFM!


5

This was driving me insane but I've figured it out. You need to edit the $entry object (1st parameter of the function) in order for this to work. You can, however, use the 2nd parameter, $values, for easy reading of the data. public function before_channel_entry_save( $entry, $values ) { // Set value for specific field name $entry->setProperty( '...


4

Unfortunately, there is no hook that runs after creating new categories, which is a shame. (You can find a list of available extension hooks here.) You could try writing an extension that uses the sessions_end hook, then checks for the various $_GET variables that indicate that you just created a new category, but that wouldn't account for times when ...


4

The entry_submission_start hook doesn't pass an $entry_id, because the entry should not have been saved yet. It only passes a $channel_id and a boolean value for $autosave. (Docs.) I see your function (which is presumably the function you've installed as the callback for entry_submission_start in your extension) is expecting three parameters ($entry_id, $...


4

Something is way off about your approach. You should not need the ob_start() methods if you were to build this properly. If you need a callback method, what you really want to look into is a using a module for a "controller". (For more info on a controller, refer to CodeIgniter's MVC pattern.) So could create an ACT url (http://yourdomain.com/ACT=X) and ...


4

That hook gives you all the data you need to query the database. $meta will hold your entry_id, channel_id, title, etc (anything that goes in exp_channel_titles), and $data holds your custom field data. So just as an example: if(!empty($meta['entry_id'])) { $current = $this->EE->db->query(" SELECT * FROM exp_channel_data WHERE entry_id ...


4

It mainly goes down to processing order. When the order is successfully placed Store then does a little housekeeping to round off the order completion process. It will look to set a default status before checking for any extensions latching on to the store_order_complete_end hook. So walking through the process with your specific extension code: Order is ...


3

After tinkering around, I found out that the way to do it is to set these values inside the method $this->EE->api_channel_entries->data['my_field_id'] = 'my_field_value';


3

It looks like the hooks were running, but it was more a case of the logged messages not appearing. Store uses the Post-Redirect-Get pattern, which means that the cart is updated (and hooks run) during an HTTP POST request. When the cart has finished updating (unless there were any errors), it redirects the customer's browser back to the checkout page using ...


3

It looks like there is a problem with the logic in your extension. You don't want to change the name of a particular status when the order is complete - you want to change the status of the order. I would expect it to look something more like this: public function store_order_complete_end($order) { if (ee()->session->userdata('group_id') == 10) ...


3

Yes I don't see any problem with that if it's just for a simple tax adjustment. We don't look to make things deliberately hard. :) You could also look to set it up as an actual tax adjustment if you wanted to however. Adjustments were introduced in Store v2 to handle extra line items for anything which is not a product (e.g. shipping, discounts, taxes). ...


3

It depends on whether the events that trigger the functions trigger a hook. If a button click, form submission, page load etc triggers a hook, then an extension is the right place for your custom functionality. If no hook is triggered and you need to respond to arbitrary clicks or form submissions, then a module or plugin would be appropriate. You can react ...


3

Extensions are for backend or server side stuff, whereas Modules can interact via the frontend or EE Control Panel. So an Extension captures a hook from another class, but can't capture a form submission or Ajax call from the frontend. Whereas a Module can't tap into a hook. But you can roll both an extension and a module into a single add-on (same name, ...


2

If you look at Activating & Updating in the Extensions documentation, you'll see in the code example that the data passed to the Insert query contains a reference to an ExpressionEngine hook. That database entry will enable your extension to be called when that hook is triggered. All available hooks are documented here.


2

Yes, it can be a bit tricky to get into it at first. What you're looking for are the Extension docs: http://ellislab.com/expressionengine/user-guide/development/extensions.html An extension can be included alongside a module. The code that you posted is the actual code called within EE when loading any extensions attached to that hook. Thus all the ...


2

I just want to point out that BrilliantRetail has methods for handling IPN callbacks when creating custom gateways. I would consider using the core methods instead of putting logic in templates or files outside of the ExpressionEngine system: http://docs.brilliantretail.com/3-extending-brilliantretail/payment-gateways/index.html#ipn-methods The PayPal ...


2

First - you can get this count in your template by using {my_matrix_field:total_rows} - but I'll assume you need the number stored as a value in a field for other purposes (use in orderby perhaps). In which case - yes, you'd write an extension, and use the entry_submission_ready hook. Then in your method, pass $data by reference, so you can modify it. ...


2

You should look into "URI Class"


2

No, there isn't any hook for it. You might see this question/answer Track logged-in user events which seems much similar to your need.


2

You can compare $meta['edit_date'] with $meta['entry_date']. You will need to bring both dates to same format of course, as entry_date contains current timestamp, while edit_date is formatted as '%Y%m%d%H%i%s'


2

I usually check if entry_id = 0 (for new entry) $this->EE->input->get_post('entry_id') == 0


2

I have got it to work using a second hook, channel_form_submit_entry_start Using channel_form_submit_entry_start I can manipulate the $_POST array directly, then this saves. Seems wrong I should manipulate $_POST, and also a shame I have to have a second method to do the same as the entry_submission_ready (difficult to combine as I am using different arrays)...


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