wikimedia/mediawiki-extensions-Wikibase

View on GitHub
repo/includes/ParserOutput/ParserOutputJsConfigBuilder.php

Summary

Maintainability
A
0 mins
Test Coverage
<?php

namespace Wikibase\Repo\ParserOutput;

use MediaWiki\Parser\ParserOutput;
use Wikibase\DataModel\Entity\EntityDocument;

/**
 * @license GPL-2.0-or-later
 */
class ParserOutputJsConfigBuilder {

    public function build( EntityDocument $entity, ParserOutput $parserOutput ): void {
        global $wgEditSubmitButtonLabelPublish;

        $entityId = $entity->getId();

        if ( !$entityId ) {
            $entityId = ''; //XXX: should probably throw an exception
        } else {
            $entityId = $entityId->getSerialization();
        }

        $parserOutput->setJsConfigVar( 'wbEntityId', $entityId );
        $parserOutput->setJsConfigVar( 'wgEditSubmitButtonLabelPublish', $wgEditSubmitButtonLabelPublish );
    }

}