/** * Test the getInput method. * * @return void * * @since 11.3 */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="databaseconnection" type="databaseconnection" supported="mysqli" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldDatabaseConnection($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error; in this case, a "Mysqli" option.'); $this->assertThat($form->load('<form><field name="databaseconnection" type="databaseconnection" supported="non-existing" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldDatabaseConnection($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error; in this case, a "None" option.'); // TODO: Should check all the attributes have come in properly. }
/** * Test the getInput method. * * @return void */ public function testGetInput() { $form = new JForm('form1'); // Test a traditional hidden field type. $this->assertThat($form->load('<form><field name="hidden" type="hidden" label="foo" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $this->assertEmpty($form->getLabel('hidden'), 'Line:' . __LINE__ . ' The label of a hidden element should be nothing.'); // Test a field with attribute hidden = true. $this->assertThat($form->load('<form><field name="hidden" type="text" label="foo" hidden="true" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $this->assertEmpty($form->getLabel('hidden'), 'Line:' . __LINE__ . ' The label of a hidden element should be nothing.'); // Test a field with attribute hidden = false. $this->assertThat($form->load('<form><field name="hidden" type="text" label="foo" hidden="false" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $matcher = array('id' => 'hidden-lbl', 'tag' => 'label', 'attributes' => array('for' => 'hidden', 'class' => ''), 'content' => 'regexp:/foo/'); $this->assertTag($matcher, $form->getLabel('hidden'), 'Line:' . __LINE__ . ' The label of a non-hidden element should be some HTML.'); }
/** * Auto-populate the model state. * * Note. Calling getState in this method will result in recursion. * * @return void * @since 3.0 */ protected function preprocessForm(JForm $form, $data, $group = 'jevents') { // Association content items $app = JFactory::getApplication(); $assoc = false && JLanguageAssociations::isEnabled() && JFactory::getApplication()->isAdmin(); 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_JEVENTS_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_article'); $field->addAttribute('language', $tag); $field->addAttribute('label', $language->title); $field->addAttribute('translate_label', 'false'); $field->addAttribute('edit', 'true'); $field->addAttribute('clear', 'true'); } } if ($add) { $form->load($addform, false); } } parent::preprocessForm($form, $data, $group); }
/** * Test the getInput method. * * @return void */ public function testGetInput() { $form = new JForm('form1'); // Test a traditional hidden field type. $this->assertThat($form->load('<form><field name="hidden" type="hidden" label="foo" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldHidden($form); $this->assertThat($form->getLabel('hidden'), $this->equalTo(''), 'Line:' . __LINE__ . ' The label of a hidden element should be nothing.'); // Test a field with attribute hidden = true. $this->assertThat($form->load('<form><field name="hidden" type="text" label="foo" hidden="true" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldHidden($form); $this->assertThat($form->getLabel('hidden'), $this->equalTo(''), 'Line:' . __LINE__ . ' The label of a hidden element should be nothing.'); // Test a field with attribute hidden = false. $this->assertThat($form->load('<form><field name="hidden" type="text" label="foo" hidden="false" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldHidden($form); $this->assertThat($form->getLabel('hidden'), $this->equalTo('<label id="hidden-lbl" for="hidden" class="">foo</label>'), 'Line:' . __LINE__ . ' The label of a non-hidden element should be some HTML.'); }
/** * Render HTML Markup for administrator UI * * @return string */ public function render() { $adminFormXml = $this->_generateFormXML(); // Create form instance $this->adminForm = new JForm('template-setting'); $this->adminForm->addFieldPath(JSN_PATH_TPLFRAMEWORK . '/libraries/joomlashine/form/fields'); $this->adminForm->load($adminFormXml->asXML()); $params = $this->helper->loadParams($this->data->params, $this->data->template); // Bind value of parameters to form foreach ($params as $key => $value) { $this->adminForm->setValue($key, 'jsn', $value); } // Get Joomla application object $app = JFactory::getApplication(); // Store current compression parameters $app->setUserState('jsn.template.maxCompressionSize', $params['maxCompressionSize']); $app->setUserState('jsn.template.cacheDirectory', $params['cacheDirectory']); // Start rendering ob_start(); include JSN_PATH_TPLFRAMEWORK_LIBRARIES . '/template/tmpl/default.php'; $body = ob_get_clean(); // Detect method to use for getting and setting response body if (version_compare(JVERSION, '3.2.0', 'ge')) { $get = array($app, 'getBody'); $set = array($app, 'setBody'); } else { $get = array('JResponse', 'getBody'); $set = array('JResponse', 'setBody'); } // Parse current response body list($head, $tmp) = preg_split('/<form[^>]+name="adminForm"[^>]*>/', call_user_func($get), 2); list($tmp, $foot) = explode('</form>', $tmp, 2); // Replace current response body call_user_func($set, $head . $body . $foot); }
/** * Test the getInput method. * * @return void */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="combo" type="combo" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldCombo($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); }
/** * Test the getInput method. * * @return void * * @since 11.1 */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="accesslevel" type="accesslevel" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldAccessLevel($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.'); }
/** * Test the getInput method. * * @return void * * @since 12.1 */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="color" type="color" disabled="true" onchange="window.reload()" class="inputbox" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldColor($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.'); }
/** * Test the getOptions method. * * @return void * * @since 11.3 */ public function testGetOptions() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="radio" type="radio"><option value="0">No</option><item value="1">Yes</item></field></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldRadio($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->logicalNot($this->StringContains('Yes')), 'Line:' . __LINE__ . ' The field should not contain a Yes option.'); }
/** * Tests the getInput method. * * @return void * * @since 3.1 */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="moduletag" type="moduletag" label="Module Tag" description="Module Tag listing" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldModuletag($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertContains('<option value="nav">nav</option>', $field->input, 'Line:' . __LINE__ . ' The getInput method should return an option with various opening tags, verify nav tag is in list.'); }
/** * Tests the getInput method. * * @return void * * @since 3.1 */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="helpsite" type="helpsite" label="Help Site" description="Help Site listing" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldHelpsite($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertContains('<option value="http://help.joomla.org/proxy/index.php?option=com_help&keyref=Help{major}{minor}:{keyref}">', $field->input, 'Line:' . __LINE__ . ' The getInput method should return an option with a link to the help site.'); }
/** * Tests the JForm::__construct method */ public function testConstruct() { $form = new JForm('form1'); $this->assertThat($form->load(JFormDataHelper::$loadFieldDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldInspector($form); $this->assertThat($field instanceof JFormField, $this->isTrue(), 'Line:' . __LINE__ . ' The JFormField constuctor should return a JFormField object.'); $this->assertThat($field->getForm(), $this->identicalTo($form), 'Line:' . __LINE__ . ' The internal form should be identical to the variable passed in the contructor.'); }
/** * Test the getInput method. * * @return void * * @since 11.1 * @todo Should check all the attributes have come in properly. */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="componentlayout" type="componentlayout" extension="com_content" client_id="0" view="blog" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldComponentlayout($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.'); }
/** * Test the getInput method. * * @return void * * @since 12.1 */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="filelist" type="filelist" directory="modules/mod_finder/tmpl" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldFileList($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.'); // TODO: Should check all the attributes have come in properly. }
/** * Test the getInput method. * * @return void */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="rules" type="rules" section="component" component="com_content" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldRules($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.'); // TODO: Should check all the attributes have come in properly. }
/** * Test the getInput method. * * @return void */ public function testGetInput() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="file" type="file" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldFile($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); // $this->markTestIncomplete('Problems encountered in next assertion'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.'); // TODO: Should check all the attributes have come in properly. }
/** * Test the getInput method. * * @return void * * @since 11.1 */ public function testGetInput() { $form = new JForm('form1'); $expected = '<form><field name="usergroup" type="usergroup" class="inputbox" disabled="true" onclick="window.reload()">' . '<option value="*">None</option><item value="fake">Fake</item></field></form>'; $this->assertThat($form->load($expected), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldUsergroup($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat(strlen($field->input), $this->greaterThan(0), 'Line:' . __LINE__ . ' The getInput method should return something without error.'); // TODO: Should check all the attributes have come in properly. }
/** * @param int $userId The user id * @param JForm $form * * @return boolean */ function onPrepareUserProfileForm($userId, &$form) { // Add the profile fields to the form. JForm::addFormPath(dirname(__FILE__) . DS . 'profiles'); $form->load('profile', true, false); // Toggle whether the address1 field is required. if ($this->params->get('profile-require_address1', 1) > 0) { $form->setFieldAttribute('address1', 'required', $this->params->get('profile-require_address1') == 2, 'profile'); } else { $form->removeField('address1', 'profile'); } // Toggle whether the address2 field is required. if ($this->params->get('profile-require_address2', 1) > 0) { $form->setFieldAttribute('address2', 'required', $this->params->get('profile-require_address2') == 2, 'profile'); } else { $form->removeField('address2', 'profile'); } // Toggle whether the city field is required. if ($this->params->get('profile-require_city', 1) > 0) { $form->setFieldAttribute('city', 'required', $this->params->get('profile-require_address1') == 2, 'profile'); } else { $form->removeField('city', 'profile'); } // Toggle whether the region field is required. if ($this->params->get('profile-require_region', 1) > 0) { $form->setFieldAttribute('region', 'required', $this->params->get('profile-require_address1') == 2, 'profile'); } else { $form->removeField('region', 'profile'); } // Toggle whether the country field is required. if ($this->params->get('profile-require_country', 1) > 0) { $form->setFieldAttribute('country', 'required', $this->params->get('profile-require_address1') == 2, 'profile'); } else { $form->removeField('country', 'profile'); } // Toggle whether the postal code field is required. if ($this->params->get('profile-require_postal_code', 1) > 0) { $form->setFieldAttribute('postal_code', 'required', $this->params->get('profile-require_address1') == 2, 'profile'); } else { $form->removeField('postal_code', 'profile'); } // Toggle whether the phone field is required. if ($this->params->get('profile-require_phone', 1) > 0) { $form->setFieldAttribute('phone', 'required', $this->params->get('profile-require_address1') == 2, 'profile'); } else { $form->removeField('phone', 'profile'); } // Toggle whether the website field is required. if ($this->params->get('profile-require_website', 1) > 0) { $form->setFieldAttribute('website', 'required', $this->params->get('profile-require_address1') == 2, 'profile'); } else { $form->removeField('website', 'profile'); } return true; }
/** * Method to get the field input markup. * * @return string The field input markup. * * @since 3.2 */ protected function getInput() { // Initialize variables. $subForm = new JForm($this->name, array('control' => 'jform')); $xml = $this->element->children()->asXML(); $subForm->load($xml); // Needed for repeating modals in gmaps $subForm->repeatCounter = (int) @$this->form->repeatCounter; $children = $this->element->children(); $subForm->setFields($children); $modalid = $this->id . '_modal'; $str = array(); $str[] = '<div id="' . $modalid . '" style="display:none">'; $str[] = '<table id="' . $modalid . '_table" class="adminlist ' . $this->element['class'] . ' table table-striped">'; $str[] = '<thead><tr>'; $names = array(); $attributes = $this->element->attributes(); foreach ($subForm->getFieldset($attributes->name . '_modal') as $field) { $names[] = (string) $field->element->attributes()->name; $str[] = '<th>' . strip_tags($field->getLabel($field->name)); $str[] = '<br /><small style="font-weight:normal">' . JText::_($field->description) . '</small>'; $str[] = '</th>'; } $str[] = '<th><a href="#" class="add btn button btn-success"><span class="fa fa-plus"></span> </a></th>'; $str[] = '</tr></thead>'; $str[] = '<tbody><tr>'; foreach ($subForm->getFieldset($attributes->name . '_modal') as $field) { $str[] = '<td>' . $field->getInput() . '</td>'; } $str[] = '<td>'; $str[] = '<div class="btn-group"><a class="add btn button btn-success"><span class="fa fa-plus"></span> </a>'; $str[] = '<a class="remove btn button btn-danger"><span class="fa fa-minus"></span> </a></div>'; $str[] = '</td>'; $str[] = '</tr></tbody>'; $str[] = '</table>'; $str[] = '</div>'; $names = json_encode($names); JHtml::_('script', 'system/repeatable.js', true, true); // If a maximum value isn't set then we'll make the maximum amount of cells a large number $maximum = $this->element['maximum'] ? (int) $this->element['maximum'] : '999'; $script = "(function (\$){\r\n\t\t\t\$(document).ready(function (){\r\n\t\t\t\tvar repeatable = new \$.JRepeatable('{$modalid}', {$names}, '{$this->id}', '{$maximum}');\r\n\t\t\t});\r\n\t\t})(jQuery);"; $document = JFactory::getDocument(); $document->addScriptDeclaration($script); $select = (string) $this->element['select'] ? JText::_((string) $this->element['select']) : JText::_('JLIB_FORM_BUTTON_SELECT'); $icon = $this->element['icon'] ? '<i class="icon-' . $this->element['icon'] . '"></i> ' : ''; $str[] = '<button class="btn" id="' . $modalid . '_button" data-modal="' . $modalid . '">' . $icon . $select . '</button>'; if (is_array($this->value)) { $this->value = array_shift($this->value); } $value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'); $str[] = '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="' . $value . '" />'; JText::script('JAPPLY'); JText::script('JCANCEL'); return implode("\n", $str); }
/** * Test the getOptions method. * * @return void * * @since 11.3 */ public function testGetOptions() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="integer" type="integer" first="1" last="-5" step="1"/></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldInteger($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat($field->input, $this->logicalNot($this->StringContains('<option')), 'Line:' . __LINE__ . ' The field should not contain any options.'); $this->assertThat($form->load('<form><field name="integer" type="integer" first="-7" last="-5" step="1"/></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldInteger($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat($field->input, $this->StringContains('<option value="-7">-7</option>'), 'Line:' . __LINE__ . ' The field should contain -7 through -5 as options.'); $this->assertThat($form->load('<form><field name="integer" type="integer" first="-7" last="-5" step="-1"/></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldInteger($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat($field->input, $this->logicalNot($this->StringContains('<option')), 'Line:' . __LINE__ . ' The field should not contain any options.'); $this->assertThat($form->load('<form><field name="integer" type="integer" first="-5" last="-7" step="-1"/></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldInteger($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $this->assertThat($field->input, $this->StringContains('<option value="-7">-7</option>'), 'Line:' . __LINE__ . ' The field should contain -5 through -7 as options.'); }
/** * Tests the JFormField::__construct method * * @covers JFormField::__construct * * @return void */ public function testConstruct() { $form = new JForm('form1'); $this->assertThat( $form->load(JFormDataHelper::$loadFieldDocument), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.' ); $field = new JFormFieldInspector($form); $this->assertThat( $field instanceof JFormField, $this->isTrue(), 'Line:' . __LINE__ . ' The JFormField constuctor should return a JFormField object.' ); $this->assertThat( $field->getForm(), $this->identicalTo($form), 'Line:' . __LINE__ . ' The internal form should be identical to the variable passed in the contructor.' ); // Add custom path. JForm::addFieldPath(__DIR__ . '/_testfields'); JFormHelper::loadFieldType('foo.bar'); $field = new FooFormFieldBar($form); $this->assertEquals( $field->type, 'FooBar', 'Line:' . __LINE__ . ' The field type should have been guessed by the constructor.' ); JFormHelper::loadFieldType('foo'); $field = new JFormFieldFoo($form); $this->assertEquals( $field->type, 'Foo', 'Line:' . __LINE__ . ' The field type should have been guessed by the constructor.' ); JFormHelper::loadFieldType('modal_foo'); $field = new JFormFieldModal_Foo($form); $this->assertEquals( $field->type, 'Modal_Foo', 'Line:' . __LINE__ . ' The field type should have been guessed by the constructor.' ); }
/** * Test the getLabel method. * * @return void */ public function testGetLabel() { $form = new JForm('form1'); $this->assertThat($form->load('<form><field name="spacer" type="spacer" description="spacer" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldSpacer($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $equals = '<span class="spacer"><span class="before"></span><span>' . '<label id="spacer-lbl" class="hasTooltip" title="<strong>spacer</strong>">spacer</label></span>' . '<span class="after"></span></span>'; $this->assertEquals($equals, $field->label, 'Line:' . __LINE__ . ' The getLabel method should return something without error.'); $this->assertThat($form->load('<form><field name="spacer" type="spacer" class="text" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldSpacer($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $equals = '<span class="spacer"><span class="before"></span><span class="text">' . '<label id="spacer-lbl" class="">spacer</label></span><span class="after"></span></span>'; $this->assertEquals($equals, $field->label, 'Line:' . __LINE__ . ' The getLabel method should return something without error.'); $this->assertThat($form->load('<form><field name="spacer" type="spacer" class="text" label="MyLabel" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldSpacer($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $equals = '<span class="spacer"><span class="before"></span><span class="text">' . '<label id="spacer-lbl" class="">MyLabel</label></span><span class="after"></span></span>'; $this->assertEquals($field->label, $equals, 'Line:' . __LINE__ . ' The getLabel method should return something without error.'); $this->assertThat($form->load('<form><field name="spacer" type="spacer" hr="true" /></form>'), $this->isTrue(), 'Line:' . __LINE__ . ' XML string should load successfully.'); $field = new JFormFieldSpacer($form); $this->assertThat($field->setup($form->getXml()->field, 'value'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true.'); $expected = '<span class="spacer"><span class="before"></span><span><hr /></span>' . '<span class="after"></span></span>'; $this->assertEquals($expected, $field->label, 'Line:' . __LINE__ . ' The getLabel method should return something without error.'); }
/** * @param JForm $form The form to be altered. * @param array $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 a valid form. $app = JFactory::getApplication(); if ($form->getName() != 'com_plugins.plugin' || isset($data->name) && $data->name != 'plg_system_languagecode' || empty($data) && !$app->getUserState('plg_system_language_code.edit')) { return true; } // Mark the plugin as being edited $app->setUserState('plg_system_language_code.edit', $data->name == 'plg_system_languagecode'); // Get site languages $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; }
/** * Adds additional fields to the user editing form * * @param JForm $form The form to be altered. * @param mixed $data The associated data for the form. * * @return boolean */ public function onContentPrepareForm($form, $data) { if (!$form instanceof JForm) { $this->_subject->setError('JERROR_NOT_A_FORM'); return false; } // We only work with com_users.* and com_admin.profile: $form_name = $form->getName(); if (!in_array($form_name, array('com_admin.profile', 'com_users.user', 'com_users.profile', 'com_users.registration'))) { return true; } //JLog::add("onContentPrepareForm ".htmlentities($form_name)); $app = JFactory::getApplication(); if ($app->isSite() && $form_name == 'com_users.registration') { $lang = JFactory::getLanguage()->getTag(); $form->removeField("email2"); $grpoptions = ""; foreach (explode(",", $this->params->get('altgroups')) as $grp) { $grp = htmlentities(trim($grp)); $grpoptions .= " <option value=\"{$grp}\">" . ($lang == "ru-RU" ? "Я -" : "I'm") . " {$grp}</option>\n"; } /* Append "altgroup.groupname" field to "default" fieldset * so that it would be rendered in the same "block" as * core user fields like "username/email/password": */ $form->load('<form>' . ' <fields name="altgroup">' . ' <fieldset name="default">' . ' <field name="groupname" type="radio"' . ' label=' . ($lang == "ru-RU" ? '"Кто вы?"' : '"Who are you?"') . ' required="true">' . $grpoptions . ' </field>' . ' </fieldset>' . ' </fields>' . '</form>'); /* JLog::add("input=".self::_str( $form->getInput("groupname", "altgroup"))); JLog::add("form=".self::_str($form));*/ } elseif ($form_name == 'com_users.profile') { $lang = JFactory::getLanguage()->getTag(); $form->removeField("email2"); $group_names = array(); if (isset($data->altgroup['groups'])) { foreach ($data->altgroup['groups'] as $g) { $group_names[] = $g[1]; } } /* Append "altgroup.groupnames" field to "core" * fieldset: */ $form->load('<form>' . ' <fields name="altgroup">' . ' <fieldset name="core">' . ' <field name="groupnames" type="text"' . ' disabled="true"' . ' label=' . ($lang == "ru-RU" ? '"Вы:"' : '"You are:"') . ' default="' . htmlentities(implode(", ", $group_names)) . '"' . ' />' . ' </fieldset>' . ' </fields>' . '</form>'); } return true; }
/** * Manupulates the registration form * * @param string &$data - registration form data * * @return mixed */ public function onUserRegisterFormDisplay(&$data) { // Load the funky stuff CompojoomHtmlBehavior::jquery(); JHtml::stylesheet('media/plg_community_cmc/css/style.css'); JHtml::script('media/plg_community_cmc/js/cmc.js'); // Create the xml for JForm $builder = CmcHelperXmlbuilder::getInstance($this->params); $xml = $builder->build(); $form = new JForm('myform'); $form->addFieldPath(JPATH_ADMINISTRATOR . '/components/com_cmc/models/fields'); $form->load($xml); $displayData = new stdClass(); $displayData->form = $form; $layout = new CompojoomLayoutFile('newsletter.form', JPATH_BASE . '/plugins/community/cmc/layouts'); $html = $layout->render($displayData); $pos = strrpos($data, '<div class="joms-form__group">'); $data = substr($data, 0, $pos) . $html . substr($data, $pos); }
/** * Method to allow derived classes 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 (defaults to "content"). * * @return void * * @see JFormField * @since 11.1 * @throws Exception if there is an error in the form event. */ protected function preprocessForm(JForm $form, $data, $group = 'content') { if (!$data) { parent::preprocessForm($form, $data, $group); return; } $blogXML = JPATH_ROOT . '/components/com_content/views/category/tmpl/blog.xml'; $listXML = JPATH_ROOT . '/components/com_content/views/category/tmpl/default.xml'; $articleXML = JPATH_ROOT . '/components/com_content/views/article/tmpl/default.xml'; $menuXML = JPATH_BASE . '/components/com_menus/models/forms/item_component.xml'; // set list params $listParams = simplexml_load_file($listXML); $listParams->fields[1]['name'] = 'list'; // set blog params $blogParams = simplexml_load_file($blogXML); $blogParams->fields[1]['name'] = 'blog'; // set article params $articleParams = simplexml_load_file($articleXML); $articleParams->fields[1]['name'] = 'article'; // create Form $this->listForm = JForm::getInstance('list', $listParams->asXML(), array('control' => 'jform'), true, '/metadata'); $this->blogForm = JForm::getInstance('blog', $blogParams->asXML(), array('control' => 'jform'), true, '/metadata'); $this->articleForm = JForm::getInstance('article', $articleParams->asXML(), array('control' => 'jform'), true, '/metadata'); // set menu xml $menuParams = simplexml_load_file($menuXML); $menuParams->fields[0]['name'] = 'list'; $this->listForm->load($menuParams->asXML(), true, '/form'); $menuParams->fields[0]['name'] = 'blog'; $this->blogForm->load($menuParams->asXML(), true, '/form'); $menuParams->fields[0]['name'] = 'article'; $this->articleForm->load($menuParams->asXML(), true, '/form'); // bind data $data->list = json_decode($data->list); $data->blog = json_decode($data->blog); $data->article = json_decode($data->article); $this->listForm->bind($data); $this->blogForm->bind($data); $this->articleForm->bind($data); parent::preprocessForm($form, $data, $group); }
/** * Method to get the field input markup. * * @return string The field input markup. * * @since 3.2 */ protected function getInput() { // Initialize variables. $subForm = new JForm($this->name, array('control' => 'jform')); $xml = $this->element->children()->asXML(); $subForm->load($xml); // Needed for repeating modals in gmaps // @TODO: what and where??? $subForm->repeatCounter = (int) @$this->form->repeatCounter; $children = $this->element->children(); $subForm->setFields($children); // If a maximum value isn't set then we'll make the maximum amount of cells a large number $maximum = $this->element['maximum'] ? (int) $this->element['maximum'] : '999'; // Build a Table $head_row_str = array(); $body_row_str = array(); foreach ($subForm->getFieldset() as $field) { // Reset name to simple $field->name = (string) $field->element['name']; // Build heading $head_row_str[] = '<th>' . strip_tags($field->getLabel($field->name)); $head_row_str[] = '<br /><small style="font-weight:normal">' . JText::_($field->description) . '</small>'; $head_row_str[] = '</th>'; // Build body $body_row_str[] = '<td>' . $field->getInput() . '</td>'; } // Append buttons $head_row_str[] = '<th><div class="btn-group"><a href="#" class="add btn button btn-success"><span class="icon-plus"></span> </a></div></th>'; $body_row_str[] = '<td><div class="btn-group">'; $body_row_str[] = '<a class="add btn button btn-success"><span class="icon-plus"></span> </a>'; $body_row_str[] = '<a class="remove btn button btn-danger"><span class="icon-minus"></span> </a>'; $body_row_str[] = '</div></td>'; // Put all table parts together $table = '<table id="' . $this->id . '_table" class="adminlist ' . $this->element['class'] . ' table table-striped">' . '<thead><tr>' . implode("\n", $head_row_str) . '</tr></thead>' . '<tbody><tr>' . implode("\n", $body_row_str) . '</tr></tbody>' . '</table>'; // And finaly build a main container $str = array(); $str[] = '<div id="' . $this->id . '_container">'; // Add the table to modal $str[] = '<div id="' . $this->id . '_modal" class="modal hide">'; $str[] = $table; $str[] = '<div class="modal-footer">'; $str[] = '<button class="close-modal btn button btn-link">' . JText::_('JCANCEL') . '</button>'; $str[] = '<button class="save-modal-data btn button btn-primary">' . JText::_('JAPPLY') . '</button>'; $str[] = '</div>'; // Close modal container $str[] = '</div>'; // Close main container $str[] = '</div>'; // Button for display the modal window $select = (string) $this->element['select'] ? JText::_((string) $this->element['select']) : JText::_('JLIB_FORM_BUTTON_SELECT'); $icon = $this->element['icon'] ? '<span class="icon-' . $this->element['icon'] . '"></span> ' : ''; $str[] = '<button class="open-modal btn" id="' . $this->id . '_button" >' . $icon . $select . '</button>'; if (is_array($this->value)) { $this->value = array_shift($this->value); } // Script params $data = array(); $data[] = 'data-container="#' . $this->id . '_container"'; $data[] = 'data-modal-element="#' . $this->id . '_modal"'; $data[] = 'data-repeatable-element="table tbody tr"'; $data[] = 'data-bt-add="a.add"'; $data[] = 'data-bt-remove="a.remove"'; $data[] = 'data-bt-modal-open="#' . $this->id . '_button"'; $data[] = 'data-bt-modal-close="button.close-modal"'; $data[] = 'data-bt-modal-save-data="button.save-modal-data"'; $data[] = 'data-maximum="' . $maximum . '"'; $data[] = 'data-input="#' . $this->id . '"'; // Hidden input, where the main value is $value = htmlspecialchars($this->value, ENT_COMPAT, 'UTF-8'); $str[] = '<input type="hidden" name="' . $this->name . '" id="' . $this->id . '" value="' . $value . '" class="form-field-repeatable" ' . implode(' ', $data) . ' />'; // Add scripts JHtml::_('bootstrap.framework'); JHtml::_('script', 'system/repeatable.js', true, true); return implode("\n", $str); }
protected function preprocessForm(JForm $form, $data, $group = 'content') { // Association content items $app = JFactory::getApplication(); $assoc = JLanguageAssociations::isEnabled(); if ($assoc) { $languages = JLanguageHelper::getLanguages('lang_code'); // force to array (perhaps move to $this->loadFormData()) $data = (array) $data; $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_CONTACT_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_contact'); $field->addAttribute('language', $tag); $field->addAttribute('label', $language->title); $field->addAttribute('translate_label', 'false'); $field->addAttribute('edit', 'true'); $field->addAttribute('clear', 'true'); } } if ($add) { $form->load($addform, false); } } parent::preprocessForm($form, $data, $group); }
/** * @param object $form A form object. * @param mixed $data The data expected for the form. * * @return void * @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.file'); jimport('joomla.filesystem.folder'); // Initialise variables. $link = $this->getState('item.link'); $type = $this->getState('item.type'); $formFile = false; // Initialise form with component view params if available. if ($type == 'component') { $link = htmlspecialchars_decode($link); // Parse the link arguments. $args = array(); parse_str(parse_url(htmlspecialchars_decode($link), PHP_URL_QUERY), $args); // Confirm that the option is defined. $option = ''; $base = ''; if (isset($args['option'])) { // The option determines the base path to work with. $option = $args['option']; $base = JPATH_SITE . '/components/' . $option; } // Confirm a view is defined. $formFile = false; if (isset($args['view'])) { $view = $args['view']; // Determine the layout to search for. if (isset($args['layout'])) { $layout = $args['layout']; } else { $layout = 'default'; } $formFile = false; // Check for the layout XML file. Use standard xml file if it exists. $path = JPath::clean($base . '/views/' . $view . '/tmpl/' . $layout . '.xml'); if (JFile::exists($path)) { $formFile = $path; } // if custom layout, get the xml file from the template folder // template folder is first part of file name -- template:folder if (!$formFile && strpos($layout, ':') > 0) { $temp = explode(':', $layout); $templatePath = JPATH::clean(JPATH_SITE . '/templates/' . $temp[0] . '/html/' . $option . '/' . $view . '/' . $temp[1] . '.xml'); if (JFile::exists($templatePath)) { $formFile = $templatePath; } } } //Now check for a view manifest file if (!$formFile) { $path = JPath::clean($base . '/views/metadata.xml'); if (JFile::exists($path)) { $formFile = $path; } else { //Now check for a component manifest file $path = JPath::clean($base . '/metadata.xml'); if (JFile::exists($path)) { $formFile = $path; } } } } if ($formFile) { // If an XML file was found in the component, load it first. // We need to qualify the full path to avoid collisions with component file names. if ($form->loadFile($formFile, true, '/metadata') == false) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } // Attempt to load the xml file. if (!($xml = simplexml_load_file($formFile))) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } // Get the help data from the XML file if present. $help = $xml->xpath('/metadata/layout/help'); if (!empty($help)) { $helpKey = trim((string) $help[0]['key']); $helpURL = trim((string) $help[0]['url']); $helpLoc = trim((string) $help[0]['local']); $this->helpKey = $helpKey ? $helpKey : $this->helpKey; $this->helpURL = $helpURL ? $helpURL : $this->helpURL; $this->helpLocal = $helpLoc == 'true' || $helpLoc == '1' || $helpLoc == 'local' ? true : false; } } // Now load the component params. // TODO: Work out why 'fixing' this breaks JForm if ($isNew = false) { $path = JPath::clean(JPATH_ADMINISTRATOR . '/components/' . $option . '/config.xml'); } else { $path = 'null'; } if (JFile::exists($path)) { // Add the component params last of all to the existing form. if (!$form->load($path, true, '/config')) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } } // Load the specific type file if (!$form->loadFile('item_' . $type, false, false)) { throw new Exception(JText::_('JERROR_LOADFILE_FAILED')); } // Trigger the default form events. parent::preprocessForm($form, $data); }
/** * 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); }