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));
}