/** * Removes an existing formfield instance by its name. * * @param string $fieldName */ public function removeFieldByName($fieldName) { $this->fields->removeByName($fieldName); }
/** * Test removing multiple fields from a set by their names in an array. */ public function testRemoveFieldsByName() { $fields = new FieldList(); /* First of all, we add some fields into our FieldList object */ $fields->push(new TextField('Name', 'Your name')); $fields->push(new TextField('Email', 'Your email')); /* We have 2 fields in our set now */ $this->assertEquals(2, $fields->Count()); /* Then, we call up removeByName() to take it out again */ $fields->removeByName(array('Name', 'Email')); /* We have 0 fields in our set now, as we've just removed the one we added */ $this->assertEquals(0, $fields->Count()); }
/** * Set if the existing password should be required * * @param bool $show Flag to show or hide this field * @return $this */ public function setRequireExistingPassword($show) { // Don't modify if already added / removed if ((bool) $show === $this->requireExistingPassword) { return $this; } $this->requireExistingPassword = $show; $name = $this->getName(); $currentName = "{$name}[_CurrentPassword]"; if ($show) { $confirmField = PasswordField::create($currentName, _t('Member.CURRENT_PASSWORD', 'Current Password')); $this->children->unshift($confirmField); } else { $this->children->removeByName($currentName, true); } return $this; }
/** * @param FieldList $fieldset * @return false */ public function updateFieldSet(&$fieldset) { // Remove, in case it was added beforehand $fieldset->removeByName($this->getName()); return false; }
/** * Remove a field from this CompositeField by Name. * The field could also be inside a CompositeField. * * @param string $fieldName The name of the field * @param boolean $dataFieldOnly If this is true, then a field will only * be removed if it's a data field. Dataless fields, such as tabs, will * be left as-is. */ public function removeByName($fieldName, $dataFieldOnly = false) { $this->children->removeByName($fieldName, $dataFieldOnly); }
/** * @param FieldList $fields */ public function updateCMSFields(FieldList $fields) { // remove the version field from the CMS as this should be left // entirely up to the extension (not the cms user). $fields->removeByName('Version'); }