From 24813061995523cb5d4c53994656f01eb7edaf1b Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 6 Sep 2024 20:06:12 -0400 Subject: [PATCH] Create two new events in the remote lib to allow loading custom plugin fields. --- interface/lib/classes/remoting_lib.inc.php | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/interface/lib/classes/remoting_lib.inc.php b/interface/lib/classes/remoting_lib.inc.php index 84d468a9d0..c8903cc644 100644 --- a/interface/lib/classes/remoting_lib.inc.php +++ b/interface/lib/classes/remoting_lib.inc.php @@ -82,11 +82,22 @@ class remoting_lib extends tform_base { //* Load the form definition from file. - special version for remoting // module parameter is only for compatibility with base class function loadFormDef($file, $module = '') { - global $app, $conf; + global $app; include $file; + // Search for module name by path because $_SESSION['s']['module']['name'] + // isn't set in a remote call. + $module_path = array_reverse(explode('/', $file)); + $module_name = isset($module_path[2]) && $module_path[1] == 'form' && preg_match("/^[a-z]{2,20}$/i", $module_path[2]) ? $module_path[2] : ''; + + // Allow plugins to be loaded + if ($module_name) { + $app->plugin->raiseEvent($module_name.':'.$form['name'] . ':on_remote_before_formdef', $this); + } + $this->formDef = $form; + unset($this->formDef['tabs']); //* Copy all fields from all tabs into one form definition @@ -97,6 +108,11 @@ class remoting_lib extends tform_base { } unset($form); + // Allow plugins to be loaded + if ($module_name) { + $app->plugin->raiseEvent($module_name.':'.$this->formDef['name'] . ':on_remote_after_formdef', $this); + } + $this->dateformat = 'Y-m-d'; //$app->lng('conf_format_dateshort'); $this->datetimeformat = 'Y-m-d H:i:s'; //$app->lng('conf_format_datetime'); @@ -203,14 +219,14 @@ class remoting_lib extends tform_base { function getSQL($record, $action = 'INSERT', $primary_id = 0, $sql_ext_where = '', $dummy = '') { global $app; - + // early usage. make sure _primary_id is sanitized if present. if ( isset($record['_primary_id']) && is_numeric($record['_primary_id'])) { $_primary_id = intval($record['_primary_id']); if ($_primary_id > 0) $this->primary_id_override = $_primary_id; } - + if(!is_array($this->formDef)) $app->error("Form definition not found."); $this->dataRecord = $record; -- GitLab