1<?php 2 3namespace OOUI; 4 5/** 6 * Icon widget. 7 * 8 * See IconElement for more information. 9 */ 10class IconWidget extends Widget { 11 use IconElement; 12 use TitledElement; 13 use LabelElement; 14 use FlaggedElement; 15 16 /* Static Properties */ 17 18 public static $tagName = 'span'; 19 20 /** 21 * @param array $config Configuration options 22 */ 23 public function __construct( array $config = [] ) { 24 // Parent constructor 25 parent::__construct( $config ); 26 27 // Traits 28 $this->initializeIconElement( 29 array_merge( [ 'iconElement' => $this ], $config ) 30 ); 31 $this->initializeTitledElement( 32 array_merge( [ 'titled' => $this ], $config ) 33 ); 34 $this->initializeLabelElement( 35 array_merge( [ 'labelElement' => $this, 'invisibleLabel' => true ], $config ) 36 ); 37 $this->initializeFlaggedElement( 38 array_merge( [ 'flagged' => $this ], $config ) 39 ); 40 41 // Initialization 42 $this->addClasses( [ 'oo-ui-iconWidget' ] ); 43 // Remove class added by LabelElement initialization. It causes unexpected CSS to apply when 44 // nested in other widgets, because this widget used to not mix in LabelElement. 45 $this->removeClasses( [ 'oo-ui-labelElement-label' ] ); 46 47 $this->registerConfigCallback( function ( &$config ) { 48 // We have changed the default value, so change when it is outputted. 49 unset( $config['invisibleLabel'] ); 50 if ( $this->invisibleLabel !== true ) { 51 $config['invisibleLabel'] = $this->invisibleLabel; 52 } 53 } ); 54 } 55} 56