Merge "Table of contents elements should not be rendered where none available"

This commit is contained in:
jenkins-bot 2023-01-13 18:15:31 +00:00 committed by Gerrit Code Review
commit 21996f5bc5
2 changed files with 11 additions and 9 deletions

View file

@ -50,14 +50,12 @@ class VectorComponentTableOfContents implements VectorComponent {
* @inheritDoc
*/
public function getTemplateData(): array {
// If the table of contents has no items, we won't output it.
// empty array is interpreted by Mustache as falsey.
if ( empty( $this->tocData ) || empty( $this->tocData[ 'array-sections' ] ) ) {
$sections = $this->tocData[ 'array-sections' ] ?? [];
if ( empty( $sections ) ) {
return [];
}
// Populate button labels for collapsible TOC sections
foreach ( $this->tocData[ 'array-sections' ] as &$section ) {
foreach ( $sections as &$section ) {
if ( $section['is-top-level-section'] && $section['is-parent-section'] ) {
$section['vector-button-label'] =
$this->localizer->msg( 'vector-toc-toggle-button-label', $section['line'] )->text();

View file

@ -307,6 +307,10 @@ class SkinVector22 extends SkinMustache {
$loginLinkData = $this->buildLoginData( $returnto, $this->useCombinedLoginLink() );
$createAccountData = $this->buildCreateAccountData( $returnto );
$localizer = $this->getContext();
$tocData = $parentData['data-toc'];
// If the table of contents has no items, we won't output it.
// empty array is interpreted by Mustache as falsey.
$isTocUnavailable = empty( $tocData ) || empty( $tocData[ 'array-sections' ] );
$components = [
'data-vector-variants' => new VectorComponentMenuVariants(
$parentData['data-portlets']['data-variants'],
@ -372,11 +376,11 @@ class SkinVector22 extends SkinMustache {
$langData['html-after-portal'] ?? '',
$this->getTitle()
) : null,
'data-toc-container' => new VectorComponentTableOfContentsContainer(
'data-toc-container' => $isTocUnavailable ? null : new VectorComponentTableOfContentsContainer(
$localizer,
),
'data-toc' => new VectorComponentTableOfContents(
$parentData['data-toc'],
'data-toc' => $isTocUnavailable ? null : new VectorComponentTableOfContents(
$tocData,
$localizer,
$this->getConfig()
),
@ -417,7 +421,7 @@ class SkinVector22 extends SkinMustache {
$this->msg( 'toolbox' )->text(),
VectorComponentPageTools::ID . '-dropdown',
) : null,
'data-page-titlebar-toc-dropdown' => new VectorComponentDropdown(
'data-page-titlebar-toc-dropdown' => $isTocUnavailable ? null : new VectorComponentDropdown(
'vector-page-titlebar-toc',
// no label,
'',