Need new hook
6 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: March 31, 2011 (RSS)
By jenolan - March 28, 2011
One thing I want to do is a similar thing to the breadcrumb, when a record is created/saved I need to set a value before the record is updated. The existing 'record_presave' doesn't actually let you set a value that is set to none as putting the value into the $_REQUEST array is ignored by the function _getRecordValuesFromFormInput, and if it is not 'none' then it is included in the edit when it is a 'display only' value.
I can do it by re-reading the record and then doing a save but that seems hugely wasteful. What would be the nicest is a new field type of 'hidden' that could still be set in the presave call but not displayed for edit.
Thanks,
Larry
Peace and Long Life
Re: [jenolan] Need new hook
By jenolan - March 29, 2011
Oh yeah .. being able to hide a table totally, I know I could create one outside the name space but I want to keep everything installable/uninstallable from within cms Builder [cool]
Peace and Long Life
Re: [jenolan] Need new hook
By Dave - March 29, 2011
For adding a field after the fact the easiest is to do it with the record_postsave hook and update it after the fact. This gives you the record number as well if you need that (which isn't available beforehand when creating records).
It's true that it's not the most efficient way, but save doesn't get called very much (relative to the code on viewer pages) and it's still fractions of a second.
As for indexes, that is on our (and my) wishlist, but for now you need to do it manually. A good place would be in the same code that creates your schemas when the plugin is actived.
For hiding tables, we usually set menuHidden = 1 in the schema which hides it from the menu but still have it accessible by direct link or from the section editors menu. Also we prefix tables with _ so as to not conflict with any user created tables (user tables must start with a letter).
Hope that helps! Any questions let me know.
interactivetools.com
Re: [Dave] Need new hook
By jenolan - March 29, 2011
There is no hook called for plugin activate/deactivate for a hook pr have I missed something obvious?
Larry
Peace and Long Life
Re: [jenolan] Need new hook
By jenolan - March 29, 2011
function activatePlugin($file) {
global $SETTINGS;
// test for errors - if this dies it won't activate the plugin
$pluginsDir = "{$GLOBALS['PROGRAM_DIR']}/plugins";
include "$pluginsDir/$file";
// add plugin to list
$activePluginFiles = array();
$activePluginFiles[$file] = 1;
foreach (preg_split('/,\s+/', $SETTINGS['activePlugins']) as $activeFile) {
$activePluginFiles[$activeFile] = 1;
}
// save settings
$GLOBALS['SETTINGS']['activePlugins'] = join(', ', array_keys($activePluginFiles));
saveINI(SETTINGS_FILEPATH, $SETTINGS, 'sortKeys');
doAction( 'plugin_activate', $file );
}
function deactivatePlugin($file) {
global $SETTINGS;
// remove plugin from list
$activePluginFiles = array();
foreach (preg_split('/,\s+/', $SETTINGS['activePlugins']) as $activeFile) {
$activePluginFiles[$activeFile] = 1;
}
unset($activePluginFiles[$file]);
// save settings
$GLOBALS['SETTINGS']['activePlugins'] = join(', ', array_keys($activePluginFiles));
saveINI(SETTINGS_FILEPATH, $SETTINGS, 'sortKeys');
doAction( 'plugin_deactivate', $file );
}
Peace and Long Life
Re: [jenolan] Need new hook
By Dave - March 31, 2011
That's a good idea, I've added both of those to 2.08. You can add them to your code manually and know they'll be in the next release.
Another way I sometimes create schemas is like this (from outgoing SMSl):
$GLOBALS['OUTGOING_SMS_TABLENAME'] = '_outgoing_sms';
addAction('admin_postlogin', '_outgoingSMS_createSchema', null, 0);
...
//
function _outgoingSMS_createSchema() {
$tableName = $GLOBALS['OUTGOING_SMS_TABLENAME'];
$sourcePath = dirname(__FILE__) . "/$tableName.ini.php";
createSchemaFromFile( $sourcePath );
}
And then I add other code in there as needed.
Let me know any other questions or suggestions. Thanks!
interactivetools.com