Get JsonResponse array for Settings novalidate and form display.

@param FormInterface $form
@param View          $view
@param $novalidate

@throws \Exception

@return array
13863
private function getNotPersistedSettingsResponse(FormInterface $form, View $view, $novalidate)
    {
        $template = sprintf(
            '%s:%s',
            $this->getBaseTemplatePath(),
            ($novalidate === false) ? 'settings.html.twig' : 'form.html.twig'
        );

        return [
            'success' => !$form->isSubmitted(),
            'html'    => $this->container->get('templating')->render(
                $template,
                [
                    'page'               => $view,
                    'form'               => $form->createView(),
                    'businessProperties' => $this->getBusinessProperties($view),
                ]
            ),
        ];
    }
794187
public function getRegistryData(FormInterface $form = null, PropertyAccess $conf = null)
    {
        $data = [];

        if (null !== $form) {
            if (!$form->isSubmitted()) {
                throw new RuntimeException('Form must have been submitted');
            }
            $newData = $form->getData();
            $data = $this->filterNullValues($newData);
        }

        $currentConf = $conf ? ($conf->get('registry') ?: []) : [];

        return array_replace_recursive($this->getDefaultData($currentConf), $data);
    }
467969
public function getFormId(FormInterface $form)
    {
        if (is_object($form->getData())) {
            $ret = preg_replace('/\W/', '_', get_class($form->getData()));
        } else {
            if ($form->getName()) {
                return (string)$form->getName();
            } else {
                return preg_replace('/\W/', '_', get_class($form));
            }
        }
        return $ret;
    }
917621
public function buildResults(array &$form, FormStateInterface $form_state) {
    $user_input = $form_state->getUserInput();

    $values = $form_state->getValues();
    $query = $this->state;
    $filter_date = NULL;
    if (!isset($values['location']) && is_numeric($query['location'])) {
      $values['location_select'] = $values['location'] = $query['location'];
    }
    if (!isset($values['date']) && !empty($query['filter_date'])) {
      $values['date_select'] = $values['date'] = $query['filter_date'];
    }
    $location = !empty($values['location_select']) ? $values['location_select'] : $values['location'];
    if (isset($values['date'])) {
      $filter_date = !empty($values['date_select']) ? $values['date_select'] : $values['date'];
    }
    if (isset($user_input['date_select']) && $user_input['date_select'] != $filter_date) {
      $filter_date = $user_input['date_select'];
    }
    $class = !empty($values['class_select']) ? $values['class_select'] : 'any';
    if ($class == 'any' && empty($user_input['class_select']) && is_numeric($query['class'])) {
      $class = $query['class'];
    }
    $category = !empty($values['category_select']) ? $values['category_select'] : 'any';
    if ($category == 'any' && empty($user_input['category_select']) && is_numeric($query['category'])) {
      $category = $query['category_select'];
    }

    $filter_length = !empty($query['filter_length']) ? $query['filter_length'] : 'day';
    $groupex_class = !empty($query['groupex_class']) ? $query['groupex_class'] : 'groupex_table_class';
    $triggering_element = $form_state->getTriggeringElement();
    // Reset to day length in any case if date select has been changed.
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'date_select') {
      $filter_length = 'day';
    }
    // Reset to day length in any case if date select has been changed.
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'location_select' && is_numeric($class)) {
      $filter_length = 'week';
      $groupex_class = 'groupex_table_class_individual';
      $view_mode = 'class';
    }
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'class_select' && $triggering_element['#value'] != 'any') {
      $class = $triggering_element['#value'];
      $filter_length = 'week';
      $groupex_class = 'groupex_table_class_individual';
      $view_mode = 'class';
    }
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'category_select' && $triggering_element['#value'] != 'any') {
      $category = $triggering_element['#value'];
      $filter_length = 'week';
      $groupex_class = 'groupex_table_class_individual';
      $view_mode = 'class';
    }
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'location_select' && $groupex_class = 'groupex_table_instructor_individual') {
      $location = $triggering_element['#value'];
      $class = 'any';
      $filter_length = 'day';
      $groupex_class = 'groupex_table_class';
    }
    $parameters = [
      'location' => $location,
      'class' => $class,
      'category' => $category,
      'filter_length' => $filter_length,
      'filter_date' => $filter_date,
      'groupex_class' => $groupex_class,
    ];
    // Add optional parameters.
    if (!empty($user_input['instructor_select'])) {
      $parameters['instructor'] = $user_input['instructor_select'];
    }
    elseif (!empty($query['instructor'])) {
      $parameters['instructor'] = $query['instructor'];
    }
    if (isset($view_mode)) {
      $parameters['view_mode'] = $view_mode;
    }
    if (isset($triggering_element['#name']) && $triggering_element['#name'] == 'location_select' && $groupex_class = 'groupex_table_instructor_individual') {
      unset($parameters['instructor']);
      unset($parameters['view_mode']);
    }

    // Remove instructor parameter in case of no instructor selected.
    if (isset($parameters['instructor']) && $parameters['instructor'] == 'any') {
      unset($parameters['instructor']);
    }

    $this->scheduleFetcher->__construct($this->groupexHelper, $this->configFactory, $parameters);

    // Get classes schedules.
    $schedule = $this->scheduleFetcher->getSchedule();
    // Are results empty?
    $formatted_results = $this->t('No results. Please try again.');
    if (!$empty_results = $this->scheduleFetcher->isEmpty()) {
      // Format results as table view.
      $formatted_results = openy_group_schedules_schedule_table_layout($schedule);
    }
    return $formatted_results;
  }
