generate the options for a select box

@param   array   array of options
@param   array   array of attributes
@return  string
499022
public function generateSelectOptions($options, $attr)
    {
        $return = '';

        foreach ($options as $key => $value) {
            if (is_array($value)) {
                $subArray = $this->generateSelectOptions($value, $attr);

                $return .= $this->Html->tag(
                    'optgroup',
                    array(
                        'label' => $key
                    ),
                    $subArray,
                    true
                );
            } else {
                $optionsAttr = array('value' => $key);

                if (isset($attr['selected']) && $attr['selected'] == $key) {
                    $optionsAttr[] = 'selected';
                }

                $return .= $this->Html->tag(
                    'option',
                    $optionsAttr,
                    $value,
                    true
                );
            }
        }

        return $return;
    }
1096182
public function toOptionArray()
    {
        $options = [];
        //exclude attributes from mapping
        $excluded = [
            'created_at',
            'created_in',
            'dob',
            'dotmailer_contact_id',
            'email',
            'firstname',
            'lastname',
            'gender',
            'group_id',
            'password_hash',
            'prefix',
            'rp_token',
            'rp_token_create_at',
            'website_id',
        ];
        $attributes = $this->customerFactory->create()
            ->getAttributes();

        foreach ($attributes as $attribute) {
            if ($attribute->getFrontendLabel()) {
                $code = $attribute->getAttributeCode();
                //escape the label in case of quotes
                $label = $this->escaper->escapeQuote($attribute->getFrontendLabel());
                if (!in_array($code, $excluded)) {
                    $options[] = [
                        'value' => $attribute->getAttributeCode(),
                        'label' => $label,
                    ];
                }
            }
        }

        return $options;
    }
653397
public function getOptions()
    {
        $selectedValues = $this->getValueArray();
        $defaultItems = $this->getDefaultItems();
        $disabledItems = $this->getDisabledItems();

        // Generate list of options to display
        $odd = false;
        $formID = $this->ID();
        $options = new ArrayList();
        foreach ($this->getSource() as $itemValue => $title) {
            $itemID = Convert::raw2htmlid("{$formID}_{$itemValue}");
            $odd = !$odd;
            $extraClass = $odd ? 'odd' : 'even';
            $extraClass .= ' val' . preg_replace('/[^a-zA-Z0-9\-\_]/', '_', $itemValue);

            $itemChecked = in_array($itemValue, $selectedValues) || in_array($itemValue, $defaultItems);
            $itemDisabled = $this->isDisabled() || in_array($itemValue, $disabledItems);

            $options->push(new ArrayData(array(
                'ID' => $itemID,
                'Class' => $extraClass,
                'Name' => "{$this->name}[{$itemValue}]",
                'Value' => $itemValue,
                'Title' => $title,
                'isChecked' => $itemChecked,
                'isDisabled' => $itemDisabled,
            )));
        }
        $this->extend('updateGetOptions', $options);
        return $options;
    }
286704
public static function selectOption($option, $value)
    {
        $attributes = [''];

        $attributes[] = "value=\"{$option['value']}\"";

        if (
            (is_array($value) && in_array($option['value'], $value))
            || ($option['value'] == $value)
        ) {
            $attributes[] = 'selected="selected"';
        }

        $attributes = implode(' ', $attributes);
        return "<option {$attributes}>{$option['label']}</option>";
    }
713851
public function makeAttributesForOption ($attributes)
    {
        $attrs = '';
        if ($attributes) {
            foreach ($attributes as $key => $value) {
                $attrs .= "$key='" . $value . "'";
            }
        }
        return $attrs;
    }
470004
public function select(
        $name,
        $list = [],
        $selected = null,
        array $selectAttributes = [],
        array $optionsAttributes = [],
        array $optgroupsAttributes = []
    ) {
        $selectAttributes = $this->appendClassToOptions(Config::get('form-builder.control-class'), $selectAttributes);

        return parent::select($name, $list, $selected, $selectAttributes, $optionsAttributes);
    }
287959
protected function optionGroup($list, $label, $selected, array $attributes = [], array $optionsAttributes = [], $level = 0)
    {
        $html = [];
        $space = str_repeat("&nbsp;", $level);
        foreach ($list as $value => $display) {
            $optionAttributes = $optionsAttributes[$value] ?? [];
            if (is_iterable($display)) {
                $html[] = $this->optionGroup($display, $value, $selected, $attributes, $optionAttributes, $level+5);
            } else {
                $html[] = $this->option($space.$display, $value, $selected, $optionAttributes);
            }
        }
        return $this->toHtmlString('<optgroup label="' . e($space.$label, false) . '"' . $this->html->attributes($attributes) . '>' . implode('', $html) . '</optgroup>');
    }
