/**
  * @param ValueRenderEvent $fieldValueEvent
  */
 public function beforeValueRender(ValueRenderEvent $fieldValueEvent)
 {
     $originalValue = $fieldValueEvent->getOriginalValue();
     $metadata = $fieldValueEvent->getMetadata();
     if ($originalValue instanceof AddressInterface) {
         $fieldValueEvent->setConvertedValue($this->addressFormatter->format($originalValue));
     } elseif ($originalValue instanceof NamePrefixInterface || $originalValue instanceof FirstNameInterface || $originalValue instanceof MiddleNameInterface || $originalValue instanceof LastNameInterface || $originalValue instanceof NameSuffixInterface) {
         $fieldValueEvent->setConvertedValue($this->nameFormatter->format($originalValue));
     } elseif ($originalValue instanceof \DateTime) {
         $dateType = $metadata->get('render_date_type');
         $timeType = $metadata->get('render_time_type');
         $dateTimePattern = $metadata->get('render_datetime_pattern');
         $fieldValueEvent->setConvertedValue($this->dateTimeFormatter->format($originalValue, $dateType, $timeType, null, null, $dateTimePattern));
     } elseif (is_numeric($originalValue)) {
         $numberStyle = $metadata->get('render_number_style');
         if (!$numberStyle) {
             $numberStyle = 'default_style';
         }
         $fieldValueEvent->setConvertedValue($this->numberFormatter->format($originalValue, $numberStyle));
     }
 }
Exemplo n.º 2
0
 public function testSetConvertedValueShouldChangeConvertedValue()
 {
     $newConvertedValue = date('Y');
     $this->target->setConvertedValue($newConvertedValue);
     $this->assertEquals($this->target->getConvertedValue(), $newConvertedValue);
 }