Symfony 4:CollectionType 的 "allow_delete" 选项的逻辑在哪里?
Symfony 4: Where is the logic of the CollectionType's "allow_delete" option?
所以,我正在尝试了解 Symfony 表单。我正在搜索 "allow_delete" 选项的核心代码以查看它在引擎盖下是如何工作的,但唯一可以找到它的地方是 CollectionType
class 而我找不到任何那里的逻辑。
文档 states:
If set to true, then if an existing item is not contained in the
submitted data, it will be correctly absent from the final array of
items.
它在代码的什么地方影响提交的数据?
您可以在第 91 行开始的 MergeCollectionListener.php
中找到函数:
// Remove deleted items before adding to free keys that are to be
// replaced
if ($this->allowDelete) {
foreach ($itemsToDelete as $key) {
unset($dataToMergeInto[$key]);
}
}
$dataToMergeInto
设置为 $dataToMergeInto = $event->getForm()->getNormData();
指的是在 FormInterface.php
:
中解释的函数
/**
* Returns the normalized data of the field.
*
* @return mixed When the field is not submitted, the default data is returned.
* When the field is submitted, the normalized submitted data is
* returned if the field is valid, null otherwise.
*/
public function getNormData();
所以,我正在尝试了解 Symfony 表单。我正在搜索 "allow_delete" 选项的核心代码以查看它在引擎盖下是如何工作的,但唯一可以找到它的地方是 CollectionType
class 而我找不到任何那里的逻辑。
文档 states:
If set to true, then if an existing item is not contained in the submitted data, it will be correctly absent from the final array of items.
它在代码的什么地方影响提交的数据?
您可以在第 91 行开始的 MergeCollectionListener.php
中找到函数:
// Remove deleted items before adding to free keys that are to be
// replaced
if ($this->allowDelete) {
foreach ($itemsToDelete as $key) {
unset($dataToMergeInto[$key]);
}
}
$dataToMergeInto
设置为 $dataToMergeInto = $event->getForm()->getNormData();
指的是在 FormInterface.php
:
/**
* Returns the normalized data of the field.
*
* @return mixed When the field is not submitted, the default data is returned.
* When the field is submitted, the normalized submitted data is
* returned if the field is valid, null otherwise.
*/
public function getNormData();