Ejemplo n.º 1
0
 public function testCanHandleMultiCheckboxesCorrectly()
 {
     $options = array('This is the first label' => 'value1', 'This is the second label' => 'value2', 'This is the third label' => 'value3');
     $element = new Element\MultiCheckbox('foo');
     $element->setAttribute('type', 'multi_checkbox');
     $element->setAttribute('options', $options);
     $element->setLabel('This is a multi-checkbox');
     $markup = $this->helper->render($element);
     $this->assertContains("<fieldset>", $markup);
     $this->assertContains("<legend>", $markup);
     $this->assertContains("<label>", $markup);
 }
Ejemplo n.º 2
0
 /**
  * @dataProvider getMultiElements
  * @group multi
  */
 public function testRendersMultiElementsAsExpected($type, $inputType, $additionalMarkup)
 {
     $element = new Element\MultiCheckbox('foo');
     $element->setAttribute('type', $type);
     $element->setAttribute('options', array('value1' => 'option', 'value2' => 'label', 'value3' => 'last'));
     $element->setAttribute('value', 'value2');
     $markup = $this->helper->render($element);
     $this->assertEquals(3, substr_count($markup, '<' . $inputType), $markup);
     $this->assertContains($additionalMarkup, $markup);
     if ($type == 'select') {
         $this->assertRegexp('#value="value2"[^>]*?(selected="selected")#', $markup);
     }
 }
Ejemplo n.º 3
0
 /**
  * Load upload prevalue editor
  *
  * @return string
  */
 public function load()
 {
     $parameters = $this->getConfig();
     $elements = array();
     $optionsValues = !empty($parameters['options']) ? $parameters['options'] : array();
     $fieldset = new Fieldset('Available options');
     $element = new Element\MultiCheckbox('options');
     $element->setAttribute('selected', $optionsValues);
     $element->setAttribute('class', 'input-checkbox');
     $element->setValueOptions(array(array('value' => 'maxNumberOfFiles', 'label' => 'Is multiple', 'selected' => empty($optionsValues['maxNumberOfFiles']) ? false : true)));
     $fieldset->add($element);
     $elements[] = $fieldset;
     $element = new Element\MultiCheckbox('mime_list');
     $mimeList = array('image/gif', 'image/jpeg', 'image/png', 'image/tiff', 'image/svg+xml', 'text/css', 'text/csv', 'text/html', 'text/javascript', 'text/plain', 'text/xml', 'video/mpeg', 'video/mp4', 'video/quicktime', 'video/x-ms-wmv', 'video/x-msvideo', 'video/x-flv', 'audio/mpeg', 'audio/x-ms-wma', 'audio/vnd.rn-realaudio', 'audio/x-wav');
     $options = array();
     foreach ($mimeList as $mime) {
         $options[] = array('value' => $mime, 'label' => $mime, 'selected' => !in_array($mime, empty($parameters['mime_list']) ? array() : $parameters['mime_list']) ? false : true);
     }
     $element->setValueOptions($options);
     $element->setAttribute('class', 'input-checkbox');
     $fieldset = new Fieldset('Mime list');
     $fieldset->add($element);
     $elements[] = $fieldset;
     return $this->addPath(__DIR__)->render('upload-prevalue.phtml', array('elements' => $elements));
 }
Ejemplo n.º 4
0
 public function getElementWithOptionSpec()
 {
     $element = new MultiCheckboxElement('foo');
     $options = array('This is the first label' => 'value1', 'This is the second label' => array('value' => 'value2', 'label' => 'This is the second label (overridden)', 'disabled' => false, 'label_attributes' => array('class' => 'label-class'), 'attributes' => array('class' => 'input-class')), 'This is the third label' => 'value3');
     $element->setAttribute('options', $options);
     return $element;
 }
Ejemplo n.º 5
0
 /**
  * Load upload prevalue editor
  *
  * @return Element\Checkbox[]
  */
 public function load()
 {
     $config = $this->getConfig();
     $isMultiple = new Element\Checkbox('is_multiple');
     $isMultiple->setAttributes(array('value' => isset($config['is_multiple']) ? $config['is_multiple'] : '', 'class' => 'input-checkbox', 'id' => 'is_multiple'));
     $isMultiple->setOptions(array('label' => 'Is Multiple', 'label_attributes' => array('class' => 'required control-label col-lg-2')));
     $mimeList = new Element\MultiCheckbox('mime_list');
     $array = array('image/gif', 'image/jpeg', 'image/png', 'image/tiff', 'image/svg+xml', 'text/css', 'text/csv', 'text/html', 'text/javascript', 'text/plain', 'text/xml', 'video/mpeg', 'video/mp4', 'video/quicktime', 'video/x-ms-wmv', 'video/x-msvideo', 'video/x-flv', 'audio/mpeg', 'audio/x-ms-wma', 'audio/vnd.rn-realaudio', 'audio/x-wav');
     $options = array();
     foreach ($array as $mime) {
         $options[] = array('value' => $mime, 'label' => $mime, 'selected' => !in_array($mime, empty($config['mime_list']) ? array() : $config['mime_list']) ? false : true);
     }
     $mimeList->setAttribute('class', 'input-checkbox');
     $mimeList->setValueOptions($options);
     return array($isMultiple, $this->addPath(__DIR__)->render('upload-prevalue.phtml', array('mimeList' => $mimeList)));
 }
