= 1 && $count <= 6 ? $count : 6 );
$attr['multiple'] = true;
$attr['name'] .= '[]';
}
$attr['type'] = 'select';
$options = $attr;
unset( $attr['options'] );
unset( $attr['value'] );
unset( $attr['show_option_none'] );
return \sprintf(
'%s%s',
$this->label(),
HTML\get_attr( 'input', $attr ),
$this->renderOptions( $options ),
$this->description()
);
}
protected function renderOptions( array $attr ) {
if ( isset( $attr['show_option_none'] ) ) {
$none = \is_string( $attr['show_option_none'] ) ? $attr['show_option_none'] : __( 'None', 'italystrap' ) ;
$attr['options'] = [ $none ] + $attr['options'];
}
$html = '';
foreach ( (array) $attr['options'] as $value => $option ) {
$html .= \sprintf(
'',
HTML\get_attr(
'option',
[
'value' => $value,
'selected' => $this->isSelected( $value, $attr['value'], $attr ),
]
),
\esc_html( $option )
);
}
return $html;
}
/**
* @param int|string $needle
* @param int|string|array $haystack
* @param array $attr
*
* @return bool|string
*/
protected function isSelected( $needle, $haystack, array $attr ) {
if (
\is_array( $haystack )
&& \in_array( $needle, $haystack, true )
|| $needle == $haystack
) {
return 'selected';
}
return false;
}
protected function isMultiple( array $attr) {
return isset( $attr['multiple'] ) || isset( $attr['attributes']['multiple'] );
}
/**
* Create the Field Select with Options Group
*
* @TODO
*
* @access public
* @param array $key The key of field's array to create the HTML field.
* @param string $out The HTML form output.
* @return string Return the HTML Field Select with Options Group
*/
private function selectGroup( array $key, $out = '' ) {
// $out .= $this->label( $key['name'], $key['_id'] );
$out .= $this->label();
$out .= '';
if ( isset( $key['desc'] ) ) {
// $out .= $this->description( $key['desc'] );
$out .= $this->description();
}
return $out;
}
}