tocData = $tocData; $this->localizer = $localizer; $this->isPinned = $featureManager->isFeatureEnabled( Constants::FEATURE_TOC_PINNED ); $this->config = $config; $this->pinnableHeader = new VectorComponentPinnableHeader( $this->localizer, $this->isPinned, self::ID, 'toc-pinned', false, 'h2' ); } /** * @return bool */ public function isPinned(): bool { return $this->isPinned; } /** * In tableOfContents.js we have tableOfContents::getTableOfContentsSectionsData(), * that yields the same result as this function, please make sure to keep them in sync. * @inheritDoc */ public function getTemplateData(): array { $sections = $this->tocData[ 'array-sections' ] ?? []; if ( !$sections ) { return []; } // Populate button labels for collapsible TOC sections 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' ) ->rawParams( $section['line'] ) ->escaped(); } } $this->tocData[ 'array-sections' ] = $sections; $pinnableElement = new VectorComponentPinnableElement( self::ID ); return $pinnableElement->getTemplateData() + array_merge( $this->tocData, [ 'vector-is-collapse-sections-enabled' => count( $this->tocData['array-sections'] ) > 3 && $this->tocData[ 'number-section-count'] >= $this->config->get( 'VectorTableOfContentsCollapseAtCount' ), 'data-pinnable-header' => $this->pinnableHeader->getTemplateData(), ] ); } }