Ejemplo n.º 6
0
 /**
  * Load Image cropper prevalue editor
  *
  * @return string
  */
 public function load()
 {
     $config = $this->getConfig();
     $resizeOption = new Element\Select('resize_option');
     $resizeOption->setValue(empty($config['resize_option']) ? 'auto' : $config['resize_option'])->setAttribute('class', 'form-control')->setAttribute('id', 'resize-option')->setLabel('Resize option')->setLabelAttributes(array('class' => 'col-lg-2'))->setValueOptions(array('auto' => 'auto', 'crop' => 'crop'));
     $backgroundOption = new Element\Text('background');
     $backgroundOption->setValue(empty($config['background']) ? '' : $config['background'])->setAttribute('class', 'form-control')->setAttribute('id', 'background')->setLabel('Background color')->setLabelAttributes(array('class' => 'col-lg-2'));
     $mimeList = new Element\MultiCheckbox('mime_list');
     $mimeList->setAttribute('class', 'input-checkbox')->setLabel('Mime list')->setLabelAttributes(array('class' => 'col-lg-2'));
     $array = array('image/gif', 'image/jpeg', 'image/png');
     $options = array();
     foreach ($array as $mime) {
         $options[] = array('value' => $mime, 'label' => $mime, 'selected' => !in_array($mime, empty($config['mime_list']) ? array() : $config['mime_list']) ? false : true);
     }
     $mimeList->setValueOptions($options);
     $sizeElements = array();
     $idx = 0;
     if (!empty($config['size'])) {
         foreach ($config['size'] as $idx => $size) {
             $elementSizeName = new Element\Text('size[' . $idx . '][name]');
             $elementSizeName->setValue($size['name'])->setAttribute('class', 'form-control')->setAttribute('id', 'name' . $idx)->setLabel('Name');
             $elementWidth = new Element\Text('size[' . $idx . '][width]');
             $elementWidth->setValue($size['width'])->setAttribute('class', 'form-control')->setAttribute('id', 'width' . $idx)->setLabel('Width');
             $elementHeight = new Element\Text('size[' . $idx . '][height]');
             $elementHeight->setValue($size['height'])->setAttribute('class', 'form-control')->setAttribute('id', 'height' . $idx)->setLabel('Height');
             $sizeElements[] = array($elementSizeName, $elementWidth, $elementHeight);
         }
         $idx++;
     }
     $elementSizeName = new Element\Text('size[#{idx}][name]');
     $elementSizeName->setAttribute('id', 'name#{idx}')->setAttribute('class', 'form-control')->setLabel('Name');
     $elementWidth = new Element\Text('size[#{idx}][width]');
     $elementWidth->setLabel('Width')->setAttribute('class', 'form-control')->setAttribute('id', 'width#{idx}');
     $elementHeight = new Element\Text('size[#{idx}][height]');
     $elementHeight->setLabel('Height')->setAttribute('class', 'form-control')->setAttribute('id', 'height#{idx}');
     $template = array($elementSizeName, $elementWidth, $elementHeight);
     return $this->addPath(__DIR__)->render('upload-prevalue.phtml', array('elements' => array('resize-option' => $resizeOption, 'background' => $backgroundOption, 'mime' => $mimeList, 'size' => $sizeElements, 'size-template' => $template)));
 }
Ejemplo n.º 7
0
 public function testGetSelectedAttributeForGroupReturnTrue()
 {
     $element = new MultiCheckboxElement('foo');
     $element->setAttribute('selected', 'true');
     $element->setValueOptions(array(array('label' => 'label1', 'value' => 'value1')));
     $markup = $this->helper->render($element);
     $this->assertRegexp('#value="value1" checked="checked"#', $markup);
 }
Ejemplo n.º 8
0
 /**
  * Initialize infos sub form
  *
  * @return \Zend\Form\FieldSet
  */
 protected function getInfos()
 {
     $fieldsets = $this->getFieldSets();
     if (!empty($fieldsets['infos'])) {
         return $fieldsets['infos'];
     }
     $fieldsets = new FieldSet('infos');
     $this->getInputFilter()->add(array('type' => 'Zend\\InputFilter\\InputFilter', 'name' => array('name' => 'name', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'db\\no_record_exists', 'options' => array('table' => 'document_type', 'field' => 'name', 'adapter' => $this->getAdapter())))), 'description' => array('name' => 'description', 'required' => false, 'allow_empty' => true), 'icon_id' => array('name' => 'icon_id', 'required' => true, 'allow_empty' => false), 'dependency' => array('name' => 'dependency', 'required' => false, 'allow_empty' => true)), 'infos');
     $fieldsets->add(new Element\Text('name'));
     $fieldsets->add(new Element\Text('description'));
     $iconId = new Element\Select('icon_id');
     $collection = new Icon\Collection();
     $iconId->setValueOptions($collection->getIcons())->setAttribute('class', 'form-control');
     $fieldsets->add($iconId);
     $documentTypeCollection = new DocumentTypeCollection();
     $select = $documentTypeCollection->getSelect();
     if (!empty($select)) {
         $dependency = new Element\MultiCheckbox('infos[dependency]');
         $dependency->setAttribute('class', 'input-checkbox');
         $dependency->setValueOptions($documentTypeCollection->getSelect());
         $fieldsets->add($dependency);
     }
     $this->add($fieldsets);
     return $fieldsets;
 }