当前位置: 首页>>代码示例>>PHP>>正文


PHP Form::getViewData方法代码示例

本文整理汇总了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;
 }
开发者ID:theus77,项目名称:ElasticMS,代码行数:43,代码来源:DataService.php

示例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());
 }
开发者ID:LinkValue,项目名称:JsonFormExtension-dev,代码行数:8,代码来源:FormTypeJsonExtensionIntegrationTest.php

示例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());
 }
开发者ID:yceruto,项目名称:symfony,代码行数:9,代码来源:SimpleFormTest.php

示例4: assertForm

 private function assertForm(Form $form)
 {
     static::assertTrue($form->isSynchronized());
     static::assertSame((string) $this->time, $form->getViewData());
 }
开发者ID:Bukashk0zzz,项目名称:TimestampTypeBundle,代码行数:5,代码来源:TimestampTypeTest.php


注:本文中的Symfony\Component\Form\Form::getViewData方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。