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

Commit

Permalink
Merge branch 'hotfix/134' into develop
Browse files Browse the repository at this point in the history
Forward port #134

Conflicts:
	CHANGELOG.md
  • Loading branch information
weierophinney committed Apr 26, 2017
2 parents f96a55f + 38d282c commit 106be69
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,35 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#134](https://github.com/zendframework/zend-form/pull/134) fixes how the
`FormElementManager` handles invokable classes when the `autoAddInvokableClass`
flag is enabled. Previously, it used the built-in utilities from
zend-servicemanager, but now correctly uses its own `setInvokableClass()`
method, which forces usage of the `ElementFactory` for such classes, and thus
ensures the name and options are passed to the element constructor.

## 2.10.0 - 2017-02-23

### Added

- [#115](https://github.com/zendframework/zend-form/pull/115) adds translatable
HTML attributes to the abstract view helper.
- [#116](https://github.com/zendframework/zend-form/pull/116) adds the InputFilterFactory
dependency to the constructor.

### Deprecated

- Nothing.

### Removed

- Nothing.

### Fixed

- [#139](https://github.com/zendframework/zend-form/pull/139) adds support for
ReCaptcha version 2 though zend-captcha 2.7.1.

## 2.10.0 - 2017-02-23

### Added
Expand Down
12 changes: 12 additions & 0 deletions src/FormElementManager/FormElementManagerTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ public function get($name, $options = [], $usePeeringServiceManagers = true)
if (is_string($options)) {
$options = ['name' => $options];
}

if (! $this->has($name)) {
if (! $this->autoAddInvokableClass || ! class_exists($name)) {
throw new Exception\InvalidElementException(sprintf(
'A plugin by the name "%s" was not found in the plugin manager %s',
$name,
get_class($this)
));
}

$this->setInvokableClass($name, $name);
}
return parent::get($name, $options, $usePeeringServiceManagers);
}

Expand Down
12 changes: 12 additions & 0 deletions test/FormElementManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,18 @@ public function testAddingInvokableCreatesAliasAndMapsClassToElementFactory()
}
}

public function testAutoAddInvokableClass()
{
$instance = $this->manager->get(
TestAsset\ConstructedElement::class,
['constructedKey' => 'constructedKey']
);
$this->assertEquals('constructedelement', $instance->getName());
$this->assertEquals([
'constructedKey' => 'constructedKey'
], $instance->getOptions());
}

public function testAllAliasesShouldBeCanonicalized()
{
if (method_exists($this->manager, 'configure')) {
Expand Down
27 changes: 27 additions & 0 deletions test/TestAsset/ConstructedElement.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* @see https://github.com/zendframework/zend-navigation for the canonical source repository
* @copyright Copyright (c) 2017 Zend Technologies USA Inc. (http://www.zend.com)
* @license https://github.com/zendframework/zend-form/blob/master/LICENSE.md New BSD License
*/

namespace ZendTest\Form\TestAsset;

use Zend\Form\Element;

class ConstructedElement extends Element
{
public $constructedKey;

/**
* @param null|int|string $name
* @param array $options
*/
public function __construct($name = null, $options = [])
{
if (isset($options['constructedKey'])) {
$this->constructedKey = $options['constructedKey'];
}
parent::__construct($name, $options);
}
}

0 comments on commit 106be69

Please sign in to comment.