Cake\View\StringTemplate::_formatAttribute PHP Method

_formatAttribute() protected method

Works with minimized attributes that have the same value as their name such as 'disabled' and 'checked'
protected _formatAttribute ( string $key, string | array $value, boolean $escape = true ) : string
$key string The name of the attribute to create
$value string | array The value of the attribute to create.
$escape boolean Define if the value must be escaped
return string The composed attribute.
    protected function _formatAttribute($key, $value, $escape = true)
    {
        if (is_array($value)) {
            $value = implode(' ', $value);
        }
        if (is_numeric($key)) {
            return "{$value}=\"{$value}\"";
        }
        $truthy = [1, '1', true, 'true', $key];
        $isMinimized = isset($this->_compactAttributes[$key]);
        if ($isMinimized && in_array($value, $truthy, true)) {
            return "{$key}=\"{$key}\"";
        }
        if ($isMinimized) {
            return '';
        }
        return $key . '="' . ($escape ? h($value) : $value) . '"';
    }