Skip to content

Commit

Permalink
Merge pull request #406 from Wikia/simplify-mapping-service
Browse files Browse the repository at this point in the history
Change signature of MapsMappingService::addDependencies
  • Loading branch information
JeroenDeDauw authored Jan 22, 2018
2 parents 2763cf1 + 6453e06 commit 4c1d0a8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 17 deletions.
6 changes: 4 additions & 2 deletions includes/Maps_DisplayMapRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public final function renderMap( array $params, Parser $parser ) {
self::getLayerDependencies( $params['mappingservice'], $params )
);

$this->service->addDependencies( $parser );
$parser->getOutput()->addHeadItem( $configVars );
$parserOutput = $parser->getOutput();

$this->service->addDependencies( $parserOutput );
$parserOutput->addHeadItem( $configVars );

return $output;
}
Expand Down
23 changes: 8 additions & 15 deletions includes/Maps_MappingService.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,25 +78,18 @@ public function addFeature( $featureName, $handlingClass ) {
}

/**
* @since 0.6.3
* @since 5.2.0
* @param ParserOutput $parserOutput
*/
public final function addDependencies( &$parserOrOut ) {
public final function addDependencies( ParserOutput $parserOutput ) {
$dependencies = $this->getDependencyHtml();

// Only add a head item when there are dependencies.
if ( $parserOrOut instanceof Parser ) {
if ( $dependencies ) {
$parserOrOut->getOutput()->addHeadItem( $dependencies );
}

$parserOrOut->getOutput()->addModules( $this->getResourceModules() );
} elseif ( $parserOrOut instanceof OutputPage ) {
if ( $dependencies !== false ) {
$parserOrOut->addHeadItem( md5( $dependencies ), $dependencies );
}

$parserOrOut->addModules( $this->getResourceModules() );
if ( $dependencies ) {
$parserOutput->addHeadItem( $dependencies );
}

$parserOutput->addModules( $this->getResourceModules() );
}

/**
Expand All @@ -106,7 +99,7 @@ public final function getDependencyHtml() {
$allDependencies = array_merge( $this->getDependencies(), $this->dependencies );
$dependencies = [];

// Only add dependnecies that have not yet been added.
// Only add dependencies that have not yet been added.
foreach ( $allDependencies as $dependency ) {
if ( !in_array( $dependency, $this->addedDependencies ) ) {
$dependencies[] = $dependency;
Expand Down

0 comments on commit 4c1d0a8

Please sign in to comment.