Ejemplo n.º 1
0
 /**
  * 
  * get some form field by looking it in all fieldsets
  */
 private static function getFormField(JForm $form, $fieldName)
 {
     $field = $form->getField($fieldName);
     if (!empty($field)) {
         return $field;
     }
     foreach (self::$arrGroupsAssoc as $group => $nothing) {
         $field = $form->getField($fieldName, $group);
         if (!empty($field)) {
             return $field;
         }
     }
     UniteFunctionsRev::throwError("Field not found: {$fieldName}");
 }
Ejemplo n.º 2
0
 /**
  * Default view function
  *
  * @return void
  */
 public function displayTask()
 {
     // Get scope
     $this->view->scope = Request::getWord('scope', 'Hub');
     $this->view->scope_id = Request::getInt('scope_id', 0);
     // Get permissions
     $access = new \JForm('permissions');
     $access->loadFile(dirname(dirname(__DIR__)) . DS . 'models' . DS . 'forms' . DS . 'permissions.xml');
     // Bind existing rules if applicable
     $asset = new \JTableAsset($this->database);
     $name = 'com_time.' . strtolower($this->view->scope) . '.' . $this->view->scope_id;
     $asset->loadByName($name);
     if ($asset->get('id')) {
         $access->setValue('asset_id', null, $asset->get('id'));
     }
     $this->view->permissions = $access->getField(strtolower($this->view->scope));
     // Display
     $this->view->display();
 }
