use SilverStripe\Forms\FieldList; use SilverStripe\Forms\TextField; // Define a form with a text field $form = FieldList::create( TextField::create('MyTextField', 'This is a text field') ); // Replace "MyTextField" with a new text field that has a different label $newField = TextField::create('MyTextField', 'This is a different label'); $form->replaceField('MyTextField', $newField);
use SilverStripe\Forms\CheckboxField; // Get the FieldList object for an existing form $form = $this->getCMSFields(); // Replace the "Publish" checkbox with a new checkbox that has a different label $newCheckbox = CheckboxField::create('Publish', 'This is a different label'); $form->replaceField('Publish', $newCheckbox);In both examples, we first create a FieldList object with a single field (a text field in Example 1 and a checkbox field in Example 2). Then, we use the replaceField method to replace that field with a different field object. Based on the use of the SilverStripe namespace and the FieldList class, it's safe to say that these examples are part of the SilverStripe framework. Specifically, the examples make use of the SilverStripe Forms module.