Skip to content

Commit 19f8ff0

Browse files
committed
Merge branch 'master' of github.com:consultnn/yii2-mongodb-embedded
2 parents ed6ee28 + 800419e commit 19f8ff0

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

AbstractEmbeddedBehavior.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ abstract class AbstractEmbeddedBehavior extends Behavior
2727
*/
2828
public $embedded;
2929

30+
/**
31+
* If true, Embedded model formName look like this: Company['address']
32+
* @var bool
33+
*/
34+
public $setFormName = true;
35+
3036
/**
3137
* @var mixed
3238
*/

EmbeddedDocument.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ public function formName()
4747
*/
4848
public function setFormName($formName)
4949
{
50-
$this->_formName = $formName;
50+
if (!empty($formName)) {
51+
$this->_formName = $formName;
52+
}
5153
}
5254

5355
/**

EmbedsManyBehavior.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ class EmbedsManyBehavior extends AbstractEmbeddedBehavior
1515

1616
public function getFormName($index)
1717
{
18-
return Html::getInputName($this->owner, $this->fakeAttribute."[{$index}]");
18+
if ($this->setFormName) {
19+
return Html::getInputName($this->owner, $this->fakeAttribute."[{$index}]");
20+
} else {
21+
return null;
22+
}
1923
}
2024

2125
protected function setAttributes(array $attributes, $safeOnly = true)
@@ -48,7 +52,7 @@ public function getStorage()
4852
$model = $this->createEmbedded(
4953
$modelAttributes,
5054
false,
51-
['formName' => $this->getFormName($this->storage->getNextIndex())]
55+
['formName' => $this->getFormName($this->_storage->getNextIndex())]
5256
);
5357
$this->_storage[] = $model;
5458
}

EmbedsOneBehavior.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public function getStorage()
2626
$this->_storage = $this->createEmbedded(
2727
(array)$this->owner->{$this->attribute},
2828
false,
29-
['formName' => Html::getInputName($this->owner, $this->fakeAttribute)]
29+
['formName' => $this->setFormName ? Html::getInputName($this->owner, $this->fakeAttribute) : null]
3030
);
3131
}
3232
return $this->_storage;

0 commit comments

Comments
 (0)