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

Commit 106be69

Browse files
committed
Merge branch 'hotfix/134' into develop
Forward port #134 Conflicts: CHANGELOG.md
2 parents f96a55f + 38d282c commit 106be69

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,35 @@ All notable changes to this project will be documented in this file, in reverse
3636

3737
### Fixed
3838

39+
- [#134](https://github.com/zendframework/zend-form/pull/134) fixes how the
40+
`FormElementManager` handles invokable classes when the `autoAddInvokableClass`
41+
flag is enabled. Previously, it used the built-in utilities from
42+
zend-servicemanager, but now correctly uses its own `setInvokableClass()`
43+
method, which forces usage of the `ElementFactory` for such classes, and thus
44+
ensures the name and options are passed to the element constructor.
45+
46+
## 2.10.0 - 2017-02-23
47+
48+
### Added
49+
50+
- [#115](https://github.com/zendframework/zend-form/pull/115) adds translatable
51+
HTML attributes to the abstract view helper.
52+
- [#116](https://github.com/zendframework/zend-form/pull/116) adds the InputFilterFactory
53+
dependency to the constructor.
54+
55+
### Deprecated
56+
57+
- Nothing.
58+
59+
### Removed
60+
3961
- Nothing.
4062

63+
### Fixed
64+
65+
- [#139](https://github.com/zendframework/zend-form/pull/139) adds support for
66+
ReCaptcha version 2 though zend-captcha 2.7.1.
67+
4168
## 2.10.0 - 2017-02-23
4269

4370
### Added

src/FormElementManager/FormElementManagerTrait.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ public function get($name, $options = [], $usePeeringServiceManagers = true)
3535
if (is_string($options)) {
3636
$options = ['name' => $options];
3737
}
38+
39+
if (! $this->has($name)) {
40+
if (! $this->autoAddInvokableClass || ! class_exists($name)) {
41+
throw new Exception\InvalidElementException(sprintf(
42+
'A plugin by the name "%s" was not found in the plugin manager %s',
43+
$name,
44+
get_class($this)
45+
));
46+
}
47+
48+
$this->setInvokableClass($name, $name);
49+
}
3850
return parent::get($name, $options, $usePeeringServiceManagers);
3951
}
4052

test/FormElementManagerTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,18 @@ public function testAddingInvokableCreatesAliasAndMapsClassToElementFactory()
222222
}
223223
}
224224

225+
public function testAutoAddInvokableClass()
226+
{
227+
$instance = $this->manager->get(
228+
TestAsset\ConstructedElement::class,
229+
['constructedKey' => 'constructedKey']
230+
);
231+
$this->assertEquals('constructedelement', $instance->getName());
232+
$this->assertEquals([
233+
'constructedKey' => 'constructedKey'
234+
], $instance->getOptions());
235+
}
236+
225237
public function testAllAliasesShouldBeCanonicalized()
226238
{
227239
if (method_exists($this->manager, 'configure')) {

test/TestAsset/ConstructedElement.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* @see https://github.com/zendframework/zend-navigation for the canonical source repository
4+
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
5+
* @license https://github.com/zendframework/zend-form/blob/master/LICENSE.md New BSD License
6+
*/
7+
8+
namespace ZendTest\Form\TestAsset;
9+
10+
use Zend\Form\Element;
11+
12+
class ConstructedElement extends Element
13+
{
14+
public $constructedKey;
15+
16+
/**
17+
* @param null|int|string $name
18+
* @param array $options
19+
*/
20+
public function __construct($name = null, $options = [])
21+
{
22+
if (isset($options['constructedKey'])) {
23+
$this->constructedKey = $options['constructedKey'];
24+
}
25+
parent::__construct($name, $options);
26+
}
27+
}

0 commit comments

Comments
 (0)