本文整理汇总了PHP中Symfony\Component\Form\Form::getViewData方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getViewData方法的具体用法?PHP Form::getViewData怎么用?PHP Form::getViewData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\Form
的用法示例。
在下文中一共展示了Form::getViewData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isValid
public function isValid(\Symfony\Component\Form\Form &$form)
{
$viewData = $form->getViewData();
//pour le champ hidden allFieldsAreThere de Revision
if (!is_object($viewData) && 'allFieldsAreThere' == $form->getName()) {
return true;
}
if ($viewData instanceof Revision) {
/** @var DataField $dataField */
$dataField = $viewData->getDatafield();
} elseif ($viewData instanceof DataField) {
/** @var DataField $dataField */
$dataField = $viewData;
} else {
throw new \Exception("Unforeseen type of viewData");
}
if ($dataField->getFieldType() !== null && $dataField->getFieldType()->getType() !== null) {
$dataFieldTypeClassName = $dataField->getFieldType()->getType();
/** @var DataFieldType $dataFieldType */
$dataFieldType = new $dataFieldTypeClassName();
}
$isValid = true;
if (isset($dataFieldType) && $dataFieldType->isContainer()) {
//If datafield is container or type is null => Container => Recursive
$formChildren = $form->all();
foreach ($formChildren as $child) {
if ($child instanceof \Symfony\Component\Form\Form) {
$tempIsValid = $this->isValid($child);
//Recursive
$isValid = $isValid && $tempIsValid;
}
}
if (!$isValid) {
$form->addError(new FormError("At least one child is not valid!"));
}
}
// $isValid = $isValid && $dataFieldType->isValid($dataField);
if (isset($dataFieldType) && !$dataFieldType->isValid($dataField)) {
$isValid = false;
$form->addError(new FormError("This Field is not valid! " . $dataField->getMessages()[0]));
}
return $isValid;
}
示例2: testRequestWithValidJsonShouldPopulateForm
public function testRequestWithValidJsonShouldPopulateForm()
{
$request = $this->getRequest('{ "name": "test1" }');
$this->form->handleRequest($request);
$this->assertEquals(['name' => 'test1', 'lastname' => null], $this->form->getData());
$this->assertEquals(['name' => 'test1', 'lastname' => null], $this->form->getNormData());
$this->assertEquals(['name' => 'test1', 'lastname' => null], $this->form->getViewData());
}
示例3: testViewDataMayBeArrayAccessIfDataClassIsNull
public function testViewDataMayBeArrayAccessIfDataClassIsNull()
{
$arrayAccess = $this->getMock('\\ArrayAccess');
$config = new FormConfigBuilder('name', null, $this->dispatcher);
$config->addViewTransformer(new FixedDataTransformer(array('' => '', 'foo' => $arrayAccess)));
$form = new Form($config);
$form->setData('foo');
$this->assertSame($arrayAccess, $form->getViewData());
}
示例4: assertForm
private function assertForm(Form $form)
{
static::assertTrue($form->isSynchronized());
static::assertSame((string) $this->time, $form->getViewData());
}