Adds a rule collection.

@param string|FormView $view The form full_name or view instance
@param RuleCollection $collection A RuleCollection instance
764348
public function add($view, RuleCollection $collection)
    {
        $name = FormHelper::getFormName($view);
        if (isset($this->rules[$name])) {
            $this->rules[$name]->addCollection($collection);
        } else {
            $this->rules[$name] = $collection;
        }
    }
450987
public function buildCollection(FormEvent $event, $eventName)
    {
        $form = $event->getForm();

        for ($i = 0; $i < $this->options['max_items']; ++$i) {
            $required = $i < $this->options['min_items'] ? true : false;
            $displayed = $i < $this->options['min_items'] || $this->isDisplayable($event, $i, $eventName);

            $options = $this->options['options'];
            $options['required'] = isset($options['required']) ?
                $options['required'] && $required :
                $required
            ;
            $options['attr'] = array_replace(
                isset($options['attr']) ? $options['attr'] : array(),
                array(
                    'data-collection-id' => $this->options['collection_id'],
                    'data-display' => $displayed ? 'show' : 'hide',
                    'data-position' => $i,
                )
            );

            if (!$displayed) {
                self::disableConstraints($options);
            }

            $form->add($i, $this->options['type'], $options);

            $form->get($i)->add('__to_remove', CheckboxType::class, array(
                'mapped' => false,
                'required' => false,
                'data' => !$displayed,
                'attr' => array(
                    'class' => 'idci_collection_item_remove',
                ),
            ));
        }
    }
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'];
            }
        }
    }
635180
protected function createBlockView(FormView $view)
    {
        $bView = new BlockView();
        $bView->vars = $view->vars;
        $bView->vars['block'] = $bView;
        unset($bView->vars['form']);

        return $bView;
    }
1297093
public function createCollectionTranslation(Collection $collection, string $locale): void
    {
        $query = $this->connection->createQueryBuilder()
            ->insert('ngbm_collection_translation')
            ->values(
                [
                    'collection_id' => ':collection_id',
                    'status' => ':status',
                    'locale' => ':locale',
                ]
            )
            ->setParameter('collection_id', $collection->id, Type::INTEGER)
            ->setParameter('status', $collection->status, Type::INTEGER)
            ->setParameter('locale', $locale, Type::STRING);

        $query->execute();
    }
1215665
private function doesRuleCollectionMatchsLineItem(RuleCollection $ruleCollection, LineItemScope $lineItemScope): bool
    {
        /** @var RuleEntity $discountRule */
        foreach ($ruleCollection as $discountRule) {
            $ruleCondition = $discountRule->getPayload();

            if (!$ruleCondition instanceof Rule) {
                continue;
            }

            if ($ruleCondition->match($lineItemScope)) {
                return true;
            }
        }

        return false;
    }
963143
public function buildView(FormView $view, FormInterface $form, array $options) {
        if(isset($options['ad_component_addon'])) {
            switch ($options['ad_component_addon']) {
                case 'pre':
                case 'post':
                    $addons=[$options['ad_component_addon']];
                    break;
                case 'both':
                    $addons=['pre','post'];
                    break;
                default:
                    throw new LogicException('Valor "'.$options['ad_component_addon'].'" parámetro "ad_component_addon" no válido. Valores permitidos: pre|post|both');
            }
            foreach ($addons as $addon) {
                $view->vars['ad_component_addon_type_'.$addon] = is_array($options['ad_component_addon_type']) ?
                    (isset($options['ad_component_addon_type'][$addon]) ? $options['ad_component_addon_type'][$addon] : null) :
                    $options['ad_component_addon_type'];
                if(is_null($view->vars['ad_component_addon_type_'.$addon])){
                    throw new LogicException('Falta parámetro "ad_component_addon_type" para "'.$addon.'" addon');
                }
                elseif(!in_array($view->vars['ad_component_addon_type_'.$addon], ['text','button','icon'])){
                    throw new LogicException('Valor "'.$view->vars['ad_component_addon_type_'.$addon].'" parámetro "ad_component_addon_type" para "'.$addon.'" addon no válido. Valores permitidos: text|button|icon');
                }

                $view->vars['ad_component_addon_content_type_'.$addon] = is_array($options['ad_component_addon_content_type']) ?
                    (isset($options['ad_component_addon_content_type'][$addon]) ? $options['ad_component_addon_content_type'][$addon] : null) :
                    $options['ad_component_addon_content_type'];
                if($view->vars['ad_component_addon_type_'.$addon]=='button') {
                    if(is_null($view->vars['ad_component_addon_content_type_'.$addon])) {
                        throw new LogicException('Falta Parámetro "ad_component_addon_content_type" para "' . $addon . '" addon');
                    }
                    elseif(!in_array($view->vars['ad_component_addon_content_type_'.$addon], ['text','icon'])) {
                        throw new LogicException('Valor "'.$view->vars['ad_component_addon_content_type_'.$addon].'" parámetro "ad_component_addon_content_type" para "'.$addon.'" addon no válido. Valores permitidos: text|icon');
                    }
                }

                $view->vars['ad_component_addon_content_'.$addon] = is_array($options['ad_component_addon_content']) ?
                    (isset($options['ad_component_addon_content'][$addon]) ? $options['ad_component_addon_content'][$addon] : null) :
                    $options['ad_component_addon_content'];
                if(is_null($view->vars['ad_component_addon_content_'.$addon])){
                    throw new LogicException('Falta Parámetro "ad_component_addon_content" para "'.$addon.'" addon');
                }

                $view->vars['ad_component_addon_attr_'.$addon] = isset($options['ad_component_addon_attr']) ?
                    (isset($options['ad_component_addon_attr'][$addon]) ? $options['ad_component_addon_attr'][$addon] : $options['ad_component_addon_attr']) :
                    array();
            }
        }
    }
