|
@@ -27,6 +27,8 @@ class FormMapper
|
|
|
|
|
|
protected $admin;
|
|
|
|
|
|
+ protected $currentGroup;
|
|
|
+
|
|
|
public function __construct(FormContractorInterface $formContractor, FormBuilder $formBuilder, AdminInterface $admin)
|
|
|
{
|
|
|
$this->formBuilder = $formBuilder;
|
|
@@ -34,6 +36,35 @@ class FormMapper
|
|
|
$this->admin = $admin;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param $name
|
|
|
+ * @param array $options
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function with($name, array $options = array())
|
|
|
+ {
|
|
|
+ $formGroups = $this->admin->getFormGroups();
|
|
|
+ if (!isset($formGroups[$name])) {
|
|
|
+ $formGroups[$name] = array_merge(array('collapsed' => false, 'fields' => array()), $options);
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->admin->setFormGroups($formGroups);
|
|
|
+
|
|
|
+ $this->currentGroup = $name;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function end()
|
|
|
+ {
|
|
|
+ $this->currentGroup = null;
|
|
|
+
|
|
|
+ return $this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @param string $name
|
|
|
* @param string $type
|
|
@@ -43,6 +74,14 @@ class FormMapper
|
|
|
*/
|
|
|
public function add($name, $type = null, array $options = array(), array $fieldDescriptionOptions = array())
|
|
|
{
|
|
|
+ if (!$this->currentGroup) {
|
|
|
+ $this->with($this->admin->getLabel());
|
|
|
+ }
|
|
|
+
|
|
|
+ $formGroups = $this->admin->getFormGroups();
|
|
|
+ $formGroups[$this->currentGroup]['fields'][$name] = $name;
|
|
|
+ $this->admin->setFormGroups($formGroups);
|
|
|
+
|
|
|
if (!isset($fieldDescriptionOptions['type']) && is_string($type)) {
|
|
|
$fieldDescriptionOptions['type'] = $type;
|
|
|
}
|