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

Commit

Permalink
Merge branch 'feature/7309' into develop
Browse files Browse the repository at this point in the history
Close #7309
Fixes #7131
  • Loading branch information
weierophinney committed Mar 17, 2015
2 parents 256362e + 86ad98b commit 7fbb074
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
10 changes: 9 additions & 1 deletion library/Zend/Form/Annotation/ElementAnnotationsListener.php
Expand Up @@ -98,7 +98,10 @@ public function handleAttributesAnnotation($e)

$elementSpec = $e->getParam('elementSpec');
if (isset($elementSpec['spec']['attributes'])) {
$elementSpec['spec']['attributes'] = array_merge($elementSpec['spec']['attributes'], $annotation->getAttributes());
$elementSpec['spec']['attributes'] = array_merge(
$elementSpec['spec']['attributes'],
$annotation->getAttributes()
);
return;
}

Expand Down Expand Up @@ -163,6 +166,11 @@ public function handleComposedObjectAnnotation($e)
$specification['type'] = 'Zend\Form\Fieldset';
}

if (isset($elementSpec['spec']['options'])) {
$specification['options'] = isset($specification['options']) ? $specification['options'] : array();
$specification['options'] = array_merge($elementSpec['spec']['options'], $specification['options']);
}

// Add element spec:
$elementSpec['spec'] = $specification;
$elementSpec['spec']['name'] = $name;
Expand Down
29 changes: 29 additions & 0 deletions tests/ZendTest/Form/Annotation/AnnotationBuilderTest.php
Expand Up @@ -11,6 +11,7 @@

use PHPUnit_Framework_TestCase as TestCase;
use Zend\Form\Annotation;
use Zend\Form\Element\Collection;
use ZendTest\Form\TestAsset;

class AnnotationBuilderTest extends TestCase
Expand Down Expand Up @@ -239,6 +240,34 @@ public function provideOptionsAnnotationAndComposedObjectAnnotation()
return array(array('child'), array('childTheSecond'));
}

/**
* @dataProvider provideOptionsAnnotationAndComposedObjectAnnotationNoneCollection
* @param string $childName
*
* @group 7108
*/
public function testOptionsAnnotationAndComposedObjectAnnotationNoneCollection($childName)
{
$entity = new TestAsset\Annotation\EntityUsingComposedObjectAndOptions();
$builder = new Annotation\AnnotationBuilder();
$form = $builder->createForm($entity);

$child = $form->get($childName);

$this->assertInstanceOf('Zend\Form\FieldsetInterface', $child);
$this->assertEquals('My label', $child->getLabel());
}

/**
* Data provider
*
* @return string[][]
*/
public function provideOptionsAnnotationAndComposedObjectAnnotationNoneCollection()
{
return array(array('childTheThird'), array('childTheFourth'));
}

public function testCanHandleOptionsAnnotation()
{
$entity = new TestAsset\Annotation\EntityUsingOptions();
Expand Down
Expand Up @@ -29,4 +29,18 @@ class EntityUsingComposedObjectAndOptions
* @Annotation\Options({"label": "My label"})
*/
public $childTheSecond;

/**
* @Annotation\Name("childTheThird")
* @Annotation\ComposedObject("ZendTest\Form\TestAsset\Annotation\Entity")
* @Annotation\Options({"label": "My label"})
*/
public $childTheThird;

/**
* @Annotation\Name("childTheFourth")
* @Annotation\Options({"label": "My label"})
* @Annotation\ComposedObject("ZendTest\Form\TestAsset\Annotation\Entity")
*/
public $childTheFourth;
}

0 comments on commit 7fbb074

Please sign in to comment.