Example #1
0
 protected function preprocessForm(FOFForm $form, $data, $group = 'content')
 {
     $form_file = JPATH_COMPONENT_ADMINISTRATOR . "/models/forms/standard.xml";
     $form->loadFile($form_file, false, false);
     $app = JFactory::getApplication();
     $data_ = $app->getUserState('com_redslider.edit.slide.data');
     if ($data_) {
         if ($data_['type'] != 'standard') {
             $form_file_type = JPATH_COMPONENT_ADMINISTRATOR . "/models/forms/" . $data_['type'] . ".xml";
             $form->loadFile($form_file_type, false, false);
         }
     } else {
         if ($data['type'] != 'standard') {
             $form_file_type = JPATH_COMPONENT_ADMINISTRATOR . "/models/forms/" . $data['type'] . ".xml";
             $form->loadFile($form_file_type, false, false);
         }
     }
     // Trigger the default form events.
     parent::preprocessForm($form, $data, $group);
 }
Example #2
0
 /**
  * Method to allow derived classes to preprocess the form.
  *
  * @param   FOFForm  &$form  A FOFForm object.
  * @param   mixed    &$data  The data expected for the form.
  * @param   string   $group  The name of the plugin group to import (defaults to "content").
  *
  * @return  void
  *
  * @see     FOFFormField
  * @since   2.0
  * @throws  Exception if there is an error in the form event.
  */
 protected function preprocessForm(FOFForm &$form, &$data, $group = 'content')
 {
     // Do what have to be done
     parent::preprocessForm($form, $data, $group);
     $formName = $this->getState('form_name');
     if ($formName == 'form.form' || $formName == 'form.item') {
         $isAdmin = FOFPlatform::getInstance()->isBackend();
         $params = JComponentHelper::getParams('com_babioonevent');
         // Handele enabled field access
         if (!$isAdmin || $this->input->getCmd('task') == 'edit' && !$isAdmin) {
             $this->removeFields($form, 'enabled');
         }
         if ($isAdmin) {
             // Change the field type for the backend, use the "normal" datepicker
             $form->setFieldAttribute('sdate', 'type', 'calendar');
             $form->setFieldAttribute('sdate', 'format', '%d.%m.%Y');
             $form->setFieldAttribute('edate', 'type', 'calendar');
             $form->setFieldAttribute('edate', 'format', '%d.%m.%Y');
         }
         // Handle the date and time fields
         $showdates = $params->get('showdates', 4);
         $remove = array('stimehh', 'stimemm', 'edate', 'etimehh', 'etimemm');
         $required = array();
         if (!in_array($showdates, array(1, 3, 6, 9, 14))) {
             $offset = array_search('stimehh', $remove);
             array_splice($remove, array_search('stimehh', $remove), 1);
             array_splice($remove, array_search('stimemm', $remove), 1);
         }
         if ($showdates > 5) {
             array_splice($remove, array_search('edate', $remove), 1);
         }
         if (in_array($showdates, array(8, 12, 13, 17, 18, 19))) {
             array_splice($remove, array_search('etimehh', $remove), 1);
             array_splice($remove, array_search('etimemm', $remove), 1);
         }
         if (in_array($showdates, array(3, 4, 5)) || $showdates > 8) {
             $required[] = 'sdate';
         }
         if (in_array($showdates, array(5, 11, 13, 16, 18, 19))) {
             $required[] = 'stimehh';
             $required[] = 'stimemm';
         }
         if ($showdates > 13) {
             $required[] = 'edate';
         }
         if ($showdates == 19) {
             $required[] = 'etimehh';
             $required[] = 'etimemm';
         }
         $this->removeFields($form, $remove);
         $this->setFieldsRequired($form, $required);
         $fields = array('organiser' => 2, 'contact' => 1, 'phone' => 1, 'website' => 1, 'email' => 1, 'shortdesc' => 1, 'longdesc' => 1);
         foreach ($fields as $fieldname => $defaultvalue) {
             $this->manageField($form, $fieldname, $params->get('show' . $fieldname, $defaultvalue));
         }
         // Remove checkbox showemail when email is disabled
         if ($params->get('showemail', 1) == 0) {
             $this->removeFields($form, 'showemail');
         }
         // Change editor to textbox when frontend
         if (!$isAdmin) {
             $form->setFieldAttribute('teaser', 'type', 'textarea');
             $form->setFieldAttribute('text', 'type', 'textarea');
         }
         // Location fields
         $showlocation = $params->get('showlocation', 2);
         $locDetails = array('ainfo', 'street', 'pcode', 'city', 'state', 'country');
         if ($showlocation == 0) {
             $this->removeFields($form, 'address');
             foreach ($locDetails as $field) {
                 $this->removeFields($form, $locDetails);
             }
         } else {
             if ($showlocation > 2) {
                 $this->removeFields($form, 'address');
                 if ($showlocation > 3) {
                     $this->setFieldsRequired($form, array_slice($locDetails, 1));
                 }
             } else {
                 $this->removeFields($form, $locDetails);
                 if ($showlocation == 2) {
                     $this->setFieldsRequired($form, 'address');
                 }
             }
         }
         // Manage charge fields
         if ($params->get('showcharge', 2) == 0) {
             $this->removeFields($form, 'isfreeofcharge');
             $form->setFieldAttribute('charge', 'required', 'false');
             $this->removeFields($form, 'charge');
         }
         $defaultcategory = $params->get('defaultcategory', 0);
         // Remove category field when always standard category
         if ($params->get('showcategory', 1) == 0) {
             // We remove it only when we have a default category
             if ($defaultcategory != 0) {
                 $this->removeFields($form, 'catid');
             }
         } else {
             if ($defaultcategory != 0) {
                 $form->setFieldAttribute('catid', 'default', $defaultcategory);
             }
         }
     }
 }