Datatypes\Mixed\PrevalueEditor::load PHP Method

load() public method

Load mixed prevalue editor
public load ( ) : string
return string
    public function load()
    {
        $config = $this->getConfig();
        $listDir = $this->getDatatype()->getDatatypesList();
        $options = array();
        foreach ($listDir as $dir) {
            $options[$dir] = $dir;
        }
        $datatypes = empty($config['datatypes']) ? array() : $config['datatypes'];
        foreach ($datatypes as $datatypeId => $datatypeConfig) {
            //Get datatypes
            $object = $this->loadDatatype($datatypeConfig['name']);
            //Force configuration
            $object->getPrevalueEditor()->setConfig(empty($datatypeConfig['config']) ? null : serialize($datatypeConfig['config']));
            //Initiliaze prefix
            $prefix = 'datatypes[' . $datatypeId . ']';
            //Create form
            $fieldset = new Fieldset();
            $hidden = new Element\Hidden();
            $hidden->setName($prefix . '[name]');
            $hidden->setValue($datatypeConfig['name']);
            $fieldset->add($hidden);
            $label = new Element\Text();
            $label->setName($prefix . '[label]');
            $label->setAttribute('class', 'form-control');
            $label->setLabel('Label');
            $label->setAttribute('id', 'label' . $datatypeId);
            $label->setValue(empty($datatypeConfig['label']) ? '' : $datatypeConfig['label']);
            $fieldset->add($label);
            AbstractForm::addContent($fieldset, $object->getPrevalueEditor()->load(), $prefix);
            $datatypes[$datatypeId]['fieldset'] = $fieldset;
        }
        $data = array();
        $data['datatypes'] = $datatypes;
        $data['modelOptions'] = $options;
        return $this->addPath(__DIR__)->render('mixed-prevalue.phtml', $data);
    }

Usage Example

Example #1
0
 /**
  * Test
  *
  * @return void
  */
 public function testLoad()
 {
     $this->assertInternalType('string', $this->object->load());
 }