/** * Test pushing a field to the beginning of a set. * * This tests {@link FieldList->unshift()}. */ public function testPushFieldToBeginningOfSet() { $fields = new FieldList(); /* A field named Country is added to the set */ $fields->unshift(new TextField('Country')); /* We only have 1 field in the set */ $this->assertEquals(1, $fields->Count()); /* Another field called Email is added to the set */ $fields->unshift(new EmailField('Email')); /* There are now 2 fields in the set */ $this->assertEquals(2, $fields->Count()); /* The most recently added field is at the beginning of the set */ $this->assertEquals('Email', $fields->First()->getName()); // Test that pushing a composite field without a name onto the set works $fields->unshift(new CompositeField(new TextField('Test1'), new TextField('Test2'))); $this->assertEquals(3, $fields->Count()); }
/** * Add a new child field to the beginning of the set. * * @param FormField */ public function unshift(FormField $field) { $this->children->unshift($field); }
/** * 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; }
/** * Adds extra fields to this form * * @param FieldList $fields * @param Controller $controller * @param string $name * @param array $context */ public function updateFormFields(FieldList &$fields, Controller $controller, $name, $context = []) { // Add preview link if (empty($context['Record'])) { return; } $record = $context['Record']; if ($record->hasExtension(Versioned::class)) { $link = $controller->Link('preview'); $fields->unshift(new LiteralField("PreviewLink", sprintf('<a href="%s" rel="external" target="_blank">Preview</a>', Convert::raw2att($link)))); } }