src/Yggdrasil/Utils/Templating/FormExtension.php
public function addSelectList(string $name, array $items = []): void
    {
        $options = $this->formOptions['fields'][$name];
        $wrapper = $this->createWrapper();
        $label = '';

        if (isset($options['label']['text'])) {
            $label = $this->createLabel($options['label']['text'], $name);

            unset($options['label']['text']);
        }

        $list = HtmlTag::createElement('select')
            ->set('id', $name)
            ->set('name', $name);

        $caption = '';

        if (isset($options['caption']['text'])) {
            $list->set('aria-describedby', $name . '_caption');
            $caption = $this->createCaption($options['caption']['text'], $name);

            unset($options['caption']['text']);
        }

        foreach ($items as $value => $text) {
            $item[] = $list->addElement('option')
                ->set('value', $value)
                ->text($text);
        }

        $elements = [
            'wrapper' => $wrapper,
            'label'   => $label,
            'list'    => $list,
            'item'    => $item ?? [],
            'caption' => $caption
        ];

        foreach ($elements as $name => $element) {
            $$name = $this->assignOptionsToElement($options, $name, $element);
        }

        $wrapper->addElement($label);
        $wrapper->addElement($list);
        $wrapper->addElement($caption);

        echo $wrapper;
    }
public function addSelectList(string $name, array $items = []): void
    {
        $options = $this->formOptions['fields'][$name];
        $wrapper = $this->createWrapper();
        $label = '';

        if (isset($options['label']['text'])) {
            $label = $this->createLabel($options['label']['text'], $name);

            unset($options['label']['text']);
        }

        $list = HtmlTag::createElement('select')
            ->set('id', $name)
            ->set('name', $name);

        $caption = '';

        if (isset($options['caption']['text'])) {
            $list->set('aria-describedby', $name . '_caption');
            $caption = $this->createCaption($options['caption']['text'], $name);

            unset($options['caption']['text']);
        }

        foreach ($items as $value => $text) {
            $item[] = $list->addElement('option')
                ->set('value', $value)
                ->text($text);
        }

        $elements = [
            'wrapper' => $wrapper,
            'label'   => $label,
            'list'    => $list,
            'item'    => $item ?? [],
            'caption' => $caption
        ];

        foreach ($elements as $name => $element) {
            $$name = $this->assignOptionsToElement($options, $name, $element);
        }

        $wrapper->addElement($label);
        $wrapper->addElement($list);
        $wrapper->addElement($caption);

        echo $wrapper;
    }
public function addSelectList ( string $ name , array $ items = [ ] ) : void { $ options = $ this -> formOptions [ 'fields' ] [ $ name ] ; $ wrapper = $ this -> createWrapper ( ) ; $ label = '' ; if ( isset ( $ options [ 'label' ] [ 'text' ] ) ) { $ label = $ this -> createLabel ( $ options [ 'label' ] [ 'text' ] , $ name ) ; unset ( $ options [ 'label' ] [ 'text' ] ) ; } $ list = HtmlTag :: createElement ( 'select' ) -> set ( 'id' , $ name ) -> set ( 'name' , $ name ) ; $ caption = '' ; if ( isset ( $ options [ 'caption' ] [ 'text' ] ) ) { $ list -> set ( 'aria-describedby' , $ name . '_caption' ) ; $ caption = $ this -> createCaption ( $ options [ 'caption' ] [ 'text' ] , $ name ) ; unset ( $ options [ 'caption' ] [ 'text' ] ) ; } foreach ( $ items as $ value => $ text ) { $ item [ ] = $ list -> addElement ( 'option' ) -> set ( 'value' , $ value ) -> text ( $ text ) ; } $ elements = [ 'wrapper' => $ wrapper , 'label' => $ label , 'list' => $ list , 'item' => $ item ?? [ ] , 'caption' => $ caption ] ; foreach ( $ elements as $ name => $ element ) { $ $ name = $ this -> assignOptionsToElement ( $ options , $ name , $ element ) ; } $ wrapper -> addElement ( $ label ) ; $ wrapper -> addElement ( $ list ) ; $ wrapper -> addElement ( $ caption ) ; echo $ wrapper ; }
Adds select list to HTML form

@param string $name  Select list name, equivalent to ID attribute
@param array  $items Select list items [value => text]
Adds select list to HTML form