src/Forms/FormField.php
public function castedCopy($classOrCopy)
    {
        $field = $classOrCopy;

        if (!is_object($field)) {
            $field = $classOrCopy::create($this->name);
        }

        $field
            ->setValue($this->value)
            ->setForm($this->form)
            ->setTitle($this->Title())
            ->setLeftTitle($this->LeftTitle())
            ->setRightTitle($this->RightTitle())
            ->addExtraClass($this->extraClass) // Don't use extraClass(), since this merges calculated values
            ->setDescription($this->getDescription());

        // Only include built-in attributes, ignore anything set through getAttributes().
        // Those might change important characteristics of the field, e.g. its "type" attribute.
        foreach ($this->attributes as $attributeKey => $attributeValue) {
            $field->setAttribute($attributeKey, $attributeValue);
        }

        return $field;
    }
public function castedCopy($classOrCopy)
    {
        $field = $classOrCopy;

        if (!is_object($field)) {
            $field = $classOrCopy::create($this->name);
        }

        $field
            ->setValue($this->value)
            ->setForm($this->form)
            ->setTitle($this->Title())
            ->setLeftTitle($this->LeftTitle())
            ->setRightTitle($this->RightTitle())
            ->addExtraClass($this->extraClass) // Don't use extraClass(), since this merges calculated values
            ->setDescription($this->getDescription());

        // Only include built-in attributes, ignore anything set through getAttributes().
        // Those might change important characteristics of the field, e.g. its "type" attribute.
        foreach ($this->attributes as $attributeKey => $attributeValue) {
            $field->setAttribute($attributeKey, $attributeValue);
        }

        return $field;
    }
public function castedCopy ( $ classOrCopy ) { $ field = $ classOrCopy ; if ( ! is_object ( $ field ) ) { $ field = $ classOrCopy :: create ( $ this -> name ) ; } $ field -> setValue ( $ this -> value ) -> setForm ( $ this -> form ) -> setTitle ( $ this -> Title ( ) ) -> setLeftTitle ( $ this -> LeftTitle ( ) ) -> setRightTitle ( $ this -> RightTitle ( ) ) -> addExtraClass ( $ this -> extraClass ) // Don't use extraClass(), since this merges calculated values -> setDescription ( $ this -> getDescription ( ) ) ; // Only include built-in attributes, ignore anything set through getAttributes(). // Those might change important characteristics of the field, e.g. its "type" attribute. foreach ( $ this -> attributes as $ attributeKey => $ attributeValue ) { $ field -> setAttribute ( $ attributeKey , $ attributeValue ) ; } return $ field ; }
Returns another instance of this field, but "cast" to a different class. The logic tries to
retain all of the instance properties, and may be overloaded by subclasses to set additional
ones.

Assumes the standard FormField parameter signature with its name as the only mandatory
argument. Mainly geared towards creating *_Readonly or *_Disabled subclasses of the same
type, or casting to a {@link ReadonlyField}.

Does not copy custom field templates, since they probably won't apply to the new instance.

@param mixed $classOrCopy Class name for copy, or existing copy instance to update

@return FormField
Returns another instance of this field but cast to a different class . The logic tries to retain all of the instance properties and may be overloaded by subclasses to set additional ones .