public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($options['form'])) {
         $this->setForm($options['form']);
     }
 }
Exemplo n.º 2
0
 /**
  * Set options for a fieldset. Accepted options are:
  * - use_as_base_fieldset: is this fieldset use as the base fieldset?
  *
  * @param  array|Traversable $options
  * @return Element|ElementInterface
  * @throws Exception\InvalidArgumentException
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($options['use_as_base_fieldset'])) {
         $this->setUseAsBaseFieldset($options['use_as_base_fieldset']);
     }
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Accepted options for DateTime:
  * - format: A \DateTime compatible string
  *
  * @param array|\Traversable $options
  * @return DateTime
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($this->options['format'])) {
         $this->setFormat($this->options['format']);
     }
     return $this;
 }
Exemplo n.º 4
0
 /**
  * Accepted options for Captcha:
  * - captcha: a valid Zend\Captcha\AdapterInterface
  *
  * @param array|Traversable $options
  * @return Captcha
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($this->options['captcha'])) {
         $this->setCaptcha($this->options['captcha']);
     }
     return $this;
 }
Exemplo n.º 5
0
 /**
  * Accepted options for Csrf:
  * - csrf_options: an array used in the Csrf
  *
  * @param array|\Traversable $options
  * @return Csrf
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($options['csrf_options'])) {
         $this->setCsrfValidatorOptions($options['csrf_options']);
     }
     return $this;
 }
Exemplo n.º 6
0
 /**
  * @param Element $element
  */
 public function addElement($element)
 {
     $options = $element->getOptions();
     $options['displayGroup'] = $this->getName();
     $element->setOptions($options);
     $this->elements[$element->getName()] = $element;
     return $this;
 }
Exemplo n.º 7
0
 public function testCanCreateLabelValueAfterInput()
 {
     $element = new Element('foo');
     $element->setOptions(array('label' => 'The value for foo:'));
     $this->helper->setLabelPosition('append');
     $markup = $this->helper->render($element);
     $this->assertContains('<label><input', $markup);
     $this->assertContains('</label>', $markup);
 }
