Datatypes\ImageCropper\PrevalueEditor::load PHP Method

load() public method

Load Image cropper prevalue editor
public load ( ) : string
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)));
    }

Usage Example

Beispiel #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testLoad()
 {
     $this->object->setConfig(array('background' => '#FFFFFF', 'resize_option' => 'auto', 'mime_list' => array('image/gif', 'image/jpeg', 'image/png'), 'size' => array(array('name' => '223x112', 'width' => '223', 'height' => '112'), array('name' => '600x300', 'width' => '600', 'height' => '300'))));
     $this->assertInternalType('string', $this->object->load());
 }
PrevalueEditor