|
@@ -70,11 +70,11 @@ class FormMapper extends BaseGroupedMapper
|
|
}
|
|
}
|
|
|
|
|
|
// "Dot" notation is not allowed as form name, but can be used as property path to access nested data.
|
|
// "Dot" notation is not allowed as form name, but can be used as property path to access nested data.
|
|
- if (!$name instanceof FormBuilderInterface && strpos($fieldName, '.') !== false && !isset($options['property_path'])) {
|
|
|
|
|
|
+ if (!$name instanceof FormBuilderInterface && !isset($options['property_path'])) {
|
|
$options['property_path'] = $fieldName;
|
|
$options['property_path'] = $fieldName;
|
|
|
|
|
|
- // fix the form name
|
|
|
|
- $fieldName = str_replace('.', '__', $fieldName);
|
|
|
|
|
|
+ // fix the form name
|
|
|
|
+ $fieldName = $this->sanitizeFieldName($fieldName);
|
|
}
|
|
}
|
|
|
|
|
|
// change `collection` to `sonata_type_native_collection` form type to
|
|
// change `collection` to `sonata_type_native_collection` form type to
|
|
@@ -153,6 +153,8 @@ class FormMapper extends BaseGroupedMapper
|
|
*/
|
|
*/
|
|
public function get($name)
|
|
public function get($name)
|
|
{
|
|
{
|
|
|
|
+ $name = $this->sanitizeFieldName($name);
|
|
|
|
+
|
|
return $this->formBuilder->get($name);
|
|
return $this->formBuilder->get($name);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -161,6 +163,8 @@ class FormMapper extends BaseGroupedMapper
|
|
*/
|
|
*/
|
|
public function has($key)
|
|
public function has($key)
|
|
{
|
|
{
|
|
|
|
+ $key = $this->sanitizeFieldName($key);
|
|
|
|
+
|
|
return $this->formBuilder->has($key);
|
|
return $this->formBuilder->has($key);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -177,6 +181,7 @@ class FormMapper extends BaseGroupedMapper
|
|
*/
|
|
*/
|
|
public function remove($key)
|
|
public function remove($key)
|
|
{
|
|
{
|
|
|
|
+ $key = $this->sanitizeFieldName($key);
|
|
$this->admin->removeFormFieldDescription($key);
|
|
$this->admin->removeFormFieldDescription($key);
|
|
$this->admin->removeFieldFromFormGroup($key);
|
|
$this->admin->removeFieldFromFormGroup($key);
|
|
$this->formBuilder->remove($key);
|
|
$this->formBuilder->remove($key);
|
|
@@ -274,6 +279,21 @@ class FormMapper extends BaseGroupedMapper
|
|
return $this;
|
|
return $this;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
+ * Symfony default form class sadly can't handle
|
|
|
|
+ * form element with dots in its name (when data
|
|
|
|
+ * get bound, the default dataMapper is a PropertyPathMapper).
|
|
|
|
+ * So use this trick to avoid any issue.
|
|
|
|
+ *
|
|
|
|
+ * @param string $fieldName
|
|
|
|
+ *
|
|
|
|
+ * @return string
|
|
|
|
+ */
|
|
|
|
+ protected function sanitizeFieldName($fieldName)
|
|
|
|
+ {
|
|
|
|
+ return str_replace(array('__', '.'), array('____', '__'), $fieldName);
|
|
|
|
+ }
|
|
|
|
+
|
|
/**
|
|
/**
|
|
* {@inheritdoc}
|
|
* {@inheritdoc}
|
|
*/
|
|
*/
|