public function populate($value) : void
    {
        $isArray = $this->isArray();

        if ($value === null) {
            $value = $isArray ? [] : '';
        } else {
            $isCorrectType = $isArray ? is_array($value) : is_string($value);

            if (! $isCorrectType) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid value received for "%s": expected %s, got %s',
                    $this->getName(),
                    $isArray ? 'array' : 'string',
                    gettype($value)
                ));
            }
        }

        $this->resetErrors();

        $empty = ($value === '' || $value === []);

        if ($empty && $this->required) {
            $this->addTranslatableError('form.required', 'This field is required.');
        }

        if (! $empty && ! $isArray) {
            $value = $this->filter($value);
            $this->validate($value);
        }

        $this->doPopulate($value);
    }
public function populate($value) : void
    {
        $isArray = $this->isArray();

        if ($value === null) {
            $value = $isArray ? [] : '';
        } else {
            $isCorrectType = $isArray ? is_array($value) : is_string($value);

            if (! $isCorrectType) {
                throw new \InvalidArgumentException(sprintf(
                    'Invalid value received for "%s": expected %s, got %s',
                    $this->getName(),
                    $isArray ? 'array' : 'string',
                    gettype($value)
                ));
            }
        }

        $this->resetErrors();

        $empty = ($value === '' || $value === []);

        if ($empty && $this->required) {
            $this->addTranslatableError('form.required', 'This field is required.');
        }

        if (! $empty && ! $isArray) {
            $value = $this->filter($value);
            $this->validate($value);
        }

        $this->doPopulate($value);
    }
public function populate ( $ value ) : void { $ isArray = $ this -> isArray ( ) ; if ( $ value === null ) { $ value = $ isArray ? [ ] : '' ; } else { $ isCorrectType = $ isArray ? is_array ( $ value ) : is_string ( $ value ) ; if ( ! $ isCorrectType ) { throw new \ InvalidArgumentException ( sprintf ( 'Invalid value received for "%s": expected %s, got %s' , $ this -> getName ( ) , $ isArray ? 'array' : 'string' , gettype ( $ value ) ) ) ; } } $ this -> resetErrors ( ) ; $ empty = ( $ value === '' || $ value === [ ] ) ; if ( $ empty && $ this -> required ) { $ this -> addTranslatableError ( 'form.required' , 'This field is required.' ) ; } if ( ! $ empty && ! $ isArray ) { $ value = $ this -> filter ( $ value ) ; $ this -> validate ( $ value ) ; } $ this -> doPopulate ( $ value ) ; }
Populates the component with the given value.

The value will be filtered and validated.
Validation errors will be accessible via hasErrors() and getErrors().

@param string|array|null $value

@return void

@throws \InvalidArgumentException If the given value is not of a correct type for this component.
Populates the component with the given value .