Пример #1
0
 /**
  * @param string $messageKey     The unique message key for the translation system.
  * @param string $defaultMessage The default message in English, if no translator is available.
  *
  * @return void
  */
 private function addTranslatableError($messageKey, $defaultMessage)
 {
     $translator = $this->form->getTranslator();
     if ($translator) {
         $translatedMessage = $translator->translate($messageKey);
         if ($translatedMessage !== $messageKey) {
             $defaultMessage = $translatedMessage;
         }
     }
     $this->addError($defaultMessage);
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function render()
 {
     return $this->renderErrors($this->form) . $this->form->open() . $this->renderForm($this->form) . $this->form->close();
 }
Пример #3
0
 public function testCheckboxGroup()
 {
     // Setup some country codes, and whether they should be checked.
     $countries = ['US' => false, 'GB' => true, 'FR' => true];
     $form = new Form();
     $countryCheckboxes = $form->addCheckboxGroup('countries');
     foreach ($countries as $code => $checked) {
         $countryCheckboxes->addCheckbox()->setValue($code);
     }
     try {
         $form->populate(['countries' => 'US']);
         $this->fail('Should complain that CheckboxGroup does not accept a string');
     } catch (\InvalidArgumentException $e) {
         // Works as expected!
     }
     $this->assertTrue($form->populate(['countries' => array_keys($countries, true)])->isValid());
     foreach ($countryCheckboxes->getElements() as $checkbox) {
         $shouldBeChecked = $countries[$checkbox->getValue()];
         $this->assertEquals($checkbox->isChecked(), $shouldBeChecked);
     }
 }