Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[hotfix/ZF-11831] Zend_Form #517

Closed
wants to merge 2 commits into from

2 participants

Adam Lundrigan Matthew Weier O'Phinney
Adam Lundrigan

Form's default translator incorrectly passed to subforms, causing override of subform elements' default translators

adamlundrigan added some commits
Adam Lundrigan adamlundrigan [hotfix/ZF-11831] Zend_Form
Form's default translator incorrectly passed to subforms, causing override of subform elements' default translators
2558573
Adam Lundrigan adamlundrigan [hotfix/ZF-11831] Use short class names instead of full canonical nam…
…es where appropriate
3eb340a
Matthew Weier O'Phinney

Reviewed, merged, and pushed to master - thanks!b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 21, 2011
  1. Adam Lundrigan

    [hotfix/ZF-11831] Zend_Form

    adamlundrigan authored
    Form's default translator incorrectly passed to subforms, causing override of subform elements' default translators
  2. Adam Lundrigan
This page is out of date. Refresh to see the latest.
Showing with 59 additions and 1 deletion.
  1. +2 −1  library/Zend/Form/Form.php
  2. +57 −0 tests/Zend/Form/FormTest.php
3  library/Zend/Form/Form.php
View
@@ -2248,7 +2248,8 @@ public function isValid($data)
}
}
foreach ($this->getSubForms() as $key => $form) {
- if (null !== $translator && !$form->hasTranslator()) {
+ if (null !== $translator && $this->hasTranslator()
+ && !$form->hasTranslator()) {
$form->setTranslator($translator);
}
if (isset($data[$key]) && !$form->isArray()) {
57 tests/Zend/Form/FormTest.php
View
@@ -4237,4 +4237,61 @@ public function testAddDecoratorsKeepsNonNumericKeyNames()
$t2 = $this->form->getDecorators();
$this->assertEquals($t1, $t2);
}
+
+ /**
+ * @group ZF-11831
+ */
+ public function testElementsOfSubFormReceiveCorrectDefaultTranslator()
+ {
+ $isEmptyKey = \Zend\Validator\NotEmpty::IS_EMPTY;
+
+ // Global default translator
+ $trDefault = new Translator(array(
+ 'adapter' => 'arrayAdapter',
+ 'content' => array(
+ $isEmptyKey => 'Default'
+ ),
+ 'locale' => 'en'
+ ));
+ Registry::set('Zend_Translate', $trDefault);
+
+ // Translator to use for elements
+ $trElement = new Translator(array(
+ 'adapter' => 'arrayAdapter',
+ 'content' => array(
+ $isEmptyKey =>'Element'
+ ),
+ 'locale' => 'en'
+ ));
+ \Zend\Validator\AbstractValidator::setDefaultTranslator($trElement);
+
+ // Change the form's translator
+ $form = new Form();
+ $form->addElement(new \Zend\Form\Element\Text('foo', array(
+ 'required' => true,
+ 'validators' => array('NotEmpty')
+ )));
+
+ // Create a subform with it's own validator
+ $sf1 = new SubForm();
+ $sf1->addElement(new \Zend\Form\Element\Text('foosub', array(
+ 'required' => true,
+ 'validators' => array('NotEmpty')
+ )));
+ $form->addSubForm($sf1, 'Test1');
+
+ $form->isValid(array());
+
+ $messages = $form->getMessages();
+ $this->assertEquals(
+ 'Element',
+ @$messages['foo'][$isEmptyKey],
+ 'Form element received wrong validator'
+ );
+ $this->assertEquals(
+ 'Element',
+ @$messages['Test1']['foosub'][$isEmptyKey],
+ 'SubForm element received wrong validator'
+ );
+ }
}
Something went wrong with that request. Please try again.