mirror of
https://gerrit.wikimedia.org/r/mediawiki/skins/Vector.git
synced 2024-11-24 07:43:47 +00:00
Prepare data for Page Tools menu
- Creates a new skin component called PageTools which is responsible for populating the new Page Tools menu. - Removes the toolbox menu from the sidebar and places it in the Page Tools menu. Bug: T318434 Change-Id: I9d552afab834193a4905d729eadecf71dda52cd2
This commit is contained in:
parent
fe561df654
commit
568cdf3d6d
60
includes/Components/VectorComponentPageTools.php
Normal file
60
includes/Components/VectorComponentPageTools.php
Normal file
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
namespace MediaWiki\Skins\Vector\Components;
|
||||
|
||||
use Skin;
|
||||
|
||||
/**
|
||||
* VectorComponentMainMenu component
|
||||
*/
|
||||
class VectorComponentPageTools implements VectorComponent {
|
||||
|
||||
/** @var array */
|
||||
private $toolbox;
|
||||
|
||||
/** @var array */
|
||||
private $actionsMenu;
|
||||
|
||||
/** @var Skin */
|
||||
private $skin;
|
||||
|
||||
/** @var VectorComponentPinnableHeader */
|
||||
private $pinnableHeader;
|
||||
|
||||
/** @var string */
|
||||
public const TOOLBOX_ID = 'p-tb';
|
||||
|
||||
/**
|
||||
* @param array $toolbox
|
||||
* @param array $actionsMenu
|
||||
* @param VectorComponentPinnableHeader $pinnableHeader
|
||||
* @param Skin $skin
|
||||
*/
|
||||
public function __construct(
|
||||
array $toolbox,
|
||||
array $actionsMenu,
|
||||
VectorComponentPinnableHeader $pinnableHeader,
|
||||
Skin $skin
|
||||
) {
|
||||
$this->toolbox = $toolbox;
|
||||
$this->actionsMenu = $actionsMenu;
|
||||
$this->pinnableHeader = $pinnableHeader;
|
||||
$this->skin = $skin;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
public function getTemplateData(): array {
|
||||
$menusData = [ $this->toolbox, $this->actionsMenu ];
|
||||
|
||||
$pinnableDropdownData = [
|
||||
'id' => 'vector-page-tools',
|
||||
'class' => 'vector-page-tools',
|
||||
'label' => $this->skin->msg( 'toolbox' ),
|
||||
'has-multiple-menus' => true,
|
||||
'data-pinnable-header' => $this->pinnableHeader->getTemplateData(),
|
||||
'data-menus' => $menusData
|
||||
];
|
||||
return $pinnableDropdownData;
|
||||
}
|
||||
}
|
|
@ -4,6 +4,7 @@ namespace MediaWiki\Skins\Vector;
|
|||
|
||||
use MediaWiki\MediaWikiServices;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentMainMenu;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentPageTools;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentPinnableHeader;
|
||||
use MediaWiki\Skins\Vector\Components\VectorComponentSearchBox;
|
||||
|
||||
|
@ -153,35 +154,6 @@ class SkinVector22 extends SkinVector {
|
|||
] );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $portletData
|
||||
* @return array
|
||||
*/
|
||||
private function getPageToolsData( array $portletData ): array {
|
||||
$actionsMenu = $portletData[ 'data-actions' ];
|
||||
$menusData = [ $actionsMenu ];
|
||||
|
||||
// Page Tools is unpinned by default, hardcoded for now
|
||||
$isPageToolsPinned = false;
|
||||
$pinnableHeader = new VectorComponentPinnableHeader(
|
||||
$this->getContext(),
|
||||
$isPageToolsPinned,
|
||||
'vector-page-tools'
|
||||
);
|
||||
|
||||
$pinnableDropdownData = [
|
||||
'id' => 'vector-page-tools',
|
||||
'class' => 'vector-page-tools',
|
||||
'label' => $this->msg( 'toolbox' ),
|
||||
'is-pinned' => $isPageToolsPinned,
|
||||
// @phan-suppress-next-line PhanSuspiciousValueComparison
|
||||
'has-multiple-menus' => count( $menusData ) > 1,
|
||||
'data-pinnable-header' => $pinnableHeader->getTemplateData(),
|
||||
'data-menus' => $menusData
|
||||
];
|
||||
return $pinnableDropdownData;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merges the `view-overflow` menu into the `action` menu.
|
||||
* This ensures that the previous state of the menu e.g. emptyPortlet class
|
||||
|
@ -289,11 +261,23 @@ class SkinVector22 extends SkinVector {
|
|||
}
|
||||
|
||||
$isPageToolsEnabled = $featureManager->isFeatureEnabled( Constants::FEATURE_PAGE_TOOLS );
|
||||
$sidebar = $parentData[ 'data-portlets-sidebar' ];
|
||||
$toolbox = [];
|
||||
if ( $isPageToolsEnabled ) {
|
||||
$pageToolsData = $this->getPageToolsData( $parentData['data-portlets'] );
|
||||
$parentData['data-portlets']['data-page-tools'] = $pageToolsData;
|
||||
}
|
||||
$toolboxMenuIndex = array_search(
|
||||
VectorComponentPageTools::TOOLBOX_ID,
|
||||
array_column(
|
||||
$parentData[ 'data-portlets-sidebar' ][ 'array-portlets-rest' ],
|
||||
'id'
|
||||
)
|
||||
);
|
||||
|
||||
if ( $toolboxMenuIndex !== false ) {
|
||||
$toolbox = $parentData[ 'data-portlets-sidebar' ][ 'array-portlets-rest' ][ $toolboxMenuIndex ];
|
||||
unset( $parentData[ 'data-portlets-sidebar' ][ 'array-portlets-rest' ][ $toolboxMenuIndex ] );
|
||||
$sidebar = $parentData[ 'data-portlets-sidebar' ];
|
||||
}
|
||||
}
|
||||
$config = $this->getConfig();
|
||||
$components = [
|
||||
'data-search-box' => new VectorComponentSearchBox(
|
||||
|
@ -308,10 +292,21 @@ class SkinVector22 extends SkinVector {
|
|||
$this->getContext()
|
||||
),
|
||||
'data-portlets-main-menu' => new VectorComponentMainMenu(
|
||||
$parentData['data-portlets-sidebar'],
|
||||
$sidebar,
|
||||
$this,
|
||||
$this->shouldLanguageAlertBeInSidebar()
|
||||
),
|
||||
'data-page-tools' => $isPageToolsEnabled ? new VectorComponentPageTools(
|
||||
$toolbox,
|
||||
$parentData['data-portlets']['data-actions'] ?? [],
|
||||
new VectorComponentPinnableHeader(
|
||||
$this->getContext(),
|
||||
// Page Tools is unpinned by default, hardcoded for now
|
||||
false,
|
||||
'vector-page-tools'
|
||||
),
|
||||
$this
|
||||
) : null,
|
||||
];
|
||||
foreach ( $components as $key => $component ) {
|
||||
// Array of components or null values.
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<div class="vector-column-end">
|
||||
<nav class="vector-page-tools-landmark" aria-label="{{msg-tooltip-p-cactions}}">
|
||||
{{#data-portlets.data-page-tools}}
|
||||
{{#data-page-tools}}
|
||||
{{>PinnedContainer/Open}}
|
||||
{{#is-pinned}}{{>PageTools}}{{/is-pinned}}
|
||||
{{>PinnedContainer/Close}}
|
||||
{{/data-portlets.data-page-tools}}
|
||||
{{/data-page-tools}}
|
||||
</nav>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue