Bugfix and improvements for custom function

fabio84 - October 12, 2009 - 10:10
Project:Views Calc
Version:6.x-1.3
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:needs review
Description

As pointed out in http://drupal.org/node/552310 documentation for "custom function" was lacking, so i had to dive into the code to figure it out.

I found a bug: in line 86 of views_calc_field_handler.inc, it checks "if ($function == 'custom')", but $function here will contain '' in case of custom function. It should check "if ($this->definition['format'] == 'custom')".

I found also a limit in custom definition: it uses the format "function_name:param", and you can use only a custom parameter. I extended it to allow usage of the format "function_name:param1:param2:...", converted in "function_name($value,param1,param2,...)".

However I think this is yet a strong limitation, so I added the format "php" that allows to define custom php code using $value to get and update field value.

Now the limitation is that the "custom" field is stored in the database as a varchar(255), and may be better to upgrade it to a "text" field.

The attached patch works form me with the last stable version (6.x-1.3)

AttachmentSize
views_calc-custom_php.patch3.29 KB
 
 

Drupal is a registered trademark of Dries Buytaert.