Example #1
0
 /**
  * Method to preprocess the form.
  *
  * @param   JForm   $form   A JForm object.
  * @param   mixed   $data   The data expected for the form.
  * @param   string  $group  The name of the plugin group to import.
  *
  * @return  void
  *
  * @see     JFormField
  * @since   1.6
  * @throws  Exception if there is an error in the form event.
  */
 protected function preprocessForm(JForm $form, $data, $group = 'content')
 {
     jimport('joomla.filesystem.path');
     $lang = JFactory::getLanguage();
     $component = $this->getState('category.component');
     $section = $this->getState('category.section');
     $extension = JFactory::getApplication()->input->get('extension', null);
     // Get the component form if it exists
     $name = 'category' . ($section ? '.' . $section : '');
     // Looking first in the component models/forms folder
     $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/{$component}/models/forms/{$name}.xml");
     // Old way: looking in the component folder
     if (!file_exists($path)) {
         $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/{$component}/{$name}.xml");
     }
     if (file_exists($path)) {
         $lang->load($component, JPATH_BASE, null, false, true);
         $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, true);
         if (!$form->loadFile($path, false)) {
             throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
         }
     }
     // Try to find the component helper.
     $eName = str_replace('com_', '', $component);
     $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/{$component}/helpers/category.php");
     if (file_exists($path)) {
         require_once $path;
         $cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory';
         if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm'))) {
             $lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false) || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false);
             call_user_func_array(array($cName, 'onPrepareForm'), array(&$form));
             // Check for an error.
             if ($form instanceof Exception) {
                 $this->setError($form->getMessage());
                 return false;
             }
         }
     }
     // Set the access control rules field component value.
     $form->setFieldAttribute('rules', 'component', $component);
     $form->setFieldAttribute('rules', 'section', $name);
     // Association category items
     $assoc = $this->getAssoc();
     if ($assoc) {
         $languages = JLanguageHelper::getLanguages('lang_code');
         $addform = new SimpleXMLElement('<form />');
         $fields = $addform->addChild('fields');
         $fields->addAttribute('name', 'associations');
         $fieldset = $fields->addChild('fieldset');
         $fieldset->addAttribute('name', 'item_associations');
         $fieldset->addAttribute('description', 'COM_CATEGORIES_ITEM_ASSOCIATIONS_FIELDSET_DESC');
         $add = false;
         foreach ($languages as $tag => $language) {
             if (empty($data->language) || $tag != $data->language) {
                 $add = true;
                 $field = $fieldset->addChild('field');
                 $field->addAttribute('name', $tag);
                 $field->addAttribute('type', 'modal_category');
                 $field->addAttribute('language', $tag);
                 $field->addAttribute('label', $language->title);
                 $field->addAttribute('translate_label', 'false');
                 $field->addAttribute('extension', $extension);
                 $field->addAttribute('edit', 'true');
                 $field->addAttribute('clear', 'true');
             }
         }
         if ($add) {
             $form->load($addform, false);
         }
     }
     // Trigger the default form events.
     parent::preprocessForm($form, $data, $group);
 }
Example #2
0
 /**
  * Method to preprocess the form.
  *
  * @param   JForm   $form    A JForm object.
  * @param   mixed   $data    The data expected for the form.
  * @param   string  $groups  The name of the plugin group to import.
  *
  * @return  void
  *
  * @see     JFormField
  * @since   1.6
  * @throws  Exception if there is an error in the form event.
  */
 protected function preprocessForm(JForm $form, $data, $group = 'content')
 {
     jimport('joomla.filesystem.path');
     // Initialise variables.
     $lang = JFactory::getLanguage();
     $extension = $this->getState('category.extension');
     $component = $this->getState('category.component');
     $section = $this->getState('category.section');
     // Get the component form if it exists
     jimport('joomla.filesystem.path');
     $name = 'category' . ($section ? '.' . $section : '');
     // Looking first in the component models/forms folder
     $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/{$component}/models/forms/{$name}.xml");
     // Old way: looking in the component folder
     if (!file_exists($path)) {
         $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/{$component}/{$name}.xml");
     }
     if (file_exists($path)) {
         $lang->load($component, JPATH_BASE, null, false, false);
         $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false);
         if (!$form->loadFile($path, false)) {
             throw new Exception(JText::_('JERROR_LOADFILE_FAILED'));
         }
     }
     // Try to find the component helper.
     $eName = str_replace('com_', '', $component);
     $path = JPath::clean(JPATH_ADMINISTRATOR . "/components/{$component}/helpers/category.php");
     if (file_exists($path)) {
         require_once $path;
         $cName = ucfirst($eName) . ucfirst($section) . 'HelperCategory';
         if (class_exists($cName) && is_callable(array($cName, 'onPrepareForm'))) {
             $lang->load($component, JPATH_BASE, null, false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, null, false, false) || $lang->load($component, JPATH_BASE, $lang->getDefault(), false, false) || $lang->load($component, JPATH_BASE . '/components/' . $component, $lang->getDefault(), false, false);
             call_user_func_array(array($cName, 'onPrepareForm'), array(&$form));
             // Check for an error.
             if ($form instanceof Exception) {
                 $this->setError($form->getMessage());
                 return false;
             }
         }
     }
     // Set the access control rules field component value.
     $form->setFieldAttribute('rules', 'component', $component);
     $form->setFieldAttribute('rules', 'section', $name);
     // Trigger the default form events.
     parent::preprocessForm($form, $data, $group);
 }