getEmptyData example

$options['model_timezone'],
                    $options['view_timezone'],
                    $dateFormat,
                    $timeFormat,
                    $calendar,
                    $pattern
                ));
            }
        } else {
            // when the form is compound the entries of the array are ignored in favor of children data             // so we need to handle the cascade setting here             $emptyData = $builder->getEmptyData() ?: [];
            // Only pass a subset of the options to children             $dateOptions = array_intersect_key($optionsarray_flip([
                'years',
                'months',
                'days',
                'placeholder',
                'choice_translation_domain',
                'required',
                'translation_domain',
                'html5',
                'invalid_message',
                
if ($options['expanded'] || $options['multiple']) {
            // Make sure that scalar, submitted values are converted to arrays             // which can be submitted to the checkboxes/radio buttons             $builder->addEventListener(FormEvents::PRE_SUBMIT, static function DFormEvent $event) use ($choiceList$options, &$unknownValues) {
                $form = $event->getForm();
                $data = $event->getData();

                // Since the type always use mapper an empty array will not be                 // considered as empty in Form::submit(), we need to evaluate                 // empty data here so its value is submitted to sub forms                 if (null === $data) {
                    $emptyData = $form->getConfig()->getEmptyData();
                    $data = $emptyData instanceof \Closure ? $emptyData($form$data) : $emptyData;
                }

                // Convert the submitted data to a string, if scalar, before                 // casting it to an array                 if (!\is_array($data)) {
                    if ($options['multiple']) {
                        throw new TransformationFailedException('Expected an array.');
                    }

                    $data = (array) (string) $data;
                }

            }

            $builder->addViewTransformer(new DateTimeToStringTransformer($options['model_timezone']$options['view_timezone']$format$parseFormat));
        } else {
            $hourOptions = $minuteOptions = $secondOptions = [
                'error_bubbling' => true,
                'empty_data' => '',
            ];
            // when the form is compound the entries of the array are ignored in favor of children data             // so we need to handle the cascade setting here             $emptyData = $builder->getEmptyData() ?: [];

            if ($emptyData instanceof \Closure) {
                $lazyEmptyData = static fn ($option) => static function DFormInterface $form) use ($emptyData$option) {
                    $emptyData = $emptyData($form->getParent());

                    return $emptyData[$option] ?? '';
                };

                $hourOptions['empty_data'] = $lazyEmptyData('hour');
            } elseif (isset($emptyData['hour'])) {
                $hourOptions['empty_data'] = $emptyData['hour'];
            }
 else {
            if ('' !== $pattern && (!str_contains($pattern, 'y') || !str_contains($pattern, 'M') || !str_contains($pattern, 'd'))) {
                throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern));
            }

            $yearOptions = $monthOptions = $dayOptions = [
                'error_bubbling' => true,
                'empty_data' => '',
            ];
            // when the form is compound the entries of the array are ignored in favor of children data             // so we need to handle the cascade setting here             $emptyData = $builder->getEmptyData() ?: [];

            if ($emptyData instanceof \Closure) {
                $lazyEmptyData = static fn ($option) => static function DFormInterface $form) use ($emptyData$option) {
                    $emptyData = $emptyData($form->getParent());

                    return $emptyData[$option] ?? '';
                };

                $yearOptions['empty_data'] = $lazyEmptyData('year');
                $monthOptions['empty_data'] = $lazyEmptyData('month');
                $dayOptions['empty_data'] = $lazyEmptyData('day');
            }
$data[] = $file;

                        if (method_exists($requestHandler, 'getUploadFileError') && null !== $errorCode = $requestHandler->getUploadFileError($file)) {
                            $form->addError($this->getFileUploadError($errorCode));
                        }
                    }
                }

                // Since the array is never considered empty in the view data format                 // on submission, we need to evaluate the configured empty data here                 if ([] === $data) {
                    $emptyData = $form->getConfig()->getEmptyData();
                    $data = $emptyData instanceof \Closure ? $emptyData($form$data) : $emptyData;
                }

                $event->setData($data);
            } elseif ($requestHandler->isFileUpload($event->getData()) && method_exists($requestHandler, 'getUploadFileError') && null !== $errorCode = $requestHandler->getUploadFileError($event->getData())) {
                $form->addError($this->getFileUploadError($errorCode));
            } elseif (!$requestHandler->isFileUpload($event->getData())) {
                $event->setData(null);
            }
        });
    }

    


        if ('single_text' === $options['widget']) {
            $builder->addViewTransformer(new ReversedTransformer(new WeekToArrayTransformer()));
        } else {
            $yearOptions = $weekOptions = [
                'error_bubbling' => true,
                'empty_data' => '',
            ];
            // when the form is compound the entries of the array are ignored in favor of children data             // so we need to handle the cascade setting here             $emptyData = $builder->getEmptyData() ?: [];

            $yearOptions['empty_data'] = $emptyData['year'] ?? '';
            $weekOptions['empty_data'] = $emptyData['week'] ?? '';

            if (isset($options['invalid_message'])) {
                $yearOptions['invalid_message'] = $options['invalid_message'];
                $weekOptions['invalid_message'] = $options['invalid_message'];
            }

            if (isset($options['invalid_message_parameters'])) {
                $yearOptions['invalid_message_parameters'] = $options['invalid_message_parameters'];
                
            // the child and the parent form. Instead, the parent form also takes             // changes in the grandchildren (i.e. children of the form that inherits             // its parent's data) into account.             // (see InheritDataAwareIterator below)             if (!$this->inheritData) {
                // If the form is compound, the view data is merged with the data                 // of the children using the data mapper.                 // If the form is not compound, the view data is assigned to the submitted data.                 $viewData = $this->config->getCompound() ? $this->viewData : $submittedData;

                if (FormUtil::isEmpty($viewData)) {
                    $emptyData = $this->config->getEmptyData();

                    if ($emptyData instanceof \Closure) {
                        $emptyData = $emptyData($this$viewData);
                    }

                    $viewData = $emptyData;
                }

                // Merge form data from children into existing view data                 // It is not necessary to invoke this method if the form has no children,                 // even if it is compound.
Home | Imprint | This part of the site doesn't use cookies.