Datatypes\Mixed\Editor::load PHP Method

load() public method

Load mixed editor
public load ( ) : string
return string
    public function load()
    {
        $config = $this->getConfig();
        $values = unserialize($this->getValue());
        $datatypes = empty($config['datatypes']) ? array() : $config['datatypes'];
        $datatypesElements = array();
        $lineId = 0;
        if (!empty($values)) {
            foreach ($values as $lineId => $datatypeValue) {
                foreach ($datatypeValue as $datatypeId => $value) {
                    if (empty($datatypes[$datatypeId])) {
                        continue;
                    }
                    $datatypeConfig = $datatypes[$datatypeId];
                    //Get datatypes
                    $object = $this->loadDatatype($datatypeConfig['name']);
                    $editor = $object->getEditor($this->getProperty());
                    if (empty($values[$lineId][$datatypeId])) {
                        $values[$lineId][$datatypeId] = array('value' => '');
                    }
                    $editor->setValue($values[$lineId][$datatypeId]['value']);
                    if (!empty($datatypeConfig['config'])) {
                        $editor->setConfig(serialize($datatypeConfig['config']));
                    }
                    //Initialize prefix
                    $prefix = $this->getName() . '[' . $lineId . '][' . $datatypeId . ']';
                    //Create form
                    $fieldset = new Fieldset($datatypeConfig['name'] . $datatypeId);
                    AbstractForm::addContent($fieldset, $editor->load(), $prefix);
                    $datatypesElements[$lineId][$datatypeId]['label'] = empty($datatypeConfig['label']) ? '' : $datatypeConfig['label'];
                    $datatypesElements[$lineId][$datatypeId]['fieldset'] = $fieldset;
                }
            }
        }
        //Defauts elements
        $template = array();
        foreach ($datatypes as $datatypeId => $datatypeConfig) {
            $datatypeConfig = $datatypes[$datatypeId];
            //Get datatypes
            $object = $this->loadDatatype($datatypeConfig['name']);
            $editor = $object->getEditor($this->getProperty());
            if (empty($values['#{line}'][$datatypeId])) {
                $values['#{line}'][$datatypeId] = array('value' => '');
            }
            $editor->setValue($values['#{line}'][$datatypeId]['value']);
            if (!empty($datatypeConfig['config'])) {
                $editor->setConfig(serialize($datatypeConfig['config']));
            }
            //Initialize prefix
            $prefix = $this->getName() . '[#{line}][' . $datatypeId . ']';
            //Create form
            $fieldset = new Fieldset($datatypeConfig['name'] . $datatypeId);
            $hidden = new Element\Hidden();
            $hidden->setName($prefix . '[name]');
            $hidden->setValue($datatypeConfig['name']);
            $fieldset->add($hidden);
            AbstractForm::addContent($fieldset, $editor->load(), $prefix, '#{line}');
            $template[$datatypeId]['label'] = empty($datatypeConfig['label']) ? '' : $datatypeConfig['label'];
            $template[$datatypeId]['fieldset'] = $fieldset;
        }
        $this->getHelper('HeadLink')->appendStylesheet('/backend/assets/datatypes/mixed/mixed.css');
        return $this->addPath(__DIR__)->render('mixed-editor.phtml', array('property' => $this->getProperty(), 'datatypes' => $datatypesElements, 'propertyName' => $this->getName(), 'templateElements' => $template));
    }

Usage Example

Beispiel #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testLoad()
 {
     $this->object->setValue('a:3:{i:0;a:1:{i:0;a:1:{s:5:"value";s:5:"test1";}}i:1;a:1:{i:0;a:0:{}}i:3;a:1:{i:25;a:0:{}}}');
     $this->assertInternalType('string', $this->object->load());
 }