label = isset( $config['labelElement'] ) ? $config['labelElement'] : new Tag( 'span' ); // Initialization $this->label->addClasses( [ 'oo-ui-labelElement-label' ] ); $this->setLabel( isset( $config['label'] ) ? $config['label'] : null ); $this->registerConfigCallback( function ( &$config ) { if ( $this->labelValue !== null ) { $config['label'] = $this->labelValue; } } ); } /** * Set the label. * * An empty string will result in the label being hidden. A string containing only whitespace will * be converted to a single ` `. * * @param string|HtmlSnippet|null $label Label text * @return $this */ public function setLabel( $label ) { $this->labelValue = (string)$label ? $label : null; $this->label->clearContent(); if ( $this->labelValue !== null ) { if ( is_string( $this->labelValue ) && $this->labelValue !== '' && trim( $this->labelValue ) === '' ) { $this->label->appendContent( new HtmlSnippet( ' ' ) ); } else { $this->label->appendContent( $label ); } } $this->toggleClasses( [ 'oo-ui-labelElement' ], !!$this->labelValue ); return $this; } /** * Get the label. * * @return string|HtmlSnippet|null Label text */ public function getLabel() { return $this->labelValue; } }