/**
  * Transforms the value if a value transformer is set.
  *
  * @param mixed                $value
  * @param FieldConfigInterface $field
  *
  * @return string
  */
 protected function normToView($value, FieldConfigInterface $field) : string
 {
     // Scalar values should be converted to strings to
     // facilitate differentiation between empty ("") and zero (0).
     if (null === $value || !$field->getViewTransformers()) {
         if (null !== $value && !is_scalar($value)) {
             throw new \RuntimeException(sprintf('Norm value of type %s is not a scalar value or null and not cannot be ' . 'converted to a string. You must set a viewTransformer for field "%s" with type "%s".', gettype($value), $field->getName(), $field->getType()->getName()));
         }
         return (string) $value;
     }
     foreach ($field->getViewTransformers() as $transformer) {
         $value = $transformer->transform($value);
     }
     return (string) $value;
 }
Beispiel #2
0
 /**
  * Checks if the given field accepts the given value-type.
  *
  * @param FieldConfigInterface $fieldConfig
  * @param string               $type
  *
  * @throws UnsupportedValueTypeException
  *
  * @deprecated
  */
 protected function assertAcceptsType(FieldConfigInterface $fieldConfig, $type)
 {
     if (!$fieldConfig->supportValueType($type)) {
         throw new UnsupportedValueTypeException($fieldConfig->getName(), $type);
     }
 }