src/Forms/TreeMultiselectField.php
public function Field($properties = array())
    {
        $value = '';
        $titleArray = array();
        $idArray = array();
        $items = $this->getItems();
        $emptyTitle = _t('SilverStripe\\Forms\\DropdownField.CHOOSE', '(Choose)', 'start value of a dropdown');

        if ($items && count($items)) {
            foreach ($items as $item) {
                $idArray[] = $item->ID;
                $titleArray[] = ($item instanceof ViewableData)
                    ? $item->obj($this->getLabelField())->forTemplate()
                    : Convert::raw2xml($item->{$this->getLabelField()});
            }

            $title = implode(", ", $titleArray);
            sort($idArray);
            $value = implode(",", $idArray);
        } else {
            $title = $emptyTitle;
        }

        $dataUrlTree = '';
        if ($this->form) {
            $dataUrlTree = $this->Link('tree');
            if (!empty($idArray)) {
                $dataUrlTree = Controller::join_links($dataUrlTree, '?forceValue=' . implode(',', $idArray));
            }
        }
        $properties = array_merge(
            $properties,
            array(
                'Title' => $title,
                'EmptyTitle' => $emptyTitle,
                'Link' => $dataUrlTree,
                'Value' => $value
            )
        );
        return FormField::Field($properties);
    }
public function Field($properties = array())
    {
        $value = '';
        $titleArray = array();
        $idArray = array();
        $items = $this->getItems();
        $emptyTitle = _t('SilverStripe\\Forms\\DropdownField.CHOOSE', '(Choose)', 'start value of a dropdown');

        if ($items && count($items)) {
            foreach ($items as $item) {
                $idArray[] = $item->ID;
                $titleArray[] = ($item instanceof ViewableData)
                    ? $item->obj($this->getLabelField())->forTemplate()
                    : Convert::raw2xml($item->{$this->getLabelField()});
            }

            $title = implode(", ", $titleArray);
            sort($idArray);
            $value = implode(",", $idArray);
        } else {
            $title = $emptyTitle;
        }

        $dataUrlTree = '';
        if ($this->form) {
            $dataUrlTree = $this->Link('tree');
            if (!empty($idArray)) {
                $dataUrlTree = Controller::join_links($dataUrlTree, '?forceValue=' . implode(',', $idArray));
            }
        }
        $properties = array_merge(
            $properties,
            array(
                'Title' => $title,
                'EmptyTitle' => $emptyTitle,
                'Link' => $dataUrlTree,
                'Value' => $value
            )
        );
        return FormField::Field($properties);
    }
public function Field ( $ properties = array ( ) ) { $ value = '' ; $ titleArray = array ( ) ; $ idArray = array ( ) ; $ items = $ this -> getItems ( ) ; $ emptyTitle = _t ( 'SilverStripe\\Forms\\DropdownField.CHOOSE' , '(Choose)' , 'start value of a dropdown' ) ; if ( $ items && count ( $ items ) ) { foreach ( $ items as $ item ) { $ idArray [ ] = $ item -> ID ; $ titleArray [ ] = ( $ item instanceof ViewableData ) ? $ item -> obj ( $ this -> getLabelField ( ) ) -> forTemplate ( ) : Convert :: raw2xml ( $ item -> { $ this -> getLabelField ( ) } ) ; } $ title = implode ( ", " , $ titleArray ) ; sort ( $ idArray ) ; $ value = implode ( "," , $ idArray ) ; } else { $ title = $ emptyTitle ; } $ dataUrlTree = '' ; if ( $ this -> form ) { $ dataUrlTree = $ this -> Link ( 'tree' ) ; if ( ! empty ( $ idArray ) ) { $ dataUrlTree = Controller :: join_links ( $ dataUrlTree , '?forceValue=' . implode ( ',' , $ idArray ) ) ; } } $ properties = array_merge ( $ properties , array ( 'Title' => $ title , 'EmptyTitle' => $ emptyTitle , 'Link' => $ dataUrlTree , 'Value' => $ value ) ) ; return FormField :: Field ( $ properties ) ; }
We overwrite the field attribute to add our hidden fields, as this
formfield can contain multiple values.

@param array $properties
@return DBHTMLText
We overwrite the field attribute to add our hidden fields as this formfield can contain multiple values .