Skip to content
This repository was archived by the owner on Jan 31, 2020. It is now read-only.

Commit bd01e81

Browse files
committed
Merge branch 'hotfix/123'
Close #123
2 parents eda66b8 + dcd1dac commit bd01e81

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ All notable changes to this project will be documented in this file, in reverse
2020

2121
### Fixed
2222

23-
- Nothing.
23+
- [#123](https://github.com/zendframework/zend-view/pull/123) updates the
24+
`HelperPluginManager` such that it no longer injects a translator in a helper
25+
if one is already present.
2426

2527
## 2.9.0 - 2017-03-21
2628

src/HelperPluginManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ public function injectTranslator($first, $second)
337337
return;
338338
}
339339

340+
if (method_exists($helper, 'hasTranslator') && $helper->hasTranslator()) {
341+
return;
342+
}
343+
340344
if ($container->has('MvcTranslator')) {
341345
$helper->setTranslator($container->get('MvcTranslator'));
342346
return;

test/HelperPluginManagerTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,28 @@ public function testInjectTranslatorWillReturnEarlyIfThePluginManagerDoesNotHave
186186
$this->assertNull($helper->getTranslator());
187187
}
188188

189+
public function testInjectTranslatorWillReturnEarlyIfTheHelperHasTranslatorAlready()
190+
{
191+
$translatorA = new Translator();
192+
$translatorB = new Translator();
193+
$config = new Config(['services' => [
194+
'Translator' => $translatorB,
195+
]]);
196+
$services = new ServiceManager();
197+
$config->configureServiceManager($services);
198+
$helpers = new HelperPluginManager($services);
199+
$helpers->setFactory(
200+
'TestHelper',
201+
function () use ($translatorA) {
202+
$helper = new HeadTitle();
203+
$helper->setTranslator($translatorA);
204+
return $helper;
205+
}
206+
);
207+
$helperB = $helpers->get('TestHelper');
208+
$this->assertSame($translatorA, $helperB->getTranslator());
209+
}
210+
189211
public function testCanOverrideAFactoryViaConfigurationPassedToConstructor()
190212
{
191213
$helper = $this->prophesize(HelperInterface::class)->reveal();

0 commit comments

Comments
 (0)