Skip to content

Commit 8245a15

Browse files
committed
fix deep embedded form name
1 parent c094d5d commit 8245a15

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

AbstractEmbeddedBehavior.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,14 @@ protected function checkName($name)
131131
return $this->getFakeAttribute() == $name;
132132
}
133133

134-
protected function createEmbedded($attributes, $safeOnly = true)
134+
protected function createEmbedded($attributes, $safeOnly = true, $config = [])
135135
{
136136
if (is_array($this->embedded)) {
137137
$embeddedConfig = $this->embedded;
138138
} else {
139139
$embeddedConfig = ['class' => $this->embedded];
140140
}
141+
$embeddedConfig = array_merge($embeddedConfig, $config);
141142
/** @var EmbeddedDocument $model */
142143
$model = \Yii::createObject($embeddedConfig);
143144
$model->scenario = $this->owner->scenario;

EmbedsManyBehavior.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ protected function setAttributes(array $attributes, $safeOnly = true)
2222
{
2323
$this->storage->removeAll();
2424
foreach($attributes as $modelAttributes) {
25-
$model = $this->createEmbedded($modelAttributes, $safeOnly);
26-
$model->setFormName($this->getFormName($this->storage->getNextIndex()));
25+
$model = $this->createEmbedded(
26+
$modelAttributes,
27+
$safeOnly,
28+
['formName' => $this->getFormName($this->storage->getNextIndex())]
29+
);
2730
$this->storage[] = $model;
2831
}
2932
}
@@ -42,8 +45,11 @@ public function getStorage()
4245
}
4346

4447
foreach ($attributes as $modelAttributes) {
45-
$model = $this->createEmbedded($modelAttributes, false);
46-
$model->setFormName($this->getFormName($this->_storage->getNextIndex()));
48+
$model = $this->createEmbedded(
49+
$modelAttributes,
50+
false,
51+
['formName' => $this->getFormName($this->storage->getNextIndex())]
52+
);
4753
$this->_storage[] = $model;
4854
}
4955
}

EmbedsOneBehavior.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,11 @@ protected function setAttributes(array $attributes, $safeOnly = true)
2323
public function getStorage()
2424
{
2525
if (empty($this->_storage)) {
26-
$this->_storage = $this->createEmbedded((array)$this->owner->{$this->attribute}, false);
27-
$this->_storage->formName = Html::getInputName($this->owner, $this->fakeAttribute);
26+
$this->_storage = $this->createEmbedded(
27+
(array)$this->owner->{$this->attribute},
28+
false,
29+
['formName' => Html::getInputName($this->owner, $this->fakeAttribute)]
30+
);
2831
}
2932
return $this->_storage;
3033
}

0 commit comments

Comments
 (0)