MediaWiki master
ListToggle.php
Go to the documentation of this file.
1<?php
23namespace MediaWiki\Html;
24
26
37 private $output;
38
39 public function __construct( OutputPage $output ) {
40 $this->output = $output;
41
42 $output->addModules( 'mediawiki.checkboxtoggle' );
43 $output->addModuleStyles( 'mediawiki.checkboxtoggle.styles' );
44 }
45
46 private function checkboxLink( $checkboxType ) {
47 return Html::element(
48 // CSS classes: mw-checkbox-all, mw-checkbox-none, mw-checkbox-invert
49 'a', [ 'class' => 'mw-checkbox-' . $checkboxType, 'role' => 'button', 'tabindex' => 0 ],
50 $this->output->msg( 'checkbox-' . $checkboxType )->text()
51 );
52 }
53
57 public function getHTML() {
58 // Select: All, None, Invert
59 $links = [
60 $this->checkboxLink( 'all' ),
61 $this->checkboxLink( 'none' ),
62 $this->checkboxLink( 'invert' ),
63 ];
64
65 return Html::rawElement(
66 'div',
67 [
68 'class' => 'mw-checkbox-toggle-controls',
69 ],
70 $this->output->msg( 'checkbox-select' )
71 ->rawParams( $this->output->getLanguage()->commaList( $links ) )->escaped()
72 );
73 }
74}
75
77class_alias( ListToggle::class, 'ListToggle' );
static rawElement( $element, $attribs=[], $contents='')
Returns an HTML element in a string.
Definition Html.php:191
static element( $element, $attribs=[], $contents='')
Identical to rawElement(), but HTML-escapes $contents (like Xml::element()).
Definition Html.php:216
Class for generating clickable toggle links for a list of checkboxes.
__construct(OutputPage $output)
This is one of the Core classes and should be read at least once by any new developers.
addModules( $modules)
Load one or more ResourceLoader modules on this page.
addModuleStyles( $modules)
Load the styles of one or more style-only ResourceLoader modules on this page.