Hook Request

5 posts by 2 authors in: Forums > CMS Builder: Plugins & Add-ons
Last Post: March 5, 2013   (RSS)

By ITI - March 5, 2013 - edited: March 5, 2013

Hi IA staff.

I'm creating a new plugin and with the current "Hook" list I am able to modify the "out put" to suit my plugin except in the "Section Editors" > "table" > "Field Editor".

In lib/database_functions.php, the function loadSchema($tableName, $schemaDir = '') is called prior to the "Field Editor" opening which over rides any plugin modification I have made else where.

Adding a hook in this function would allow for easy modifications to the "Field Editor" dialogue.

function loadSchema($tableName, $schemaDir = '') {
  global $APP;
  // error checking
  if (!$tableName)                                       { die(__FUNCTION__ . ": no tableName specified!"); }
  if (preg_match('/[^a-zA-Z0-9\-\_\(\)]+/', $tableName)) { die(__FUNCTION__ . ": tableName '" .htmlspecialchars($tableName). "' contains invalid characters!"); }

  // get schemapath
  $tableNameWithoutPrefix = getTableNameWithoutPrefix($tableName);
  if (!$schemaDir) { $schemaFilepath = DATA_DIR . "/schema/$tableNameWithoutPrefix.ini.php"; }
  else             { $schemaFilepath = "$schemaDir/". getTableNameWithoutPrefix($tableName) . ".ini.php"; }

  // load schema
  $schema = array();
  if (file_exists($schemaFilepath)) {
    $schema = loadStructOrINI($schemaFilepath);
  }

  // add _tableName (v2.16+)
  if ($schema) {
    $schema['_tableName'] = $tableNameWithoutPrefix;
  }

doAction("new_loadSchema_hook",$tableName,$schemaDir);
  //
  return $schema;
}

As side from solving my plugin issue, it would seem that this is an ideal location for more advance customization due to the existence of the 2nd parameter "$schemaDir". 

Would you consider adding a "hook" at this location in your next release?

Alternatively, can you suggest a way of intercepting the output to perform modifications?

Glen







http://www.CanadianDomainRegistry.ca







ITI Internetworking Technologies Inc.

By ITI - March 5, 2013

Hi Dave

Since writing the post, I believe I have found a better and more appropriate solution to my issue.

Basically I want to change the menuNames and set warnings in the interface if the plugin isn't activated. I can't have the end user modifying table data if the plugin isn't active since a lot of the input data is in hidden calculated fields.

I'm just in the process of testing the use of hooks "plugin_activate and plugin_deactivate".  These appear to be far more appropriate for what I am trying to achieve including the hiding the tables altogether (when not active).

Anyway, with all the code review and investigation I had done, there is no way (that I could find) to do any customization to the "Edit Field" dialog since the call to loadSchema() is just prior to showing the dialog content. I was mainly looking at the schema data not any of the global vars.

So, although it does look like I will need the hook I was asking about I still think it might be a useful hook for some thing else in the future.

My post should be revised to "A good place to add a hook" !

Thanks for getting back to me so quick.

Glen







http://www.CanadianDomainRegistry.ca







ITI Internetworking Technologies Inc.

By Dave - March 5, 2013

Hi Glen,

Ok, great.  Here's a few other things to check out if you haven't already seen them: 

Under Admin > Section Editors > Your Section > Advanced (Tab) there's a field called "Required Plugins".  If you put the filename only (eg: myplugin.php)  in that field the user won't be able to access the section unless that plugin is active.

You can also add this to a plugin header (in the comments at the top)  to force it load everytime and prevent it from being deactivated:

Required System Plugin: true

For hiding tables, you can set  'menuHidden' => '1', in the schema to hide the menu, and 'tableHidden' => '1', to hide the table from the section editor list.  We hide certain internal tables such as uploads, _accesslist, etc.

And in regards to the field editor, it's due for a rewrite but we haven't got to it yet.  So when it gets updated perhaps there will be more hooks.  Eventually we'd like to have able to have plugins add new field types.

Good luck with your plugin and let us know any other questions, thanks!

Dave Edis - Senior Developer
interactivetools.com

By ITI - March 5, 2013 - edited: March 6, 2013

Thanks Dave.

I was already using the "'menuHidden'" key in the plugin_activate/deactivate hooks which addressed the user input issues.

I was not aware of that schema key ''tableHidden'' which addresses my concerns in the section editor, thanks for  bringing that to my attention.  I've tested it and that works perfectly.

I don't think this will need to be a system plugin with the use of the keys mentioned above.

After entering the plugin file name in 'Required Plugins'  it didn't do any thing.  But I suspect it would if I required a plugin other than 'itself".  The two keys above do the trick so I won't pursue this.

I now understand how the "Required Plugin" works. It adds a little insurance but as with the keys, if the user manually edits the schema file we've lost control anyway.

Thanks for the tips.

Glen







http://www.CanadianDomainRegistry.ca







ITI Internetworking Technologies Inc.