user = Factory::getApplication()->getIdentity(); } public function getDispatcher() { if (!$this->dispatcher) { return Factory::getContainer()->get(DispatcherInterface::class); } return $this->dispatcher; } public function getForm($data = array(), $loadData = true) { } public function getItem($pk = null) { if (isset($this->item)) { // item already loaded and processed return $this->item; } if($this->item = parent::getItem($pk)) { // sub class: format the fields parameters $this->loadFormFieldsParameters(); } return $this->item; } // try to save data in database // return appropriate message /* supported post and get parameter $id = $input->get('id', 0, 'int'); // record ic $fieldName = $input->post->get('fieldName', '', 'string'); $tableName = $input->post->get('tableName', '', 'string'); $text = ComponentHelper::filterText($input->post->get('text', '', 'raw')); @throws \UnexpectedValueException (extends \RuntimeException) @throws \RuntimeException */ public function saveAjaxTextareaInDatabase() { $input = Factory::getApplication()->getInput(); // always the record id of the form $id = $input->get('id', 0, 'int'); if (empty($id)) { throw new \UnexpectedValueException(Text::_('COM_VISFORMS_AJAX_SUBMIT_FORM_NOT_YET_SAVE_MESSAGE')); } $fieldName = $input->post->get('fieldName', '', 'string'); $tableName = $input->post->get('tableName', '', 'string'); $viewTableName = $this->getTable()->getTableName(); $key = 'id'; $text = ComponentHelper::filterText($input->post->get('text', '', 'raw')); $tableName = '#__' .$tableName; // check submitted table name is in the list of allowed tables if (!in_array($tableName, $this->ajaxTables)) { throw new \RuntimeException(Text::sprintf('COM_VISFORMS_AJAX_SUBMIT_INVALID_DATA', Text::_('COM_VISFORMS_AJAX_SUBMIT_INVALID_TABLE_NAME'))); } if (!in_array($fieldName, $this->ajaxTableColumns)) { throw new \RuntimeException(Text::sprintf('COM_VISFORMS_AJAX_SUBMIT_INVALID_DATA', Text::_('COM_VISFORMS_AJAX_SUBMIT_INVALID_COLUMN_NAME'))); } if ($tableName !== $viewTableName) { // visforms plugin with own data table // store in plugin table // may be refined later using an event and using plugin code or store the data in the data base. // use field fid in plugin data tables $key = 'fid'; } $datas = new \StdClass(); $datas->$key = $id; $datas->$fieldName = $text; $db = $this->getDatabase(); try { $db->updateObject($tableName, $datas, $key, false); } catch (\RuntimeException $e) { // Just pass it through throw new \RuntimeException($e->getMessage()); } } protected function loadFormFieldsParameters() { } }