| 1 |
<?php |
| 2 |
|
| 3 |
namespace OOUI; |
| 4 |
|
| 5 |
/** |
| 6 |
* Layout made of a fieldset and optional legend. |
| 7 |
* |
| 8 |
* Just add FieldLayout items. |
| 9 |
*/ |
| 10 |
class FieldsetLayout extends Layout { |
| 11 |
use IconElement; |
| 12 |
use LabelElement; |
| 13 |
use GroupElement; |
| 14 |
|
| 15 |
/* Static Properties */ |
| 16 |
|
| 17 |
/** @var string */ |
| 18 |
public static $tagName = 'fieldset'; |
| 19 |
|
| 20 |
/** @var Tag */ |
| 21 |
protected $header; |
| 22 |
/** @var string */ |
| 23 |
protected $helpText; |
| 24 |
/** @var string|false */ |
| 25 |
protected $helpInline; |
| 26 |
|
| 27 |
/** |
| 28 |
* @param array $config Configuration options |
| 29 |
* - FieldLayout[] $config['items'] Items to add |
| 30 |
* - string|HtmlSnippet $config['help'] Explanatory text shown as a '?' icon, or inline. |
| 31 |
* - bool $config['helpInline'] Whether or not the help should be inline, |
| 32 |
* or shown when the "help" icon is clicked. (default: false) |
| 33 |
*/ |
| 34 |
public function __construct( array $config = [] ) { |
| 35 |
// Parent constructor |
| 36 |
parent::__construct( $config ); |
| 37 |
|
| 38 |
// Traits |
| 39 |
$this->initializeIconElement( $config ); |
| 40 |
$this->initializeLabelElement( $config ); |
| 41 |
$this->initializeGroupElement( $config ); |
| 42 |
|
| 43 |
// Properties |
| 44 |
$this->header = new Tag( 'legend' ); |
| 45 |
$this->helpText = $config['help'] ?? ''; |
| 46 |
$this->helpInline = $config['helpInline'] ?? false; |
| 47 |
|
| 48 |
// Initialization |
| 49 |
$this->header |
| 50 |
->addClasses( [ 'oo-ui-fieldsetLayout-header' ] ) |
| 51 |
->appendContent( $this->icon, $this->label ); |
| 52 |
$this->group->addClasses( [ 'oo-ui-fieldsetLayout-group' ] ); |
| 53 |
$this |
| 54 |
->addClasses( [ 'oo-ui-fieldsetLayout' ] ) |
| 55 |
->prependContent( $this->header, $this->group ); |
| 56 |
|
| 57 |
if ( $this->helpText ) { |
| 58 |
if ( $this->helpInline ) { |
| 59 |
$helpWidget = new LabelWidget( [ |
| 60 |
'classes' => [ 'oo-ui-inline-help' ], |
| 61 |
'label' => $this->helpText, |
| 62 |
] ); |
| 63 |
$this->prependContent( $this->header, $helpWidget, $this->group ); |
| 64 |
} else { |
| 65 |
$helpWidget = new ButtonWidget( [ |
| 66 |
'classes' => [ 'oo-ui-fieldsetLayout-help' ], |
| 67 |
'framed' => false, |
| 68 |
'icon' => 'info', |
| 69 |
'title' => $this->helpText, |
| 70 |
// TODO We have no way to use localisation messages in PHP |
| 71 |
// (and to use different languages when used from MediaWiki) |
| 72 |
// 'label' => msg( 'ooui-field-help' ), |
| 73 |
// 'invisibleLabel' => true, |
| 74 |
] ); |
| 75 |
$this->header->appendContent( $helpWidget ); |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
if ( isset( $config['items'] ) ) { |
| 80 |
$this->addItems( $config['items'] ); |
| 81 |
} |
| 82 |
} |
| 83 |
|
| 84 |
/** @inheritDoc */ |
| 85 |
public function getConfig( &$config ) { |
| 86 |
$config['$overlay'] = true; |
| 87 |
if ( $this->helpText !== '' ) { |
| 88 |
$config['help'] = $this->helpText; |
| 89 |
} |
| 90 |
if ( $this->helpInline ) { |
| 91 |
$config['helpInline'] = $this->helpInline; |
| 92 |
} |
| 93 |
return parent::getConfig( $config ); |
| 94 |
} |
| 95 |
} |