Exemplo n.º 8
0
 /**
  * Set options for a fieldset. Accepted options are:
  * - use_as_base_fieldset: is this fieldset use as the base fieldset?
  *
  * @param  array|Traversable $options
  * @return Element|ElementInterface
  * @throws Exception\InvalidArgumentException
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($options['use_as_base_fieldset'])) {
         $this->setUseAsBaseFieldset($options['use_as_base_fieldset']);
     }
     if (isset($options['allowed_object_binding_class'])) {
         $this->setAllowedObjectBindingClass($options['allowed_object_binding_class']);
     }
     return $this;
 }
Exemplo n.º 9
0
 /**
  * Set options for an element. Accepted options are:
  * - label: label to associate with the element
  * - label_attributes: attributes to use when the label is rendered
  * - value_options: list of values and labels for the select options
  *
  * @param  array|\Traversable $options
  * @return Select|ElementInterface
  * @throws Exception\InvalidArgumentException
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($this->options['value_options'])) {
         $this->setValueOptions($this->options['value_options']);
     }
     // Alias for 'value_options'
     if (isset($this->options['options'])) {
         $this->setValueOptions($this->options['options']);
     }
     return $this;
 }
Exemplo n.º 10
0
 /**
  * reCAPTCHA options
  * - site_key: Public key (html)
  * - secret_key: Private key
  * - remote_ip: Check IP
  *
  * @param  array|\Traversable $options
  * @return self
  * @throws Exception\InvalidArgumentException
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (empty($options['site_key']) || empty($options['secret_key'])) {
         throw new Exception\InvalidArgumentException('The options site_key and/or secret_key were not found');
     }
     $this->setSiteKey($options['site_key']);
     $this->setSecretKey($options['secret_key']);
     if (isset($options['remote_ip'])) {
         $this->setRemoteIp($options['remote_ip']);
     }
     return $this;
 }
Exemplo n.º 11
0
 /**
  * Accepted options for MultiCheckbox:
  * - use_hidden_element: do we render hidden element?
  * - unchecked_value: value for checkbox when unchecked
  * - checked_value: value for checkbox when checked
  *
  * @param  array|\Traversable $options
  * @return Checkbox
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($options['use_hidden_element'])) {
         $this->setUseHiddenElement($options['use_hidden_element']);
     }
     if (isset($options['unchecked_value'])) {
         $this->setUncheckedValue($options['unchecked_value']);
     }
     if (isset($options['checked_value'])) {
         $this->setCheckedValue($options['checked_value']);
     }
     return $this;
 }
Exemplo n.º 12
0
 /**
  * Accepted options for DoctrineEntity:
  * - object_manager: a valid Doctrine 2 ObjectManager
  * - target_class: a FQCN of the target entity
  * - property: the property of the entity to use as the label in the options
  * - spec: a closure, QueryBuilder or Query
  *
  * @param  array|\Traversable $options
  * @return DoctrineEntity
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($options['object_manager'])) {
         $this->setObjectManager($options['object_manager']);
     }
     if (isset($options['target_class'])) {
         $this->setTargetClass($options['target_class']);
     }
     if (isset($options['property'])) {
         $this->setProperty($options['property']);
     }
     if (isset($options['spec'])) {
         $this->setSpec($options['spec']);
     }
     return $this;
 }
Exemplo n.º 13
0
 /**
  * Set options for an element. Accepted options are:
  * - label: label to associate with the element
  * - label_attributes: attributes to use when the label is rendered
  * - value_options: list of values and labels for the select options
  * _ empty_option: should an empty option be prepended to the options ?
  *
  * @param  array|Traversable $options
  * @return Select|ElementInterface
  * @throws InvalidArgumentException
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($this->options['value_options'])) {
         $this->setValueOptions($this->options['value_options']);
     }
     // Alias for 'value_options'
     if (isset($this->options['options'])) {
         $this->setValueOptions($this->options['options']);
     }
     if (isset($this->options['empty_option'])) {
         $this->setEmptyOption($this->options['empty_option']);
     }
     if (isset($this->options['disable_inarray_validator'])) {
         $this->setDisableInArrayValidator($this->options['disable_inarray_validator']);
     }
     return $this;
 }
Exemplo n.º 14
0
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($options['startdate'])) {
         if (isset($options['startdate']['options'])) {
             $this->getStartDateElement()->setOptions($options['startdate']['options']);
         }
         if (isset($options['startdate']['attributes'])) {
             $this->getStartDateElement()->setAttributes($options['startdate']['attributes']);
         }
     }
     if (isset($options['enddate'])) {
         if (isset($options['enddate']['options'])) {
             $this->getEndDateElement()->setOptions($options['enddate']['options']);
         }
         if (isset($options['enddate']['attributes'])) {
             $this->getEndDateElement()->setAttributes($options['enddate']['attributes']);
         }
     }
 }
Exemplo n.º 15
0
 public function getForm($article, $entityManager, $myEntity, $action)
 {
     $builder = new DoctrineAnnotationBuilder($entityManager);
     $form = $builder->createForm($article);
     //!!!!!! Start !!!!! Added to make the association tables work with select
     foreach ($form->getElements() as $element) {
         if (method_exists($element, 'getProxy')) {
             $proxy = $element->getProxy();
             if (method_exists($proxy, 'setObjectManager')) {
                 $proxy->setObjectManager($entityManager);
             }
         }
     }
     $form->setHydrator(new DoctrineHydrator($entityManager, $myEntity));
     $oName = new Element('name');
     $oName->setAttributes(array('type' => 'text', 'maxlength' => 255));
     $oName->setOptions(array('label' => 'Название'));
     $form->add($oName, array('priority' => 1000));
     $oDescription = new Element('description');
     $oDescription->setAttributes(array('type' => 'text', 'maxlength' => 255));
     $oDescription->setOptions(array('label' => 'Описание'));
     $form->add($oDescription, array('priority' => 999));
     $send = new Element('send');
     $send->setValue($action);
     // submit
     $send->setAttributes(array('type' => 'submit'));
     $form->add($send);
     foreach ($form->getElements() as $element) {
         $element->setAttribute('id', $element->getName());
         $element->setAttribute('class', 'form-control');
         /*if ($element->getLabel() === null) {
               $element->setOptions(array('add-on-div' => array('class'  => 'col-sm-offset-2 col-sm-10'), ));
           } else {
               $element->setOptions(array( 'add-on-div' => array('class'  => 'col-sm-10'), 
                                       'label_attributes' => array('class'  => 'col-sm-2 control-label'),
                                 ));
           }*/
     }
     return $form;
 }
