X-Git-Url: https://git.heureux-cyclage.org/?p=lhc%2Fweb%2Fwiklou.git;a=blobdiff_plain;f=includes%2FXmlSelect.php;h=89f2f41cb876284d488fd5c6a464d31e6d4b6f2e;hp=e765eedbc33a10ad5dc674c68e2efc6e31e70d12;hb=631e8695b15412ec16c31623cbd6e5aa3d6efb1e;hpb=586effc0b7a0307ded8a7a587adca44b9b3febf9 diff --git a/includes/XmlSelect.php b/includes/XmlSelect.php index e765eedbc3..89f2f41cb8 100644 --- a/includes/XmlSelect.php +++ b/includes/XmlSelect.php @@ -21,12 +21,13 @@ */ /** - * Class for generating HTML or elements. */ class XmlSelect { - protected $options = array(); + protected $options = []; protected $default = false; - protected $attributes = array(); + protected $tagName = 'select'; + protected $attributes = []; public function __construct( $name = false, $id = false, $default = false ) { if ( $name ) { @@ -43,12 +44,19 @@ class XmlSelect { } /** - * @param string $default + * @param string|array $default */ public function setDefault( $default ) { $this->default = $default; } + /** + * @param string|array $tagName + */ + public function setTagName( $tagName ) { + $this->tagName = $tagName; + } + /** * @param string $name * @param string $value @@ -75,7 +83,7 @@ class XmlSelect { */ public function addOption( $label, $value = false ) { $value = $value !== false ? $value : $label; - $this->options[] = array( $label => $value ); + $this->options[] = [ $label => $value ]; } /** @@ -95,7 +103,7 @@ class XmlSelect { * label => ( label => value, label => value ) * * @param array $options - * @param string $default + * @param string|array $default * @return string */ static function formatOptions( $options, $default = false ) { @@ -104,9 +112,13 @@ class XmlSelect { foreach ( $options as $label => $value ) { if ( is_array( $value ) ) { $contents = self::formatOptions( $value, $default ); - $data .= Html::rawElement( 'optgroup', array( 'label' => $label ), $contents ) . "\n"; + $data .= Html::rawElement( 'optgroup', [ 'label' => $label ], $contents ) . "\n"; } else { - $data .= Xml::option( $label, $value, $value === $default ) . "\n"; + // If $default is an array, then the