1357517
public function renderInitcmsFieldAsString(
        $template,
        $object,
        FormView $formView,
        $translationDomain = null
    ) {

        /** @var $fieldDescription \Sonata\DoctrineORMAdminBundle\Admin\FieldDescription */
        $fieldDescription = $formView->vars['sonata_admin']['field_description'];
        $value = '';

        switch ($fieldDescription->getType()) {
            case HiddenType::class:
                $value = $fieldDescription->getValue($object);
                break;
            case BooleanType::class:
                if ($fieldDescription->getValue($object)) {
                    $value = 'positive';
                } else {
                    $value = 'negative';
                }
                break;
            case ChoiceType::class:
            case AutocompleteType::class:
            case IconradioType::class:
            case EntityType::class:
                $choices = $formView->vars['choices'];
                $preferredChoices = $formView->vars['preferred_choices'];
                $choices = array_merge($choices, $preferredChoices);
                $selected = $fieldDescription->getValue($object);
                if (is_object($selected)) {
                    $selected = (string) $selected->getId();
                }
                foreach ($choices as $choice) {
                    if ($choice->value == $selected) {
                        $value = $choice->label;
                    }
                }
                break;
            case DateType::class:
                /** @var $date \DateTime */
                $date = $fieldDescription->getValue($object);
                if ($date) {
                    $value = $date->format('d.m.Y');
                } else {
                    $value = '';
                }
                break;
            case DateTimeType::class:
                /** @var $date \DateTime */
                $date = $fieldDescription->getValue($object);
                if ($date) {
                    $value = $date->format('d.m.Y H:i');
                } else {
                    $value = '';
                }
                break;
            case ModelHiddenType::class:
                $value = $fieldDescription->getValue($object);
                break;
            case CheckboxType::class:
                if ($fieldDescription->getValue($object)) {
                    $value = 'positive';
                } else {
                    $value = 'negative';
                }
                break;
            case TextType::class:
            default:
                $value = $fieldDescription->getValue($object);
                break;
        }

        if ($displayMethod = $fieldDescription->getOption('display_method')) {
            $value = $this->getFieldValue($object, $fieldDescription->getFieldName(), $displayMethod);
        }

        $valueTranslationDomain = $fieldDescription->getTranslationDomain();

        if ('visibility' === $fieldDescription->getName() || 'templateName' === $fieldDescription->getName()) {
            if (array_key_exists('choice_translation_domain', $formView->vars)) {
                $valueTranslationDomain = $formView->vars['choice_translation_domain'];
            }

            $value = $this->translator->trans($value, [], $valueTranslationDomain);
        }

        $options = [
            'page' => $object,
            'field' => $fieldDescription->getName(),
            'value' => $value,
            'translation_domain' => $translationDomain,
        ];

        return $this->templating->render($template, $options);
    }
