setValue() public method

Sets control's value.
public setValue ( $value ) : self
return self
Exemplo n.º 1
0
 /**
  * @param object         $object
  * @param string         $fieldName
  * @param BaseControl    $control
  * @param IClassMetadata $classMetadata
  * @throws \NForms\Exceptions\UnexpectedTypeException
  * @return bool
  */
 public function load($object, $fieldName, BaseControl $control, IClassMetadata $classMetadata)
 {
     if ($classMetadata->hasAssociation($fieldName)) {
         if (($value = $classMetadata->getAssociationValue($object, $fieldName)) !== NULL) {
             if ($classMetadata->isSingleValuedAssociation($fieldName)) {
                 if (!is_object($value)) {
                     throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - form expected object, given " . gettype($value) . ".");
                 }
                 $relatedMetadata = $classMetadata->getRelatedMetadata($fieldName);
                 if (!is_a($value, $relatedMetadata->getClass())) {
                     throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - form expected NULL or '{$relatedMetadata->getClass()}' instance, given " . get_class($value) . ".");
                 }
                 $value = $relatedMetadata->getId($value);
             } else {
                 if (!is_array($value) && (!$value instanceof \ArrayAccess || !$value instanceof \Iterator)) {
                     throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - form expected array or ArrayAccess and Iterator instance, given " . get_class($value) . ".");
                 }
                 $relatedMetadata = $classMetadata->getRelatedMetadata($fieldName);
                 $value = array_map(function ($object) use($classMetadata, $fieldName, $relatedMetadata) {
                     if (!is_a($object, $relatedMetadata->getClass())) {
                         throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - form expected '{$relatedMetadata->getClass()}' instance in collection, given " . get_class($object) . ".");
                     }
                     return $relatedMetadata->getId($object);
                 }, $value);
             }
         }
     } else {
         $value = $classMetadata->getFieldValue($object, $fieldName);
     }
     $control->setValue($value);
     return TRUE;
 }
Exemplo n.º 2
0
 /**
  * @param $value
  * @return $this|bool|BaseControl
  */
 public function setValue($value)
 {
     parent::setValue($value);
     $this->item = NULL;
     if ($value instanceof IdentifiedEntity) {
         if (isset($this->items[$value->id])) {
             $this->item = $this->items[$value->id];
         }
     } else {
         if (isset($this->items[$this->value])) {
             $this->item = $this->items[$this->value];
         }
     }
     return $this;
 }
Exemplo n.º 3
0
 public function setValue($value)
 {
     if ($value instanceof \DoctrineModule\Entities\IEntity) {
         return parent::setValue($value->id);
     }
 }
Exemplo n.º 4
0
 public function loadHttpData()
 {
     $input = $this->getHttpData(\Nette\Forms\Form::DATA_TEXT);
     if (empty($input)) {
         parent::setValue(NULL);
         return;
     }
     $datetime = \DateTimeImmutable::createFromFormat($this->normalizeFormat($this->format), $this->normalizeFormat($input));
     if ($datetime !== FALSE && $datetime->format($this->normalizeFormat($this->format)) === $this->normalizeFormat($input)) {
         parent::setValue($datetime->format($this->format));
         return;
     }
     parent::setValue('');
 }
Exemplo n.º 5
0
 /**
  * Sets control's value.
  *
  * @return self
  */
 public function setValue($value)
 {
     if (!$value instanceof \DateTime) {
         $value = Nette\Utils\DateTime::from($value);
     }
     return parent::setValue($value);
 }