6 * Element with a title.
8 * Titles are rendered by the browser and are made visible when hovering the element. Titles are
9 * not visible on touch devices.
19 protected $title = null;
27 * @param array $config Configuration options
28 * @param string $config['title'] Title. If not provided, the static property 'title' is used.
30 public function initializeTitledElement( array $config = [] ) {
32 $this->titled = isset( $config['titled'] ) ? $config['titled'] : $this;
36 isset( $config['title'] ) ? $config['title'] : null
39 $this->registerConfigCallback( function ( &$config ) {
40 if ( $this->title !== null ) {
41 $config['title'] = $this->title;
49 * @param string|null $title Title text or null for no title
52 public function setTitle( $title ) {
53 $title = $title !== '' ? $title : null;
55 if ( $this->title !== $title ) {
56 $this->title = $title;
64 * Update the title attribute, in case of changes to title or accessKey.
68 protected function updateTitle() {
69 $title = $this->getTitle();
70 if ( $title !== null ) {
71 // Only if this is an AccessKeyedElement
72 if ( method_exists( $this, 'formatTitleWithAccessKey' ) ) {
73 $title = $this->formatTitleWithAccessKey( $title );
75 $this->titled->setAttributes( [ 'title' => $title ] );
77 $this->titled->removeAttributes( [ 'title' ] );
85 * @return string Title string
87 public function getTitle() {