432120
protected function getAllErrors(FormInterface $form)
    {
        $errors = $form->getErrors();
        $children = $form->all();
        if (!count($errors) && !count($children)) {
            return null;
        }

        $section = [
            'field' => $form->getName()
        ];

        if (count($errors)) {
            $section['errors'] = array_map(
                function (FormError $error) {
                    return [
                        'message' => $error->getMessage(),
                        'parameters' => $error->getMessageParameters()
                    ];
                },
                iterator_to_array($form->getErrors())
            );
        }

        if (count($children)) {
            $section['children'] = array_values(
                array_filter(
                    array_map(
                        function (FormInterface $field) {
                            return $this->getAllErrors($field);
                        },
                        $form->all()
                    )
                )
            );

            if (!count($errors) && !count($section['children'])) {
                return null;
            }
        }

        return $section;
    }
688785
public function buildView(FormView $view, FormInterface $form, array $options)
    {
        if (array_key_exists('preview_base_path', $options)) {
            $parentData = $form->getParent()->getData();

            $previewUrl = null;
            if (null !== $parentData) {
                $accessor = PropertyAccess::createPropertyAccessor();
                $previewUrl = $accessor->getValue($parentData, $options['preview_base_path']);
            }

            if (!empty($previewUrl)) {
                $pathInfo = pathinfo($previewUrl);
                // define path to preview resource
                $view->vars['preview_url'] = $previewUrl;
                $view->vars['preview_basename'] = $pathInfo['basename'];
            }
        }
    }
397427
private function getFormInterface(FormInterface $form, $id): FormInterface
    {
        $name = $form->getName();
        if ($id === $name)
            return $form;
        if (mb_strpos($id, $name.'_') === 0) {
            $id = mb_substr($id, mb_strlen($name . '_'));
            foreach ($form->all() as $name => $child) {
                if ($id === $name)
                    return $child;
                if (mb_strpos($id, $name.'_') === 0)
                    return $this->getFormInterface($child, $id);
            }
        }
        return $form;
    }
740274
public function finishView(FormView $view, FormInterface $form, array $options)
    {
        $data = $this->context->getCurrentNodeId();

        if (!$view->parent && $options['compound'] and !empty($data)) {
            $factory = $form->getConfig()->getFormFactory();

            $form = $factory->createNamed($options['node_id_field_name'], 'hidden', $data, ['mapped' => false]);

            $view->children[$options['node_id_field_name']] = $form->createView($view);
        }
    }
1015187
private function getLocale(FormInterface $form)
    {
        if (null === $form->getParent()) {
            return null;
        }

        $entity = $form->getParent()->getData();

        if (!is_object($entity)) {
            return null;
        }

        $class = ClassUtils::getClass($entity);

        if (!$this->translatableManager->isTranslation($class)) {
            return null;
        }

        return $this->propertyAccessor->getValue($entity, $this->translatableManager->getTranslationLocaleProperty());
    }
200952
protected function getErrorFormLabel(FormInterface $form):array
    {
        $vars = $form->createView()->vars;

        $label = $vars['label'];
        $translationDomain = $vars['translation_domain'];

        $result = array(
            'label' => $label,
            'domain' => $translationDomain,
        );

        if (empty($label)) {
            if ($form->getParent() !== null) {
                $result = $this->getErrorFormLabel($form->getParent());
            }
        }

        return $result;
    }