294474
private function _optionsHTML()
    {
        $result = '';
        foreach ($this->options() as $key => $label) {
            $selected = ResourceTable::getSearchValue($this->index()) == $key ? ' selected="selected"' : '';
            $result .= '<option value="'.$key.'"'.$selected.'>'.$label.'</option>';
        }
        return $result;
    }
251354
public function createSelect(array $options = [], $selected = null, array $attributes = [])
    {
        $select = new Form\Elements\Select($attributes);

        if (count($options)) {
            $select->createOptions($options, $selected);
        }

        $this->childNodes->push($select);

        return $this->childNodes->last();
    }
1110597
public static function select(string $name = '', array $values = [], array $selected = [],
                                  array $attributes = []): string
    {
        $defaultAttributes = ['method-get' => false, 'class' => 'form-select'];
        $userAttributes = \array_merge($defaultAttributes, $attributes);
        $attributes = [];
        $attributes['name'] = $userAttributes['method-get'] === false ? \sprintf('MFVARS[%s]', $name) : $name;
        $attributes['id'] = isset($userAttributes['id']) ? $userAttributes['id'] : $name;
        $attributes['data-selected'] = \implode(',', $selected);
        $wrapperClass = ['select-wrapper'];

        if (\array_key_exists('multiple', $userAttributes) && $userAttributes['multiple'] === true) {
            $attributes['multiple'] = 'multiple';
            $attributes['name'] = \sprintf('%s[]', $attributes['name']);
            $wrapperClass[] = 'multiple';
        }
        if (\array_key_exists('wrapper-class', $userAttributes)) {
            $wrapperClass[] = $userAttributes['wrapper-class'];
        }
        if (\array_key_exists('disabled', $userAttributes)) {
            $wrapperClass[] = 'disabled';
        }
        $clearAttributes = ['method-get', 'id', 'multiple', 'wrapper-class'];
        $userAttributes = static::clearAttributes($userAttributes, $clearAttributes);
        $select = Tags::select(self::getOptions($values, $selected, 0), \array_merge($attributes, $userAttributes));

        return Tags::div($select, ['class' => \implode(' ', $wrapperClass)]);
    }
90221
protected function _selectOptions($elements = array(), $parents = array(), $showParents = null, $attributes = array()) {
		$selectOptions = parent::_selectOptions($elements, $parents, $showParents, $attributes);
		if ($attributes['style'] === 'checkbox') {
			foreach ($selectOptions as $key => $option) {
				$option = preg_replace('/<div.*?>/', '', $option);
				$option = preg_replace('/<\/div>/', '', $option);
				if (preg_match('/>(<label.*?>)/', $option, $match)) {
					$class = $attributes['class'];

					$inline = !$class && $this->_getCustom('inline');
					if ($inline) {
						$class = 'checkbox-inline';
					}

					if (preg_match('/.* class="(.*)".*/', $match[1], $classMatch)) {
						$class = $classMatch[1] . ' ' . $attributes['class'];
						$match[1] = str_replace(' class="' . $classMatch[1] . '"', '', $match[1]);
					}
					$option = $match[1] . preg_replace('/<label.*?>/', ' ', $option);
					$option = preg_replace('/(<label.*?)(>)/', '$1 class="' . $class . '"$2', $option);

					if (!$inline) {
						$option = $this->Html->tag('div', $option, array('class' => 'checkbox'));
					}
				}
				$selectOptions[$key] = $option;
			}
		}

		return $selectOptions;
	}
1039433
protected function getOptions()
	{
		$options = array();

		$select = new HtmlSelect;

		// Try to inject the text object into the field
		try
		{
			$select->setText($this->getText());
		}
		catch (\RuntimeException $exception)
		{
			// A Text object was not set, ignore the error and try to continue processing
		}

		// Initialize some field attributes.
		$first = (int) $this->element['first'];
		$last = (int) $this->element['last'];
		$step = (int) $this->element['step'];

		// Sanity checks.
		if ($step == 0)
		{
			// Step of 0 will create an endless loop.
			return $options;
		}
		elseif ($first < $last && $step < 0)
		{
			// A negative step will never reach the last number.
			return $options;
		}
		elseif ($first > $last && $step > 0)
		{
			// A position step will never reach the last number.
			return $options;
		}
		elseif ($step < 0)
		{
			// Build the options array backwards.
			for ($i = $first; $i >= $last; $i += $step)
			{
				$options[] = $select->option($i);
			}
		}
		else
		{
			// Build the options array.
			for ($i = $first; $i <= $last; $i += $step)
			{
				$options[] = $select->option($i);
			}
		}

		// Merge any additional options in the XML definition.
		$options = array_merge(parent::getOptions(), $options);

		return $options;
	}
378949
public function dropdown($name, $options = [], $atributes = null)
    {
        $ret = '<select name="'.$name.'" '.(($attributes !== null) ? $this->attributes($attributes) : "").'>';
        foreach ($variable as $key => $value) {
            if (is_array($value)) {
                $ret .= '<option value="'.$key.'" '.((isset($value["attributes"])) ? $this->atributes($value["attributes"]) : "").'>'.$this->getValue($key, $value["value"]).'</option>';
            } else {
                $ret .= '<option value="'.$key.'">'.$this->getValue($key, $value).'</option>';
            }
        }
        $ret .= "</select>";
        return $ret;
    }
605774
public function prepareOptions(array $options)
    {
        $optionPieces = [];
        foreach ($options as $opt => $value) {
            //if it's an array of options, throw them in there as well
            if (is_array($value)) {
                foreach ($value as $optArrayValue) {
                    $optionPieces[] = '--'.$opt.'="'.addslashes($optArrayValue).'"';
                }
            } else {
                $option = null;

                //option exists with no value
                if (is_numeric($opt)) {
                    $option = $value;
                } elseif (!empty($value)) {
                    $option = $opt.'="'.addslashes($value).'"';
                }

                if (!is_null($option)) {
                    $optionPieces[] = '--'.$option;
                }
            }
        }

        return implode(' ', $optionPieces);
    }
1140351
private static function getSelectOptions($list, $selectedValue) {
        $result = '';

        if ($selectedValue !== null && !is_array($selectedValue)) {
            $selectedValue = array($selectedValue);
        }

        foreach ($list as $item) {
            $itemAttr = array();
            $text = '';

            if ($item instanceof SelectListItem) {
                $text = $item->text;
                $itemAttr['value'] = $item->value;

                if ($item->disabled === true) {
                    $itemAttr['disabled'] = 'disabled';
                }

                if ($selectedValue === null && $item->selected === true) {
                    $itemAttr['selected'] = 'selected';
                }
                elseif ($selectedValue !== null && in_array($item->value, $selectedValue) === true) {
                    $itemAttr['selected'] = 'selected';
                }
            }
            else {
                $text = $item;

                if ($selectedValue !== null && in_array($item, $selectedValue)) {
                    $itemAttr['selected'] = 'selected';
                }
            }

            $attr = self::buildAttributes($itemAttr);

            $result .= '<option' . (!empty($attr) ? ' ' : '') . $attr . '>';
            $result .= htmlspecialchars($text);
            $result .= '</option>';
        }

        return $result;
    }
888555
public function toString()
	{
		$attributes = $this->buildAttributes();

		$select = array();
		$select[] = '<select '.$attributes.'>';

		$firstValue = $this->firstValue;
		
		$value = isset($this->override) ? $this->override : (isset($this->attributes['value']) ? $this->attributes['value'] : '');

		if($firstValue)
		{
			$selected = $value == $firstValue['value'] ? 'selected' : '';
			$select[] = '<option '.$selected.' value="'.$firstValue['value'].'">'.$firstValue['label'].'</option>';
		}

		foreach($this->options as $val => $label)
		{
			if(is_array($label))
			{
				$select[] = '<optgroup label="'.$val.'">';
				foreach($label as $v => $l)
				{
					$selected = $v === $value ? 'selected' : '';
					$select[] = '<option '.$selected.' value="'.$v.'">'.$l.'</option>';
				}
				$select[] = '</optgroup>';
			}
			else
			{
				$selected = $val === $value ? 'selected' : '';
				$select[] = '<option '.$selected.' value="'.$val.'">'.$label.'</option>';
			}
		}

		$select[] = '</select>';

		return implode('', $select);
	}
1191784
protected function getOptions()
	{
		// Initialize variables.
		$options = array();

		if (!self::$countries)
		{
			self::$countries = array();

			$countries = Geocode::countries();

			if ($countries && !empty($countries))
			{
				self::$countries = $countries;
			}
		}

		if ($this->element['option_blank'])
		{
			$options[] = Dropdown::option('', App::get('language')->txt('- Select -'), 'value', 'text');
		}

		foreach (self::$countries as $option)
		{
			// Create a new option object based on the <option /> element.
			$tmp = Dropdown::option(
				(string) $option->code,
				App::get('language')->alt(trim((string) $option->name), preg_replace('/[^a-zA-Z0-9_\-]/', '_', $this->fieldname)), 'value', 'text'
			);

			// Add the option object to the result set.
			$options[] = $tmp;
		}

		reset($options);

		return $options;
	}