public function saveInto(DataObjectInterface $record) { $schemas = $record->getSchemas(); $value = $this->Value(); $metadata = array(); foreach ($schemas as $schema) { $metadata[$schema->Name] = array(); $fields = $schema->getFormFields(); $namesMap = array(); foreach ($fields as $field) { $brPos = strrpos($field->getName(), '['); $name = substr($field->getName(), $brPos + 1, -1); $namesMap[$field->getName()] = $name; } if (isset($value[$schema->Name])) { foreach ($fields as $field) { $fName = $field->getName(); $sName = $namesMap[$fName]; if (array_key_exists($sName, $value[$schema->Name])) { $field->setValue($value[$schema->Name][$sName], $value[$schema->Name]); } else { $field->setValue(null); } } } foreach ($fields as $field) { $name = $namesMap[$field->getName()]; $schemaField = $schema->Fields()->find('Name', $name); $toSave = $schemaField->processBeforeWrite($field->dataValue(), $record); $metadata[$schema->Name][$name] = $toSave; } } $record->{$this->name} = serialize($metadata); }