public static function setGroups(HTMLFactoryInterface $factory, HTMLElement $select, $groups = [], $checkedValue = null)
    {
        foreach ($groups as $data) {
            $label = $data['label'];
            $options = $data['options'];

            // Build group
            $group = $factory->buildHtmlElement('optgroup', '', '', '', [
                'label' => $label,
            ]);

            // Add options to group
            self::setOptions($factory, $group, $options, $checkedValue);

            // Append group to container
            $factory->getHTMLHandler()->append($select, $group);
        }
    }
public static function setGroups(HTMLFactoryInterface $factory, HTMLElement $select, $groups = [], $checkedValue = null)
    {
        foreach ($groups as $data) {
            $label = $data['label'];
            $options = $data['options'];

            // Build group
            $group = $factory->buildHtmlElement('optgroup', '', '', '', [
                'label' => $label,
            ]);

            // Add options to group
            self::setOptions($factory, $group, $options, $checkedValue);

            // Append group to container
            $factory->getHTMLHandler()->append($select, $group);
        }
    }
public static function setGroups ( HTMLFactoryInterface $ factory , HTMLElement $ select , $ groups = [ ] , $ checkedValue = null ) { foreach ( $ groups as $ data ) { $ label = $ data [ 'label' ] ; $ options = $ data [ 'options' ] ; // Build group $ group = $ factory -> buildHtmlElement ( 'optgroup' , '' , '' , '' , [ 'label' => $ label , ] ) ; // Add options to group self :: setOptions ( $ factory , $ group , $ options , $ checkedValue ) ; // Append group to container $ factory -> getHTMLHandler ( ) -> append ( $ select , $ group ) ; } }
Sets the given array as groups in select.

Get label and options from each group and apply accordingly.

@param HTMLFactoryInterface $factory
@param HTMLElement          $select
@param array                $groups
@param mixed|array          $checkedValue

@throws \InvalidArgumentException
@throws \Exception
Sets the given array as groups in select .