Exemplo n.º 16
0
 public function testSetOptionsIsTraversable()
 {
     $element = new Element('foo');
     $element->setOptions(new \ArrayObject(array('foo' => 'bar')));
     $this->assertEquals('foo', $element->getName());
     $this->assertEquals(array('foo' => 'bar'), $element->getOptions());
 }
Exemplo n.º 17
0
 public function testLabelOptionsCanBeSetViaOptionsArray()
 {
     $element = new Element('foo');
     $element->setOptions(array('label_options' => array('moar' => 'foo')));
     $this->assertEquals('foo', $element->getLabelOption('moar'));
 }
Exemplo n.º 18
0
 /**
  * @param bool $create
  * @return Form
  */
 public function buildForm($create = true)
 {
     $attributes = $this->getHeaders();
     $form = new Form();
     $filter = new InputFilter();
     $validators = array();
     foreach ($attributes as $key => $attribute) {
         $label = isset($attribute['title']) ? $attribute['title'] : ucwords($key);
         $type = isset($attribute['type']) ? $attribute['type'] : 'text';
         switch ($type) {
             case 'text':
                 $element = new Element\Text($key);
                 break;
             case 'int':
                 $element = new Element\Text($key);
                 $validators[] = 'Zend\\Validator\\Digits';
                 $type = 'text';
                 break;
             case 'float':
                 $element = new Element\Text($key);
                 $validators[] = 'Zend\\I18n\\Validator\\Float';
                 $type = 'text';
                 break;
             case 'password':
                 $element = new Element\Password($key);
                 break;
             case 'select':
                 $element = new Element\Select($key);
                 break;
             case 'radio':
                 $element = new Element\Radio($key);
                 break;
             case 'hidden':
                 $element = new Element\Hidden($key);
                 break;
             case 'checkbox':
                 $element = new Element\Checkbox($key);
                 break;
             case 'textarea':
                 $element = new Element\Textarea($key);
                 break;
             case 'wysiwyg':
                 $element = new Element\Textarea($key);
                 break;
             default:
                 $element = new Element($key);
         }
         if ($create === true) {
             if (isset($attribute['create']) && $attribute['create'] === false) {
                 continue;
             }
         } else {
             if (isset($attribute['update']) && $attribute['update'] === false) {
                 continue;
             }
         }
         $element->setLabel($label);
         $element->setAttributes(array('type' => $type));
         if (isset($attribute['options'])) {
             $element->setOptions(array('value_options' => $attribute['options']));
         }
         if (isset($attribute['required']) && $attribute['required'] === true) {
             $validators[] = 'Zend\\Validator\\NotEmpty';
         }
         if (!empty($validators)) {
             foreach ($validators as $validator) {
                 $input = new Input($key);
                 $input->getValidatorChain()->attach(new $validator());
                 $filter->add($input);
             }
         }
         $form->setInputFilter($filter);
         $form->add($element);
     }
     $element = new Element($key);
     $element->setAttributes(array('type' => 'button', 'value' => '<span class="glyphicon glyphicon-chevron-left"></span> Back', 'name' => 'btnBack'));
     $form->add($element);
     $element = new Element($key);
     $element->setAttributes(array('type' => 'submit', 'value' => 'Submit', 'name' => 'btnSubmit'));
     $form->add($element);
     $form->add(array('type' => 'Zend\\Form\\Element\\Csrf', 'name' => 'csrf'));
     return $form;
 }
