[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Site 5 * @subpackage com_config 6 * 7 * @copyright (C) 2013 Open Source Matters, Inc. <https://www.joomla.org> 8 * @license GNU General Public License version 2 or later; see LICENSE.txt 9 */ 10 11 namespace Joomla\Component\Config\Site\Model; 12 13 use Joomla\CMS\Component\ComponentHelper; 14 use Joomla\CMS\Factory; 15 use Joomla\CMS\Filesystem\Path; 16 use Joomla\CMS\Form\Form; 17 use Joomla\CMS\Language\Text; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('_JEXEC') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Template style model. 25 * 26 * @since 3.2 27 */ 28 class TemplatesModel extends FormModel 29 { 30 /** 31 * Method to auto-populate the model state. 32 * 33 * Note. Calling getState in this method will result in recursion. 34 * 35 * @return null 36 * 37 * @since 3.2 38 */ 39 protected function populateState() 40 { 41 parent::populateState(); 42 43 $this->setState('params', ComponentHelper::getParams('com_templates')); 44 } 45 46 /** 47 * Method to get the record form. 48 * 49 * @param array $data An optional array of data for the form to interrogate. 50 * @param boolean $loadData True if the form is to load its own data (default case), false if not. 51 * 52 * @return Form|bool A JForm object on success, false on failure 53 * 54 * @since 3.2 55 */ 56 public function getForm($data = array(), $loadData = true) 57 { 58 try { 59 // Get the form. 60 $form = $this->loadForm('com_config.templates', 'templates', array('load_data' => $loadData)); 61 62 $data = array(); 63 $this->preprocessForm($form, $data); 64 65 // Load the data into the form 66 $form->bind($data); 67 } catch (\Exception $e) { 68 Factory::getApplication()->enqueueMessage($e->getMessage()); 69 70 return false; 71 } 72 73 if (empty($form)) { 74 return false; 75 } 76 77 return $form; 78 } 79 80 /** 81 * Method to preprocess the form 82 * 83 * @param Form $form A form object. 84 * @param mixed $data The data expected for the form. 85 * @param string $group Plugin group to load 86 * 87 * @return void 88 * 89 * @since 3.2 90 * @throws \Exception if there is an error in the form event. 91 */ 92 protected function preprocessForm(Form $form, $data, $group = 'content') 93 { 94 $lang = Factory::getLanguage(); 95 96 $template = Factory::getApplication()->getTemplate(); 97 98 // Load the core and/or local language file(s). 99 $lang->load('tpl_' . $template, JPATH_BASE) 100 || $lang->load('tpl_' . $template, JPATH_BASE . '/templates/' . $template); 101 102 // Look for com_config.xml, which contains fields to display 103 $formFile = Path::clean(JPATH_BASE . '/templates/' . $template . '/com_config.xml'); 104 105 if (!file_exists($formFile)) { 106 // If com_config.xml not found, fall back to templateDetails.xml 107 $formFile = Path::clean(JPATH_BASE . '/templates/' . $template . '/templateDetails.xml'); 108 } 109 110 // Get the template form. 111 if (file_exists($formFile) && !$form->loadFile($formFile, false, '//config')) { 112 throw new \Exception(Text::_('JERROR_LOADFILE_FAILED')); 113 } 114 115 // Attempt to load the xml file. 116 if (!$xml = simplexml_load_file($formFile)) { 117 throw new \Exception(Text::_('JERROR_LOADFILE_FAILED')); 118 } 119 120 // Trigger the default form events. 121 parent::preprocessForm($form, $data, $group); 122 } 123 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |