Private method called when rendering each option as HTML

@param mixed   $value
@param string  $label
@param boolean $selected
@param array   $options

@return string
420532
public static function renderOption($value, $label, $selected, $options = [])
    {
        if ($value === true) {
            // Handle the special case of a true value
            $value = "true";
        }
        $options = array_merge($options, ["value" => $value]);
        if ($selected) {
            $options['selected'] = true;
        }

        return sprintf("<option %s>%s</option>", html_params($options), $label);
    }
81665
public function renderValue($value, array $options = []): string
    {
        $object = isset($options['object']) ? $options['object'] : null;
        $column = isset($options['column']) ? $options['column'] : null;
        $attributeCode = isset($options['attribute']) ? $options['attribute'] : null;
        if ($column instanceof Column && null === $attributeCode) {
            $attributeCode = $column->getPropertyPath();
        }

        if ($object instanceof DataInterface && $attributeCode) {
            try {
                $attribute = $object->getFamily()->getAttribute($attributeCode);
            } catch (\Exception $e) {
                // do nothing, it's okay
                return $this->parent->renderValue($value, $options);
            }
            $formOptions = $attribute->getFormOptions();
            if (!isset($formOptions['choices'])
                || !\in_array($attribute->getType()->getCode(), $this->choiceTypes, true)
            ) {
                return $this->parent->renderValue($value, $options);
            }
            $key = array_search($value, $formOptions['choices'], true);
            if (false !== $key) {
                $translationDomain = null;
                if (array_key_exists('choice_translation_domain', $formOptions)) {
                    $translationDomain = $formOptions['choice_translation_domain'];
                }
                if (false === $translationDomain) {
                    return $key;
                }

                return $this->translator->trans($key, [], $translationDomain);
            }
        }

        return $this->parent->renderValue($value, $options);
    }
734738
public function staticControl($label, $html, $options = array()) {
		$options['type'] = 'static';
		$options = $this->addClass($options, 'form-control-static');
		$options = $this->_initInputOptions($options);

		$html = $this->Html->tag('div', $html, array('class' => $options['class']));

		// If size is set (like in an horizontal form) wrap inside div.size
		if ($this->inputOptions['custom']) {
			$html = $this->Html->tag('div', $html, array('class' => $this->inputOptions['custom']['wrap']));
		}

		if (!empty($options['label'])) {
			$label = $this->Html->tag('label', $label, $options['label']);
		}

		$divOptions = $this->_divOptions($options);
		unset($divOptions['tag']);
		$html = $this->Html->tag('div', $label . $html, $divOptions);

		return $html;
	}
1273670
public function compile($value = "")
	{
		$html = $this->compiledLabel;

		if (!empty($this->help)) {
			$html .= "<div class='help'>{$this->help}</div>";
		}

		$hasOptionValue = $this->hasOptionValue($this->options);

		$html .= "<select name=\"{$this->name}\" {$this->compiledAttr}>";

		// handle options in an associative array differently than ones in a numeric array
		if ($hasOptionValue || $this->useNumericValue) {

			foreach ($this->options as $k => $v) {
				$html .= "<option value=\"{$k}\"";
				if ($value === $k || (is_numeric($value) && (int) $value === $k)) {
					$html .= " selected=\"selected\"";
				}
				$html .= ">{$v}</option>";
			}

		} else {

			foreach ($this->options as $k => $v) {
				$html .= "<option value=\"{$v}\"";
				if ( $value === $v) {
					$html .= " selected=\"selected\"";
				}
				$html .= ">{$v}</option>";
			}
		}

		$html .= "</select>";

		return $html;
	}
246286
public static function collapseLink($label, $target, $htmlOptions = array())
    {
        $htmlOptions['data-toggle'] = 'collapse';
        return self::link($label, $target, $htmlOptions);
    }
387899
public static function label($name, $value = null, array $options = [])
    {
        self::exclure($options, ['value', 'for']);

        self::$labels[] = $name;

        $value = e(self::formatLabel($name, $value));

        $options = Html::attributes($options);

        return '<label for="'.$name.'"'.$options.'>'.$value.'</label>';
    }
1025007
protected function formatOption($name, $value, $label)
    {
        return '<option value="'.$value.'"'
                    .(isset($this->filters[$name]) && strpos($this->filters[$name], $value) === 0 ? ' selected' : '')
                .'>'.(isset($label) ? $label : $value).'</option>';
    }
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>";
    }
114640
protected function _option($value, $selected = false, $class = '', $label = '')
    {
        if ($selected === true) {
            $selected = ' selected="selected"';
        }

        $option = '<option value="' . $value . '" class="' . $class .  '"' . $selected .'>' .
                $this->_translate($label) .
            '</option>';

        return $option;
    }
352549
public function filter($value, $options = [])
    {
        $value    = (string) $value;
        $filtered = htmlentities(
            $value,
            $this->getQuoteStyle(),
            $this->getEncoding(),
            $this->getDoubleQuote()
        );

        if (strlen($value) && !strlen($filtered)) {
            if (!function_exists('iconv')) {
                $ex = new \Exception('Encoding mismatch has resulted in htmlentities errors.');
                throw $ex;
            }

            $enc      = $this->getEncoding();
            $value    = iconv('', $enc . '//IGNORE', $value);
            $filtered = htmlentities($value, $this->getQuoteStyle(), $enc, $this->getDoubleQuote());

            if (!strlen($filtered)) {
                $ex = new \Exception('Encoding mismatch has resulted in htmlentities errors.');
                throw $ex;
            }
        }

        return $filtered;
    }
549027
public function label($name, $value = null, $options = [])
    {
        if (!$value) {
            return '';
        }
        $this->labels[] = $name;
        $options        = $this->html->attributes($options);
        $value          = e($this->formatLabel($name, $value));
        return '<label for="' . $name . '"' . $options . '>' . $value . '</label>';
    }
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>');
    }
989570
public function optgroup($label, $options)
    {
        return Optgroup::create()
            ->label($label)
            ->addChildren($options, function ($text, $value) {
                return Option::create()
                    ->value($value)
                    ->text($text)
                    ->selectedIf($value === $this->value);
            });

        return $this->addChild($optgroup);
    }
1252394
public static Option create(String value, String label, boolean isSelected)
	{
		Option _result = new Option();
		_result.setValue(value);
		_result.setLabel(label);
		_result.setSelected(isSelected);
		return _result;
	}
1083946
public function createPreviewHtmlElement($label = false) {
        if ($label) {
            $options['label'] = $this->translate->_($label);
        } else {
            $options['label'] = $this->translate->_('Preview HTML');
        }
        $options['nohidden'] = true;

        return $this->_form->createElement('Html', 'preview_html', $options);
    }
635507
public static function selecty($options, $selected = null, $attribs = array())
    {
        $htmls = array();
        $htmls[] = self::select(null, $attribs, false);
        if (Arr::iterable($options)) {
            foreach ($options as $value => $title) {
                $option_attribs = array('value'=>$value);
                if ((string) $selected === (string) $value) {
                    $option_attribs['selected'] = 'selected';
                }
                
                $htmls[] = self::option($title, $option_attribs);
            }
        }
        $htmls[] = '</select>';
        return join("\n", $htmls);
    }
172396
public function toHtmlInternal($value = null)
    {
        $strSelected = "";
        if ($this->__selected && is_null($value)) {
            $strSelected = " selected=\"selected\"";
        }

        if ($value == $this->__value) {
            $strSelected = " selected=\"selected\"";
        }

        $strOutput = "<option value=\"{$this->__value}\"{$strSelected} {$this->__getMetaString()}>{$this->__label}</option>\n";

        return $strOutput;
    }