Exemplo n.º 19
0
 /**
  * Set options for an element. Accepted options are:
  * - label: label to associate with the element
  * - label_attributes: attributes to use when the label is rendered
  * - value_options: list of values and labels for the select options
  * _ empty_option: should an empty option be prepended to the options ?
  *
  * @param  array|Traversable $options
  * @return Select|ElementInterface
  * @throws InvalidArgumentException
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($this->options['value_options'])) {
         $this->setValueOptions($this->options['value_options']);
     }
     // Alias for 'value_options'
     if (isset($this->options['options'])) {
         $this->setValueOptions($this->options['options']);
     }
     if (isset($this->options['empty_option'])) {
         $this->setEmptyOption($this->options['empty_option']);
     }
     if (isset($this->options['disable_inarray_validator'])) {
         $this->setDisableInArrayValidator($this->options['disable_inarray_validator']);
     }
     if (isset($options['use_hidden_element'])) {
         $this->setUseHiddenElement($options['use_hidden_element']);
     }
     if (isset($options['unselected_value'])) {
         $this->setUnselectedValue($options['unselected_value']);
     }
     return $this;
 }
Exemplo n.º 20
0
 public function testCanRetrieveSpecificOption()
 {
     $element = new Element('foo');
     $element->setOptions(array('custom' => 'option'));
     $option = $element->getOption('custom');
     $this->assertEquals('option', $option);
 }
Exemplo n.º 21
0
 /**
  * Accepted options for DateSelect:
  * - month_attributes: HTML attributes to be rendered with the month element
  * - year_attributes: HTML attributes to be rendered with the month element
  * - min_year: min year to use in the year select
  * - max_year: max year to use in the year select
  *
  * @param array|\Traversable $options
  * @return MonthSelect
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if (isset($options['month_attributes'])) {
         $this->setMonthAttributes($options['month_attributes']);
     }
     if (isset($options['year_attributes'])) {
         $this->setYearAttributes($options['year_attributes']);
     }
     if (isset($options['min_year'])) {
         $this->setMinYear($options['min_year']);
     }
     if (isset($options['max_year'])) {
         $this->setMaxYear($options['max_year']);
     }
     if (isset($options['create_empty_option'])) {
         $this->setShouldCreateEmptyOption($options['create_empty_option']);
     }
     if (isset($options['render_delimiters'])) {
         $this->setShouldRenderDelimiters($options['render_delimiters']);
     }
     return $this;
 }
Exemplo n.º 22
0
 public function testEnsureUseHiddenElementMethodExists()
 {
     $element = new Element();
     $element->setName('codeType');
     $element->setOptions(array('label' => 'Code Type'));
     $element->setAttributes(array('type' => 'radio', 'options' => array('Markdown' => 'markdown', 'HTML' => 'html', 'Wiki' => 'wiki'), 'value' => array('markdown')));
     $markup = $this->helper->render($element);
     $this->assertNotContains('type="hidden"', $markup);
     // Lack of error also indicates this test passes
 }
Exemplo n.º 23
0
 /**
  * Set element options.
  *
  * Accepted options for MonthSelect:
  *
  * - month_attributes: HTML attributes to be rendered with the month element
  * - year_attributes: HTML attributes to be rendered with the month element
  * - min_year: min year to use in the year select
  * - max_year: max year to use in the year select
  *
  * @param array|Traversable $options
  * @return self
  */
 public function setOptions($options)
 {
     parent::setOptions($options);
     if ($options instanceof Traversable) {
         $options = ArrayUtils::iteratorToArray($options);
     }
     if (isset($options['month_attributes'])) {
         $this->setMonthAttributes($options['month_attributes']);
     }
     if (isset($options['year_attributes'])) {
         $this->setYearAttributes($options['year_attributes']);
     }
     if (isset($options['min_year'])) {
         $this->setMinYear($options['min_year']);
     }
     if (isset($options['max_year'])) {
         $this->setMaxYear($options['max_year']);
     }
     if (isset($options['create_empty_option'])) {
         $this->setShouldCreateEmptyOption($options['create_empty_option']);
     }
     if (isset($options['render_delimiters'])) {
         $this->setShouldRenderDelimiters($options['render_delimiters']);
     }
     return $this;
 }