Commit 5640444a authored by Sebastian Castro's avatar Sebastian Castro

Read and write private custom data

parent 5d4e0605
......@@ -47,7 +47,7 @@
{# VALUE #}
{% set inputValue = element.data[field.name] is defined ? element.data[field.name] : null %}
{% set inputValue = elementValue %}
{% if field.type == "title" %}{% set inputValue = element.name %}{% endif %}
{% if field.type == "email" %}{% set inputValue = element.email %}{% endif %}
......
......@@ -2,7 +2,7 @@
{% for field in config.getElementFormFields %}
{% if field.name is defined %}
{% set elementValue = element.data[field.name] is defined ? element.data[field.name] : null %}
{% set elementValue = element.data[field.name] is defined ? element.data[field.name] : element.privateData[field.name] is defined ? element.privateData[field.name] : null %}
{% endif %}
<div class="field-container field-{{field.type}}" id="field-{{ field.name|default('unknown-name') }}"
......
......@@ -31,7 +31,7 @@ class ElementFormService
$request = $request->request;
$this->updateOptionsValues($element, $request);
$this->updateCustomData($element, $request);
$this->updateCustomData($element, $request, $em);
$isMinorModif = $editMode ? $this->isMinorModification($element, $originalElement, $em) : false;
// calculate this before calling "updateOwner" because we want to check the old value of userOwnerEmail
......@@ -90,11 +90,25 @@ class ElementFormService
}
}
private function updateCustomData($element, $request)
private function updateCustomData($element, $request, $em)
{
$config = $em->getRepository('BiopenCoreBundle:Configuration')->findConfiguration();
$privateProp = $config->getApi()->getPublicApiPrivateProperties();
$data = $request->get('data');
$privateData = [];
foreach ($privateProp as $key => $prop) {
if (array_key_exists($prop, $data)) {
$privateData[$prop] = $data[$prop];
unset($data[$prop]);
}
}
if ($element->getData()) $data = array_merge($element->getData(), $data); // keeping also old data
$element->setData($data);
if ($element->getPrivateData()) $privateData = array_merge($element->getPrivateData(), $privateData); // keeping also old data
$element->setPrivateData($privateData);
}
private function updateWebsiteUrl($element)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment