/**
  * Return a readonly version of this field. Keeps the composition but returns readonly
  * versions of all the child {@link FormField} objects.
  *
  * @return CompositeField
  */
 public function performReadonlyTransformation()
 {
     parent::performReadonlyTransformation();
     $newChildren = new FieldList();
     $clone = clone $this;
     if ($clone->getChildren()) {
         foreach ($clone->getChildren() as $idx => $child) {
             if (is_object($child)) {
                 $child = $child->transform(new ReadonlyTransformation());
             }
             $newChildren->push($child, $idx);
         }
     }
     $clone->children = $newChildren;
     $clone->readonly = true;
     $clone->addExtraClass($this->extraClass());
     $clone->setDescription($this->getDescription());
     return $clone;
 }
コード例 #2
0
 public function testReadonlyCheckboxField()
 {
     // Test 1: a checked checkbox goes to "Yes"
     $field1 = new CheckboxField('IsChecked', 'Checked');
     $field1->setValue('on');
     $copy = $field1->performReadonlyTransformation();
     $this->assertEquals(_t('CheckboxField.YESANSWER', 'Yes'), trim(strip_tags($field1->performReadonlyTransformation()->Field())));
     // Test 2: an checkbox with the value set to false to "No"
     $field2 = new CheckboxField('IsChecked', 'Checked');
     $field2->setValue(false);
     $this->assertEquals(_t('CheckboxField.NOANSWER', 'No'), trim(strip_tags($field2->performReadonlyTransformation()->Field())));
     // Test 3: an checkbox with no value ever set goes to "No"
     $field3 = new CheckboxField('IsChecked', 'Checked');
     $this->assertEquals(_t('CheckboxField.NOANSWER', 'No'), trim(strip_tags($field3->performReadonlyTransformation()->Field())));
 }