1259688
public function finishView(FormView $view, FormInterface $form, array $options)
    {
        if (!$view->vars['tabbed']) {
            return;
        }

        $activeTab = null;
        $tabIndex = 0;
        $foundInvalid = false;
        $tabs = [];

        foreach ($view->children as $child) {
            if (\in_array('tab', $child->vars['block_prefixes'], true)) {
                $child->vars['tab_index'] = $tabIndex;
                $valid = $child->vars['valid'];

                if ((null === $activeTab || !$valid) && !$foundInvalid) {
                    $activeTab = $child;
                    $foundInvalid = !$valid;
                }

                $tabs[$tabIndex] = $child->vars; // ACTUAL OVERRIDE
                $tabs[$tabIndex]['active'] = false;

                ++$tabIndex;
            }
        }

        $activeTab->vars['tab_active'] = true;
        $tabs[$activeTab->vars['tab_index']]['active'] = true;

        $tabsForm = $this->formFactory->create(
            TabsType::class,
            null,
            [
                'tabs' => $tabs,
                'attr' => [
                    'class' => $options['tabs_class'],
                ],
            ]
        );

        $view->vars['tabs'] = $tabs;
        $view->vars['tabbed'] = true;
        $view->vars['tabsView'] = $tabsForm->createView();
    }
1200849
private function handleAll(FormInterface $form)
    {
        $config = $form->get('value')->getConfig();
        $choiceValue = $config->getOption('choice_value');
        $choices = iterator_to_array($config->getOption('grid')->getDataSource(['all' => true]));

        $this->buildForm($form, $choices);

        return array_map(function ($choice) use ($choiceValue) {
            return call_user_func($choiceValue, $choice);
        }, $choices);
    }
135762
public function render(Nette\Forms\Form $form, $mode = null)
    {
        $form->getElementPrototype()->setClass('form-inline');

        foreach ($form->getControls() as $control) {
            if ($control instanceof Controls\Button) {
                $usedPrimary = true;
            } elseif ($control instanceof Controls\TextBase ||
                $control instanceof Controls\SelectBox ||
                $control instanceof Controls\MultiSelectBox) {
                $control->getControlPrototype()->addClass('form-control');
            } elseif ($control instanceof Controls\Checkbox ||
                $control instanceof Controls\CheckboxList ||
                $control instanceof Controls\RadioList) {
                $control->getSeparatorPrototype()->setName('div')->addClass($control->getControlPrototype()->type);
            }
        }

        return parent::render($form, $mode);
    }
656708
protected function processRender(FormInterface $form, Request $request): void
    {
        /** @var Presenter $presenter */
        $presenter = $this->getPresenter();
        if (!$presenter->isAjax()) {
            throw new BadRequestException('The render signal is only allowed in ajax mode.');
        }

        $fields = $request->getPost($this->lookupPath(Presenter::class, true).self::NAME_SEPARATOR.'fields');
        if (!$fields) {
            throw new BadRequestException('No fields specified for rendering.');
        }

        $form->handleRequest($request);
        if (!$form->isSubmitted()) {
            throw new BadRequestException('The form was not submitted.');
        }

        $view = $this->getView();
        $widgets = [];
        foreach ($fields as $field) {
            // Validate the field identifier for security reasons. A dot in the identifier would be particularly dangerous.
            if (!Strings::match($field, '~^(?:\[\w++\])++$~')) {
                throw new BadRequestException(
                    sprintf('Field identifier "%s" contains unallowed characters.', $field)
                );
            }

            // Skip duplicates. The renderer would return an empty string on second try.
            if (isset($widgets[$field])) {
                continue;
            }

            // Wrap an exception from PropertyAccessor in a BadRequestException.
            try {
                $fieldView = $this->propertyAccessor->getValue($view, $field);
            } catch (ExceptionInterface $e) {
                throw new BadRequestException(
                    sprintf('FormView not found for field identifier "%s".', $field),
                    0,
                    $e
                );
            }

            // Render the field widget.
            $widgets[$field] = $this->renderer->searchAndRenderBlock($fieldView, 'widget');
        }

        $presenter->sendJson((object) ['widgets' => $widgets]);
    }
440535
private function createFormView(FormInterface $form)
    {
        $themes = $this->getParameterResolver()->resolveThemes();
        $view = $form->createView();

        if (!empty($themes)) {
            $this->formRenderer->setTheme($view, $themes);
        }

        return $view;
    }
388579
public function serializeFormError(FormInterface $form)
    {
        $errors = $this->formSerializer->createFormErrorArray($form);

        $responseModel = new ResponseFormErrorModel($errors);

        return new JsonResponse($responseModel->getBody(), Response::HTTP_BAD_REQUEST);
    }