/** * Method to attach a JForm object to the field. * * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * * @return boolean True on success. * * @see JFormField::setup() * @since 3.2 */ public function setup(SimpleXMLElement $element, $value, $group = null) { $return = parent::setup($element, $value, $group); if ($return) { $this->keyField = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value'; $this->valueField = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name']; $this->translate = $this->element['translate'] ? (string) $this->element['translate'] : false; $this->query = (string) $this->element['query']; } return $return; }
/** * Test forcemultiple property setup by JFormField::setup method * * @covers JFormField::setup * @covers JFormField::__get * * @return void */ public function testSetupForceMultiple() { $field = new JFormFieldCheckboxes(); $element = simplexml_load_string(' <field type="checkboxes" name="myName"> <option value="red">Red</option> <option value="blue">Blue</option> </field> '); $field->forceMultiple = true; $this->assertThat($field->setup($element, 'Comment'), $this->isTrue(), 'Line:' . __LINE__ . ' The setup method should return true if successful.'); $this->assertThat($field->multiple, $this->isTrue(), 'Line:' . __LINE__ . ' The property should be setted true forcefully.'); $this->assertThat($field->name, $this->equalTo('myName[]'), 'Line:' . __LINE__ . ' The property should be computed from the XML.'); }
/** * Method to attach a JForm object to the field. * * @param SimpleXMLElement $element The SimpleXMLElement object representing the <field /> tag for the form field object. * @param mixed $value The form field value to validate. * @param string $group The field name group control value. This acts as as an array container for the field. * For example if the field has name="foo" and the group value is set to "bar" then the * full field name would end up being "bar[foo]". * * @return boolean True on success. * * @see JFormField::setup() * @since 1.2.0 */ public function setup(SimpleXMLElement $element, $value, $group = null) { $return = parent::setup($element, $value, $group); if ($return) { $attributes = array('parentField', 'checked', 'states', 'class'); /* class is @deprecated >= J3.2 */ foreach ($attributes as $attributeName) { if (isset($element[$attributeName])) { $this->__set($attributeName, $element[$attributeName]); } } } return $return; }