refactor(core): ♻️ use core data for search box

This commit is contained in:
alistair3149 2022-10-04 22:40:23 -04:00
parent dfbaa67995
commit d78ffeadb4
No known key found for this signature in database
4 changed files with 9 additions and 17 deletions

View file

@ -73,23 +73,14 @@ final class Header extends Partial {
}
/**
* Render the search box
* Decorate search box template data
*
* @param array $searchBoxData original data-search-box
* @return array
* @throws MWException
*/
public function buildSearchProps(): array {
$skin = $this->skin;
$toggleMsg = $skin->msg( 'citizen-search-toggle' )->text();
return [
// TODO: This should be called in skin.json
'msg-citizen-search-toggle' => $toggleMsg,
'msg-citizen-search-toggle-shortcut' => $toggleMsg . ' [/]',
'form-action' => $this->getConfigValue( 'Script' ),
'html-input' => $skin->makeSearchInput( [ 'id' => 'searchInput' ] ),
'page-title' => SpecialPage::getTitleFor( 'Search' )->getPrefixedDBkey(),
public function decorateSearchBoxData( $searchBoxData ): array {
return $searchBoxData +=[
'msg-citizen-search-toggle-shortcut' => '[/]',
'html-random-href' => Skin::makeSpecialUrl( 'Randompage' ),
];
}

View file

@ -96,7 +96,6 @@ class SkinCitizen extends SkinMustache {
// Data objects
'data-header' => [
'data-personal-menu' => $header->buildPersonalMenu(),
'data-search-box' => $header->buildSearchProps(),
],
'data-sitestats' => $drawer->getSiteStatsData(),
// HTML strings
@ -109,6 +108,7 @@ class SkinCitizen extends SkinMustache {
'msg-citizen-footer-desc' => $this->msg( "citizen-footer-desc" )->inContentLanguage()->parse(),
'msg-citizen-footer-tagline' => $this->msg( "citizen-footer-tagline" )->inContentLanguage()->parse(),
// Decorate data provided by core
'data-search-box' => $header->decorateSearchBoxData( $parentData['data-search-box'] ),
'data-portlets-sidebar' => $drawer->decorateSidebarData( $parentData['data-portlets-sidebar'] ),
'data-footer' => $footer->decorateFooterData( $parentData['data-footer'] ),
];

View file

@ -41,6 +41,7 @@
"citizen-drawer-toggle",
"citizen-languages-toggle",
"citizen-personalmenu-toggle",
"citizen-search-toggle",
"randompage",
"search",
"sitetitle"

View file

@ -1,5 +1,5 @@
{{!
string msg-citizen-search-toggle-shortcut message with shortcut key for search toggle
string msg-citizen-search-toggle-shortcut shortcut key message
string msg-citizen-search-toggle tooltip message for search toggle
}}
<div class="citizen-search__button citizen-header__button">
@ -12,7 +12,7 @@
id="citizen-search__buttonCheckbox"
class="mw-checkbox-hack-button citizen-header__buttonCheckbox"
for="citizen-search__checkbox"
title="{{msg-citizen-search-toggle-shortcut}}"
title="{{msg-citizen-search-toggle}} {{msg-citizen-search-toggle-shortcut}}"
aria-hidden="true">
<span>{{msg-citizen-search-toggle}}</span>
</label>