Datatypes\Mixed\Editor::save PHP Method

save() public method

Save mixed editor
public save ( ) : void
return void
    public function save()
    {
        $config = $this->getConfig();
        $datatypesConfig = empty($config['datatypes']) ? array() : $config['datatypes'];
        $post = $this->getRequest()->getPost();
        $oldPost = $post->toArray();
        $datatypes = $post->get($this->getName());
        $oldFiles = $_FILES;
        if (!empty($datatypes) and is_array($datatypes)) {
            foreach ($datatypes as $lineId => $values) {
                $datatypes[$lineId] = array();
                foreach ($values as $datatypeId => $datatype) {
                    if (!empty($oldFiles[$this->getName()]['name'][$lineId][$datatypeId])) {
                        $name = array_keys($oldFiles[$this->getName()]['name'][$lineId][$datatypeId]);
                        if (!empty($name[0])) {
                            $data = array('name' => $oldFiles[$this->getName()]['name'][$lineId][$datatypeId][$name[0]], 'type' => $oldFiles[$this->getName()]['type'][$lineId][$datatypeId][$name[0]], 'tmp_name' => $oldFiles[$this->getName()]['tmp_name'][$lineId][$datatypeId][$name[0]], 'error' => $oldFiles[$this->getName()]['error'][$lineId][$datatypeId][$name[0]], 'error' => $oldFiles[$this->getName()]['error'][$lineId][$datatypeId][$name[0]]);
                            $_FILES[$name[0]] = $data;
                            unset($_FILES[$this->getName()]);
                        }
                    }
                    foreach ($datatype as $name => $value) {
                        $post->set($name, $value);
                    }
                    //Get datatypes
                    $datatypeConfig = $datatypesConfig[$datatypeId];
                    $object = $this->loadDatatype($datatypeConfig['name']);
                    $editor = $object->getEditor($this->getProperty());
                    if (!empty($datatypeConfig['config'])) {
                        $editor->setConfig(serialize($datatypeConfig['config']));
                    }
                    $editor->save();
                    $datatypes[$lineId][$datatypeId] = array('value' => $editor->getValue());
                    foreach ($oldPost as $key => $value) {
                        $post->set($key, $value);
                    }
                    $_FILES = $oldFiles;
                }
            }
        }
        $this->setValue(serialize($datatypes));
    }

Usage Example

Beispiel #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testSave()
 {
     $post = $this->object->getRequest()->getPost();
     $post->set($this->object->getName(), array(array(array('textstring51' => 'test1')), array(array('textstring51' => 'test2'))));
     $_FILES = array($this->object->getName() => array('name' => array(array(array('textstring51' => array(__DIR__ . '/test')))), 'type' => array(array(array('textstring51' => array('plain/text')))), 'size' => array(array(array('textstring51' => array(8)))), 'tmp_name' => array(array(array('textstring51' => array(__DIR__ . '/test')))), 'error' => array(array(array('textstring51' => array(0))))));
     $this->object->save();
     $this->assertEquals('a:2:{i:0;a:1:{i:0;a:1:{s:5:"value";N;}}i:1;a:1:{i:0;a:1:{s:5:"value";N;}}}', $this->object->getValue());
 }