Ejemplo n.º 3
0
    /**
     * Prepare form.
     *
     * @param   JForm  $form  The form to be altered.
     * @param   mixed  $data  The associated data for the form.
     *
     * @return  boolean
     *
     * @since	2.5
     */
    public function onContentPrepareForm($form, $data)
    {
        // Check we have a form.
        if (!$form instanceof JForm) {
            $this->_subject->setError('JERROR_NOT_A_FORM');
            return false;
        }
        // Check we are manipulating the languagecode plugin.
        if ($form->getName() != 'com_plugins.plugin' || !$form->getField('languagecodeplugin', 'params')) {
            return true;
        }
        // Get site languages.
        if ($languages = JLanguage::getKnownLanguages(JPATH_SITE)) {
            // Inject fields into the form.
            foreach ($languages as $tag => $language) {
                $form->load('
					<form>
						<fields name="params">
							<fieldset
								name="languagecode"
								label="PLG_SYSTEM_LANGUAGECODE_FIELDSET_LABEL"
								description="PLG_SYSTEM_LANGUAGECODE_FIELDSET_DESC"
							>
								<field
									name="' . strtolower($tag) . '"
									type="text"
									description="' . htmlspecialchars(JText::sprintf('PLG_SYSTEM_LANGUAGECODE_FIELD_DESC', $language['name']), ENT_COMPAT, 'UTF-8') . '"
									translate_description="false"
									label="' . $tag . '"
									translate_label="false"
									size="7"
									filter="cmd"
								/>
							</fieldset>
						</fields>
					</form>
				');
            }
        }
        return true;
    }
Ejemplo n.º 4
0
 public function onContentPrepareForm(JForm $form, $data)
 {
     $context = $form->getName();
     // Transform categories form name to a valid context
     if (strpos($context, 'com_categories.category') !== false) {
         $context = str_replace('com_categories.category', '', $context) . '.category';
     }
     // Extracting the component and section
     $parts = $this->getParts($context);
     if (!$parts) {
         return true;
     }
     // If we are on the save command we need the actual data
     $jformData = JFactory::getApplication()->input->get('jform', array(), 'array');
     if ($jformData && !$data) {
         $data = $jformData;
     }
     if (is_array($data)) {
         $data = (object) $data;
     }
     $component = $parts[0];
     $section = $parts[1];
     $catid = isset($data->catid) ? $data->catid : (isset($data->dpfieldscatid) ? $data->dpfieldscatid : null);
     if (!$catid && $form->getField('catid')) {
         // Choose the first category available
         $xml = new DOMDocument();
         $xml->loadHTML($form->getField('catid')->__get('input'));
         $options = $xml->getElementsByTagName('option');
         if ($firstChoice = $options->item(0)) {
             $catid = $firstChoice->getAttribute('value');
             $data->dpfieldscatid = $catid;
         }
     }
     // Getting the fields
     $fields = DPFieldsHelper::getFields($parts[0] . '.' . $parts[1], $data);
     // If there is a catid field we need to reload the page when the catid
     // is changed
     if ($form->getField('catid') && $parts[0] != 'com_dpfields') {
         // The uri to submit to
         $uri = clone JUri::getInstance('index.php');
         // Removing the catid parameter from the actual url and set it as
         // return
         $returnUri = clone JUri::getInstance();
         $returnUri->setVar('catid', null);
         $uri->setVar('return', base64_encode($returnUri->toString()));
         // Setting the options
         $uri->setVar('option', 'com_dpfields');
         $uri->setVar('task', 'field.catchange');
         $uri->setVar('context', $parts[0] . '.' . $parts[1]);
         $uri->setVar('formcontrol', $form->getFormControl());
         $uri->setVar('view', null);
         $uri->setVar('layout', null);
         // Setting the onchange event to reload the page when the category
         // has changed
         $form->setFieldAttribute('catid', 'onchange', "categoryHasChanged(this);");
         JFactory::getDocument()->addScriptDeclaration("function categoryHasChanged(element){\n\t\t\t\tvar cat = jQuery(element);\n\t\t\t\tif (cat.val() == '" . $catid . "')return;\n\t\t\t\tjQuery('input[name=task]').val('field.catchange');\n\t\t\t\telement.form.action='" . $uri . "';\n\t\t\t\telement.form.submit();\n\t\t\t}\n\t\t\tjQuery( document ).ready(function() {\n\t\t\t\tvar formControl = '#" . $form->getFormControl() . "_catid';\n\t\t\t\tif (!jQuery(formControl).val() != '" . $catid . "'){jQuery(formControl).val('" . $catid . "');}\n\t\t\t});");
     }
     if (!$fields) {
         return true;
     }
     // Creating the dom
     $xml = new DOMDocument('1.0', 'UTF-8');
     $fieldsNode = $xml->appendChild(new DOMElement('form'))->appendChild(new DOMElement('fields'));
     $fieldsNode->setAttribute('name', 'params');
     $fieldsNode->setAttribute('addfieldpath', '/administrator/components/com_dpfields/models/fields');
     $fieldsNode->setAttribute('addrulepath', '/administrator/components/com_dpfields/models/rules');
     // Defining the field set
     $fieldset = $fieldsNode->appendChild(new DOMElement('fieldset'));
     $fieldset->setAttribute('name', 'params');
     $fieldset->setAttribute('name', 'dpfields');
     $fieldset->setAttribute('addfieldpath', '/administrator/components/' . $component . '/models/fields');
     $fieldset->setAttribute('addrulepath', '/administrator/components/' . $component . '/models/rules');
     $lang = JFactory::getLanguage();
     $key = strtoupper($component . '_FIELDS_' . $section . '_LABEL');
     if (!$lang->hasKey($key)) {
         $key = 'PLG_SYSTEM_DPFIELDS_FIELDS';
     }
     $fieldset->setAttribute('label', JText::_($key));
     $key = strtoupper($component . '_FIELDS_' . $section . '_DESC');
     if ($lang->hasKey($key)) {
         $fieldset->setAttribute('description', JText::_($key));
     }
     // Looping trough the fields for that context
     foreach ($fields as $field) {
         // Creating the XML form data
         $type = DPFieldsHelper::loadTypeObject($field->type, $field->context);
         if ($type === false) {
             continue;
         }
         try {
             // Rendering the type
             $node = $type->appendXMLFieldTag($field, $fieldset, $form);
             // If the field belongs to a catid but the catid in the data is
             // not known, set the required flag to false on any circumstance
             if (!$catid && $field->catid) {
                 $node->setAttribute('required', 'false');
             }
         } catch (Exception $e) {
             JFactory::getApplication()->enqueueMessage($e->getMessage(), 'error');
         }
     }
     // Loading the XML fields string into the form
     $form->load($xml->saveXML());
     $model = JModelLegacy::getInstance('Field', 'DPFieldsModel', array('ignore_request' => true));
     // Looping trough the fields again to set the value
     if (isset($data->id) && $data->id) {
         foreach ($fields as $field) {
             $value = $model->getFieldValue($field->id, $field->context, $data->id);
             if (!$value) {
                 continue;
             }
             // Setting the value on the field
             $form->setValue($field->alias, 'params', $value);
         }
     }
     return true;
 }