Esempio n. 1
0
 /**
  * Updates the field with default data.
  *
  * @param array $appData The data formatted as expected for the underlying object
  *
  * @return Form The current form
  */
 public function setData($appData)
 {
     $event = new DataEvent($this, $appData);
     $this->dispatcher->dispatch(FormEvents::PRE_SET_DATA, $event);
     // Hook to change content of the data
     $event = new FilterDataEvent($this, $appData);
     $this->dispatcher->dispatch(FormEvents::SET_DATA, $event);
     $appData = $event->getData();
     // Treat data as strings unless a value transformer exists
     if (!$this->clientTransformers && !$this->normTransformers && is_scalar($appData)) {
         $appData = (string) $appData;
     }
     // Synchronize representations - must not change the content!
     $normData = $this->appToNorm($appData);
     $clientData = $this->normToClient($normData);
     $this->appData = $appData;
     $this->normData = $normData;
     $this->clientData = $clientData;
     $this->synchronized = true;
     if ($this->dataMapper) {
         // Update child forms from the data
         $this->dataMapper->mapDataToForms($clientData, $this->children);
     }
     $event = new DataEvent($this, $appData);
     $this->dispatcher->dispatch(FormEvents::POST_SET_DATA, $event);
     return $this;
 }
 function it_uses_a_property_path_data_mapper_while_mapping_data_to_forms(DataMapperInterface $propertyPathDataMapper, FormInterface $form, OrderItemInterface $orderItem)
 {
     $propertyPathDataMapper->mapDataToForms($orderItem, [$form])->shouldBeCalled();
     $this->mapDataToForms($orderItem, [$form]);
 }
 /**
  * {@inheritdoc}
  */
 public function mapDataToForms($data, $forms)
 {
     $this->propertyPathDataMapper->mapDataToForms($data, $forms);
 }