/**
  * Return the form's fields - used by the templates
  *
  * @return FieldList The form fields
  */
 public function Fields()
 {
     foreach ($this->getExtraFields() as $field) {
         if (!$this->fields->fieldByName($field->getName())) {
             $this->fields->push($field);
         }
     }
     return $this->fields;
 }
 public function testAddingFieldToATabWithTheSameNameAsTheField()
 {
     $FieldList = new FieldList($root = new TabSet("Root", $main = new Tab("Main", $a = new TextField("A"))));
     /* If you have a tab with the same name as the field, then technically it's a duplicate. However, it's
      * allowed because tab isn't a data field.  Only duplicate data fields are problematic */
     $FieldList->addFieldToTab("Root.MyName", $myName = new TextField("MyName"));
     $this->assertNotNull($FieldList->fieldByName('Root')->fieldByName('MyName'));
     $this->assertSame($myName, $FieldList->fieldByName('Root')->fieldByName('MyName')->Fields()->First());
 }
 public function fieldByName($name)
 {
     return $this->children->fieldByName($name);
 }
 /**
  * Value is sometimes an array, and sometimes a single value, so we need
  * to handle both cases.
  *
  * @param mixed $value
  * @param mixed $data
  * @return $this
  */
 public function setValue($value, $data = null)
 {
     // If $data is a DataObject, don't use the value, since it's a hashed value
     if ($data && $data instanceof DataObject) {
         $value = '';
     }
     //store this for later
     $oldValue = $this->value;
     if (is_array($value)) {
         $this->value = $value['_Password'];
         $this->confirmValue = $value['_ConfirmPassword'];
         $this->currentPasswordValue = $this->getRequireExistingPassword() && isset($value['_CurrentPassword']) ? $value['_CurrentPassword'] : null;
         if ($this->showOnClick && isset($value['_PasswordFieldVisible'])) {
             $this->children->fieldByName($this->getName() . '[_PasswordFieldVisible]')->setValue($value['_PasswordFieldVisible']);
         }
     } else {
         if ($value || !$value && $this->canBeEmpty) {
             $this->value = $value;
             $this->confirmValue = $value;
         }
     }
     //looking up field by name is expensive, so lets check it needs to change
     if ($oldValue != $this->value) {
         $this->children->fieldByName($this->getName() . '[_Password]')->setValue($this->value);
         $this->children->fieldByName($this->getName() . '[_ConfirmPassword]')->setValue($this->confirmValue);
     }
     return $this;
 }
 /**
  * Note: Doesn't call {@link FormField->setForm()}
  * on the returned {@link HiddenField}, you'll need to take
  * care of this yourself.
  *
  * @param FieldList $fieldset
  * @return HiddenField|false
  */
 public function updateFieldSet(&$fieldset)
 {
     if (!$fieldset->fieldByName($this->getName())) {
         $field = new HiddenField($this->getName(), null, $this->getValue());
         $fieldset->push($field);
         return $field;
     } else {
         return false;
     }
 }