Datatypes\ImageCropper\Editor::load PHP Method

load() public method

Load Image cropper editor
public load ( ) : mixed
return mixed
    public function load()
    {
        $parameters = $this->getConfig();
        $property = $this->getProperty();
        $upload = new Element\File($this->getName());
        $upload->setAttribute('class', 'form-control');
        $upload->setAttribute('required', $property->isRequired());
        $upload->setLabel($property->getName());
        $hiddenUpload = new Element\Hidden($this->getName() . '-hidden');
        $value = $this->getValue();
        if (!empty($value)) {
            $hiddenUpload->setValue($value);
            $value = unserialize($value);
            if (is_array($value)) {
                foreach ($value as $name => $file) {
                    if ($name == 'original') {
                        continue;
                    }
                    $found = false;
                    foreach ($parameters['size'] as $size) {
                        if ($size['name'] == $name) {
                            $found = true;
                            $file['options'] = $size;
                            break;
                        }
                    }
                    if (empty($found)) {
                        unset($value[$name]);
                    }
                }
            }
        }
        $this->getHelper('HeadLink')->appendStylesheet('/backend/assets/datatypes/imagecropper/jquery.jcrop.min.css');
        $this->getHelper('HeadLink')->appendStylesheet('/backend/assets/datatypes/imagecropper/image-cropper.css');
        $this->getHelper('HeadScript')->appendFile('/backend/assets/datatypes/imagecropper/jquery.jcrop.min.js');
        return array($upload, $hiddenUpload, $this->addPath(__DIR__)->render('upload-editor.phtml', array('files' => $value, 'id' => $this->getName(), 'options' => $parameters, 'name' => $this->getName())));
    }

Usage Example

Beispiel #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testLoad()
 {
     $data = serialize(array('original' => array('value' => '/media/files/test/test.jpg', 'width' => 10, 'height' => 10, 'html' => 2, 'mime' => 'image/jpeg'), '223x112' => array('value' => '/media/files/test/test-223x112.jpg', 'width' => 223, 'height' => 112, 'html' => 2, 'mime' => 'image/jpeg', 'x' => 0, 'y' => 0), '800x600' => array('value' => '/media/files/test/test.jpg', 'width' => 223, 'height' => 112, 'html' => 2, 'mime' => 'image/jpeg', 'x' => 0, 'y' => 0)));
     $this->object->setValue($data);
     $this->assertInternalType('array', $this->object->load());
 }