845420
protected function configureRoutes(RouteCollection $collection)
    {
        parent::configureRoutes($collection);
        $collection->add('duplicate', $this->getRouterIdParameter() . '/duplicate');
        $collection->add('generateEntityCode');

        /* Needed or not needed ...
         * in sonata-project/admin-bundle/Controller/CRUDController.php
         * the batchAction method
         * throw exception if the http method is not POST
        */
        if ($collection->get('batch')) {
            $collection->get('batch')->setMethods(['POST']);
        }
    }
400974
public function getFormErrors(FormView $formView)
    {
        $errors = array();

        foreach ($this->widgets as $widget) {
            $errors = array_merge($errors, $widget->getFormErrors($formView));
        }

        return $errors;
    }
1361611
protected function _setViewData($formName)
    {
        $this->controller()->request->data($formName, $this->parameters()->viewValues());
        $this->controller()->set('searchParameters', $this->parameters());
    }
1001587
public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $formName = $form->getName();
        //Make sure to exclude all form names starting with 2 underscores.
        //For instance the prototype of a Collection starts with 2 underscores
        if ('__' === substr($formName,0,2)) {
            return;
        }

        if (!empty($options['group'])) {
            $group = $options['group'];
            $type = 'group';
        } else {
            // If no group is set, make sure we have a unique index.
            // This is needed to maintain the correct order of the fields.
            $group = 'single_' . $formName;
            $type = 'single';
        }

        $root = $view->parent;

        if (!isset($root->vars['groups'][$group])) {
            $root->vars['groups'][$group] = [
                'type' => $type,
                'items' => [],
            ];
        }
        $root->vars['groups'][$group]['items'][] = $formName;
    }
1145249
public function getFormErrors(FormView $formView)
    {
        $errors = parent::getFormErrors($formView);

        $formHelper = $this->getFormHelper();

        if (isset($formView['pagepartadmin_' . $this->pagePartAdmin->getContext()])) {
            $errors = array_merge($errors, $formHelper->getRecursiveErrorMessages($formView['pagepartadmin_' . $this->pagePartAdmin->getContext()]));
        }

        return $errors;
    }
318473
protected function processFieldsCollection($fieldCollection, $data, FormHandler $formHandler)
    {
        $fields = array();
        foreach ($fieldCollection as $field) {
            // Unnamed array fields
            if ($field['name'] === null) {
                if (!isset($i)) $i = 0;

                $field['name'] = $i;
                $field = $this->typeHandler->makeView($field, $data, $formHandler);
                $fields[] = $field;

                $i++;
            }
            // Named array fields
            else {
                $fieldName = $field['name'];
                $field = $this->typeHandler->makeView($field, $data, $formHandler);

                $field['has_error'] = false;
                if ($formHandler->fieldHasError($field['name'])) {
                    $field['has_error'] = true;
                }

                $fields[$fieldName] = $field;
            }
        }

        return $fields;
    }
992247
public function buildView(FormView $view, FormInterface $form, array $options)
    {   
        $data = $form->getData();
        $view->vars['configs'] = array_merge(array(
            'dependent_value' => isset($data[$options['second_name']]) ? $data[$options['second_name']] : null
        ), $options['configs']);
        
    }
20778
public function buildView(FormView $view, FormInterface $form, array $options)
    {
        $parentData = $form->getParent()->getData();
        if ($parentData !== null) {
            $accessor = PropertyAccess::getPropertyAccessor();

            // set an "image_url" variable that will be available when rendering this field
            $url = $accessor->getValue($parentData, $options['image_path']);
            if ($url !== null) {
                $view->vars['image_url'] = $url;
            }
        }

        if (empty($view->vars['image_url']) && $options['no_image_placeholder'] !== null) {
            $view->vars['image_url'] = $options['no_image_placeholder'];
        }

        $view->vars['gaufrette'] = $options['gaufrette'];
        $view->vars['image_alt'] = $options['image_alt'];
        $view->vars['image_width'] = $options['image_width'];
        $view->vars['image_height'] = $options['image_height'];
    }
500720
public function setTranslations(Collection $collection)
    {
        $this->translations = new ArrayCollection();

        foreach ($collection as $translation) {
            $this->addTranslation($translation);
        }
    }
1065645
private function setFormTheme(FormView $formView, array $theme): void
    {
        $this->get('twig')->getRuntime(FormRenderer::class)->setTheme($formView, $theme);
    }