/**
  * @param \Symfony\Component\Form\FormView $view
  * @param \Symfony\Component\Form\FormInterface $form
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $sonataAdmin = $form->getAttribute('sonata_admin');
     // avoid to add extra information not required by non admin field
     if ($form->getAttribute('sonata_admin_enabled', true)) {
         $sonataAdmin['value'] = $form->getData();
         // add a new block types, so the Admin Form element can be tweaked based on the admin code
         $types = $view->get('types');
         $baseName = str_replace('.', '_', $sonataAdmin['field_description']->getAdmin()->getCode());
         $baseType = $types[count($types) - 1];
         $types[] = sprintf('%s_%s', $baseName, $baseType);
         $types[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['field_description']->getName(), $baseType);
         if ($sonataAdmin['block_name']) {
             $types[] = $sonataAdmin['block_name'];
         }
         $view->set('types', $types);
         $view->set('sonata_admin_enabled', true);
         $view->set('sonata_admin', $sonataAdmin);
         $attr = $view->get('attr', array());
         if (!isset($attr['class'])) {
             $attr['class'] = $sonataAdmin['class'];
         }
         $view->set('attr', $attr);
     } else {
         $view->set('sonata_admin_enabled', false);
     }
     $view->set('sonata_admin', $sonataAdmin);
 }
Esempio n. 2
0
 public function buildView(FormView $view, FormInterface $form)
 {
     if ($view->hasParent()) {
         $parentId = $view->getParent()->get('id');
         $parentName = $view->getParent()->get('name');
         $id = sprintf('%s_%s', $parentId, $form->getName());
         $name = sprintf('%s[%s]', $parentName, $form->getName());
     } else {
         $id = $form->getName();
         $name = $form->getName();
     }
     $view->set('form', $view);
     $view->set('id', $id);
     $view->set('name', $name);
     $view->set('errors', $form->getErrors());
     $view->set('value', $form->getClientData());
     $view->set('read_only', $form->isReadOnly());
     $view->set('required', $form->isRequired());
     $view->set('max_length', $form->getAttribute('max_length'));
     $view->set('size', null);
     $view->set('label', $form->getAttribute('label'));
     $view->set('multipart', false);
     $view->set('attr', array());
     $types = array();
     foreach (array_reverse((array) $form->getTypes()) as $type) {
         $types[] = $type->getName();
     }
     $view->set('types', $types);
 }
Esempio n. 3
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $name = $form->getName();
     if ($view->hasParent()) {
         if ('' === $name) {
             throw new FormException('Form node with empty name can be used only as root form node.');
         }
         if ('' !== ($parentFullName = $view->getParent()->get('full_name'))) {
             $id = sprintf('%s_%s', $view->getParent()->get('id'), $name);
             $fullName = sprintf('%s[%s]', $parentFullName, $name);
         } else {
             $id = $name;
             $fullName = $name;
         }
     } else {
         // If this form node have empty name, set id to `form`
         // to avoid rendering `id=""` in html structure
         $id = $name ?: 'form';
         $fullName = $name;
     }
     $types = array();
     foreach ($form->getTypes() as $type) {
         $types[] = $type->getName();
     }
     $view->set('form', $view)->set('id', $id)->set('name', $name)->set('full_name', $fullName)->set('errors', $form->getErrors())->set('value', $form->getClientData())->set('read_only', $form->isReadOnly())->set('required', $form->isRequired())->set('max_length', $form->getAttribute('max_length'))->set('pattern', $form->getAttribute('pattern'))->set('size', null)->set('label', $form->getAttribute('label'))->set('multipart', false)->set('attr', $form->getAttribute('attr'))->set('types', $types)->set('translation_domain', $form->getAttribute('translation_domain'));
 }
Esempio n. 4
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $configs = $form->getAttribute('configs');
     $datas = $form->getClientData();
     if (!empty($datas)) {
         if ($form->getAttribute('multiple')) {
             $datas = is_scalar($datas) ? explode(',', $datas) : $datas;
             $value = array();
             foreach ($datas as $data) {
                 if (!$data instanceof File) {
                     $data = new File($form->getAttribute('rootDir') . '/' . $data);
                 }
                 $value[] = $configs['folder'] . '/' . $data->getFilename();
             }
             $value = implode(',', $value);
         } else {
             if (!$datas instanceof File) {
                 $datas = new File($form->getAttribute('rootDir') . '/' . $datas);
             }
             $value = $configs['folder'] . '/' . $datas->getFilename();
         }
         $view->set('value', $value);
     }
     $view->set('type', 'hidden')->set('configs', $form->getAttribute('configs'));
 }
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->set('parent_field', $form->getAttribute('parent_field'));
     $view->set('entity_alias', $form->getAttribute('entity_alias'));
     $view->set('no_result_msg', $form->getAttribute('no_result_msg'));
     $view->set('empty_value', $form->getAttribute('empty_value'));
 }
Esempio n. 6
0
    public function validate(FormInterface $form)
    {
        if (!$form->isSynchronized()) {
            $form->addError(new FormError(
                $form->getAttribute('invalid_message_template'),
                $form->getAttribute('invalid_message_parameters')
            ));
        }

        if (count($form->getExtraData()) > 0) {
            $form->addError(new FormError('This form should not contain extra fields'));
        }

        if ($form->isRoot() && isset($_SERVER['CONTENT_LENGTH'])) {
            $length = (int) $_SERVER['CONTENT_LENGTH'];
            $max = trim(ini_get('post_max_size'));

            if ('' !== $max) {
                switch (strtolower(substr($max, -1))) {
                    // The 'G' modifier is available since PHP 5.1.0
                    case 'g':
                        $max *= 1024;
                    case 'm':
                        $max *= 1024;
                    case 'k':
                        $max *= 1024;
                }

                if ($length > $max) {
                    $form->addError(new FormError('The uploaded file was too large. Please try to upload a smaller file'));
                }
            }
        }
    }
Esempio n. 7
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $view->set('widget', $form->getAttribute('widget'));
     if ('single_text' === $form->getAttribute('widget')) {
         $view->set('type', 'datetime');
     }
 }
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     $view->setAttribute('data-date', Util::ICUTojQueryDate($form->getAttribute('date_pattern')));
     $timePattern = $form->getAttribute('time_pattern');
     $view->setAttribute('data-time', Util::ICUTojQueryDate($timePattern));
     $view->setAttribute('data-ampm', false !== strpos($timePattern, 'h') ? '1' : '0');
 }
Esempio n. 9
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $view->set('allow_add', $form->getAttribute('allow_add'))->set('allow_delete', $form->getAttribute('allow_delete'));
     if ($form->hasAttribute('prototype')) {
         $view->set('prototype', $form->getAttribute('prototype')->createView($view));
     }
 }
Esempio n. 10
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $choiceList = $form->getAttribute('choice_list');
     $view->set('multiple', $form->getAttribute('multiple'))->set('expanded', $form->getAttribute('expanded'))->set('preferred_choices', $choiceList->getPreferredViews())->set('choices', $choiceList->getRemainingViews())->set('separator', '-------------------')->set('empty_value', $form->getAttribute('empty_value'));
     if ($view->get('multiple') && !$view->get('expanded')) {
         // Add "[]" to the name in case a select tag with multiple options is
         // displayed. Otherwise only one of the selected options is sent in the
         // POST request.
         $view->set('full_name', $view->get('full_name') . '[]');
     }
 }
Esempio n. 11
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $configs = $form->getAttribute('configs');
     $year = $form->getAttribute('years');
     $configs['dateFormat'] = 'yy-mm-dd';
     if ('single_text' === $form->getAttribute('widget')) {
         $formatter = $form->getAttribute('formatter');
         $configs['dateFormat'] = $this->getJavascriptPattern($formatter);
     }
     $view->set('min_year', min($year))->set('max_year', max($year))->set('configs', $configs)->set('culture', $form->getAttribute('culture'));
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $choiceList = $form->getAttribute('choice_list');
     // We should not load anything right now when loading via ajax
     $view->set('multiple', $form->getAttribute('multiple'))->set('expanded', $form->getAttribute('expanded'))->set('preferred_choices', array())->set('choices', array())->set('separator', '-------------------')->set('empty_value', $form->getAttribute('empty_value'));
     if ($view->get('multiple') && !$view->get('expanded')) {
         // Add "[]" to the name in case a select tag with multiple options is
         // displayed. Otherwise only one of the selected options is sent in the
         // POST request.
         $view->set('full_name', $view->get('full_name') . '[]');
     }
 }
Esempio n. 13
0
 public function buildView(FormView $view, FormInterface $form)
 {
     $choices = $form->getAttribute('choice_list')->getChoices();
     $preferred = array_flip($form->getAttribute('preferred_choices'));
     $view->set('multiple', $form->getAttribute('multiple'))->set('expanded', $form->getAttribute('expanded'))->set('preferred_choices', array_intersect_key($choices, $preferred))->set('choices', array_diff_key($choices, $preferred))->set('separator', '-------------------')->set('empty_value', '');
     if ($view->get('multiple') && !$view->get('expanded')) {
         // Add "[]" to the name in case a select tag with multiple options is
         // displayed. Otherwise only one of the selected options is sent in the
         // POST request.
         $view->set('full_name', $view->get('full_name') . '[]');
     }
 }
Esempio n. 14
0
 /**
  * Adds a CSRF field to the root form view.
  *
  * @param FormView      $view The form view
  * @param FormInterface $form The form
  */
 public function buildViewBottomUp(FormView $view, FormInterface $form)
 {
     if (!$view->hasParent() && !$form->getAttribute('single_control') && $form->hasAttribute('csrf_field_name')) {
         $name = $form->getAttribute('csrf_field_name');
         $csrfProvider = $form->getAttribute('csrf_provider');
         $intention = $form->getAttribute('csrf_intention');
         $factory = $form->getAttribute('csrf_factory');
         $data = $csrfProvider->generateCsrfToken($intention);
         $csrfForm = $factory->createNamed('hidden', $name, $data, array('property_path' => false));
         $view->addChild($csrfForm->createView($view));
     }
 }
 public function mapFormToData(FormInterface $form, &$data)
 {
     if ($form->getAttribute('property_path') !== null && $form->isSynchronized()) {
         $propertyPath = $form->getAttribute('property_path');
         // If the data is identical to the value in $data, we are
         // dealing with a reference
         $isReference = $form->getData() === $propertyPath->getValue($data);
         $byReference = $form->getAttribute('by_reference');
         if (!(is_object($data) && $isReference && $byReference)) {
             $propertyPath->setValue($data, $form->getData());
         }
     }
 }
Esempio n. 16
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $name = $form->getName();
     $readOnly = $form->getAttribute('read_only');
     if ($view->hasParent()) {
         if ('' === $name) {
             throw new FormException('Form node with empty name can be used only as root form node.');
         }
         if ('' !== ($parentFullName = $view->getParent()->get('full_name'))) {
             $id = sprintf('%s_%s', $view->getParent()->get('id'), $name);
             $fullName = sprintf('%s[%s]', $parentFullName, $name);
         } else {
             $id = $name;
             $fullName = $name;
         }
         // Complex fields are read-only if themselves or their parent is.
         $readOnly = $readOnly || $view->getParent()->get('read_only');
     } else {
         $id = $name;
         $fullName = $name;
         // Strip leading underscores and digits. These are allowed in
         // form names, but not in HTML4 ID attributes.
         // http://www.w3.org/TR/html401/struct/global.html#adef-id
         $id = ltrim($id, '_0123456789');
     }
     $types = array();
     foreach ($form->getTypes() as $type) {
         $types[] = $type->getName();
     }
     $view->set('form', $view)->set('id', $id)->set('name', $name)->set('full_name', $fullName)->set('read_only', $readOnly)->set('errors', $form->getErrors())->set('value', $form->getClientData())->set('disabled', $form->isDisabled())->set('required', $form->isRequired())->set('max_length', $form->getAttribute('max_length'))->set('pattern', $form->getAttribute('pattern'))->set('size', null)->set('label', $form->getAttribute('label'))->set('multipart', false)->set('attr', $form->getAttribute('attr'))->set('label_attr', $form->getAttribute('label_attr'))->set('single_control', $form->getAttribute('single_control'))->set('types', $types)->set('translation_domain', $form->getAttribute('translation_domain'));
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $datas = json_decode($form->getClientData(), true);
     $value = '';
     if (!empty($datas)) {
         if ($form->getAttribute('multiple')) {
             foreach ($datas as $data) {
                 $value .= $data['label'] . ', ';
             }
         } else {
             $value = $datas['label'];
         }
     }
     $view->set('autocompleter_value', $value)->set('route_name', $form->getAttribute('route_name'))->set('freeValues', $form->getAttribute('freeValues'));
 }
Esempio n. 18
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $view->set('value', $form->getAttribute('value'))->set('checked', (bool) $form->getClientData());
     if ($view->hasParent()) {
         $view->set('full_name', $view->getParent()->get('full_name'));
     }
 }
Esempio n. 19
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $scale = $form->getAttribute('scale');
     $oneVote = $form->getAttribute('oneVote');
     if ($oneVote == null) {
         $oneVote = false;
     }
     if ($scale == null) {
         $scale = 5;
     }
     $choices = array();
     for ($i = 0; $i <= $scale; $i++) {
         $choices[$i] = $i;
     }
     $view->set('configs', $form->getAttribute('configs'))->set('scale', $form->getAttribute('scale'))->set('choices', $choices)->set('oneVote', $oneVote)->set('read_only', $form->getParent()->isReadOnly());
 }
Esempio n. 20
0
 public function buildViewBottomUp(FormView $view, FormInterface $form)
 {
     $view->set('widget', $form->getAttribute('widget'));
     if ($view->hasChildren()) {
         $pattern = $form->getAttribute('formatter')->getPattern();
         // set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
         // lookup various formats at http://userguide.icu-project.org/formatparse/datetime
         if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) {
             $pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
         } else {
             // default fallback
             $pattern = '{{ year }}-{{ month }}-{{ day }}';
         }
         $view->set('date_pattern', $pattern);
     }
 }
Esempio n. 21
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $configs = $form->getAttribute('configs');
     $data = $form->getClientData();
     if (!empty($data)) {
         if (!$data instanceof Image) {
             $data = new Image($form->getAttribute('rootDir') . '/' . $data);
         }
         if ($data->hasThumbnail($this->selected)) {
             $thumbnail = $data->getTumbnail($this->selected);
             $view->set('thumbnail', array('file' => $configs['folder'] . '/' . $thumbnail->getFilename(), 'width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()));
         }
         $value = $configs['folder'] . '/' . $data->getFilename();
         $view->set('value', $value)->set('file', $value)->set('width', $data->getWidth())->set('height', $data->getHeight());
     }
     $view->set('filters', $this->filters);
 }
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $knockout['enabled'] = $form->getAttribute('knockout');
     if ($knockout['enabled'] === true) {
         $knockout['viewModel'] = array('name' => $form->getName(), 'fields' => $this->buildViewModelFields($form->getChildren()), 'bindings' => $this->buildViewModelBindings($form->getChildren()), 'collections' => $this->getCollections($form->getChildren(), $view));
     }
     $view->set('knockout', $knockout);
 }
 /**
  * @param \Symfony\Component\Form\FormView      $view
  * @param \Symfony\Component\Form\FormInterface $form
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $format = $form->getAttribute('format');
     $imageSrc = $view->get('image_src');
     if ($imageSrc !== null && $format !== null) {
         $view->set('image_src', $this->imManager->getUrl($format, $imageSrc));
     }
 }
 /**
  * Removes CSRF fields from all the form views except the root one.
  *
  * @param FormView      $view The form view
  * @param FormInterface $form The form
  */
 public function buildViewBottomUp(FormView $view, FormInterface $form)
 {
     if ($view->hasParent() && $form->hasAttribute('csrf_field_name')) {
         $name = $form->getAttribute('csrf_field_name');
         if (isset($view[$name])) {
             unset($view[$name]);
         }
     }
 }
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $contentIds = $form->getAttribute('content_ids');
     $paths = array();
     foreach ($contentIds as $key => $id) {
         $paths[$key] = $this->router->generate(null, array('content_id' => $id));
     }
     $view->vars['content_paths'] = $paths;
     parent::buildView($view, $form, $options);
 }
Esempio n. 26
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $configs = $options['configs'];
     $years = $options['years'];
     $configs['dateFormat'] = 'yy-mm-dd';
     if ('single_text' === $options['widget']) {
         $formatter = $form->getAttribute('formatter');
         $configs['dateFormat'] = $this->getJavascriptPattern($formatter);
     }
     $view->setVar('min_year', min($years))->setVar('max_year', max($years))->setVar('configs', $configs)->setVar('culture', $options['culture']);
 }
Esempio n. 27
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormViewInterface $view, FormInterface $form, array $options)
 {
     $datas = json_decode($form->getClientData(), true);
     $value = '';
     if (false === empty($datas)) {
         if (true === $form->getAttribute('multiple')) {
             foreach ($datas as $data) {
                 $value .= $data['label'] . ', ';
             }
         } else {
             $value = $datas['label'];
         }
     }
     $view->set('tokeninput_value', $value)->set('route_name', $form->getAttribute('route_name'));
     foreach ($this->_availableTokeninputOptions as $option) {
         if ($form->hasAttribute($option)) {
             $view->set($option, $form->getAttribute($option));
         }
     }
 }
Esempio n. 28
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form)
 {
     $request = $this->request;
     $configs = $form->getAttribute('configs');
     $data = $form->getClientData();
     $fileMeta = new Upload();
     $uploadDir = "/web/temp";
     $uploadDir .= '/' . date("Y") . '/' . date("m") . '/' . date("d");
     $relativeFilePath = $uploadDir;
     $absolutePath = str_replace('/', '//', $request->getRootDir());
     $absolutePath = str_replace('\\', '\\\\', $absolutePath);
     if (!empty($data)) {
         $absoluteFilePath = $request->getRootDir() . '/../' . $data->getPath() . '/' . $data->getUniqId();
         $relativeFilePath = $data->getPath() . '/' . $data->getUniqId();
         $relativePath = $data->getPath();
         $fileMeta = $this->em->getRepository('LowbiSystemBundle:Upload')->find($data->getId());
         if ($fileMeta == null) {
             $fileMeta = new Upload();
         }
         if ($fileMeta->getTodelete()) {
             try {
                 $this->em->remove($fileMeta);
                 $this->em->flush();
             } catch (\EXception $ex) {
             }
             $view->set('filePath', $relativeFilePath)->set('absolutePath', $absolutePath)->set('value', null)->set('fileMeta', $fileMeta);
             return;
         }
         if (!$data instanceof Image) {
             if ($data instanceof File) {
                 $data = new \Lowbi\SystemBundle\Gd\File\Image($absoluteFilePath);
             } else {
                 $data = new \Lowbi\SystemBundle\Gd\File\Image($absoluteFilePath);
             }
         }
         //if ($data->hasThumbnail($this->selected)) {
         $thumbnail = $data->getThumbnail($this->selected);
         $view->set('thumbnail', array('file' => $relativePath . '/' . $thumbnail->getFilename(), 'width' => $thumbnail->getWidth(), 'height' => $thumbnail->getHeight()));
         //}
         if ($configs['custom_storage_folder'] && false === ($value = $form->getClientData()) instanceof File) {
             // This if will be executed only when we load entity with existing file pointed to the folder different
             // from $configs['folder']
         } else {
             $value = $configs['folder'] . '/' . $data->getFilename();
         }
         $view->set('value', $value)->set('file', $value)->set('width', $data->getWidth())->set('height', $data->getHeight())->set('filePath', $relativeFilePath)->set('absolutePath', $absolutePath)->set('fileMeta', $fileMeta);
     } else {
         $view->set('filePath', $relativeFilePath)->set('absolutePath', $absolutePath)->set('fileMeta', $fileMeta);
     }
     $view->set('filters', $this->filters);
 }
 public function buildView(FormView $view, FormInterface $form)
 {
     $view->set('widget_controls', $form->getAttribute('widget_controls'));
     $view->set('widget_addon', $form->getAttribute('widget_addon'));
     $view->set('widget_prefix', $form->getAttribute('widget_prefix'));
     $view->set('widget_suffix', $form->getAttribute('widget_suffix'));
     $view->set('widget_type', $form->getAttribute('widget_type'));
     $view->set('widget_remove_btn', $form->getAttribute('widget_remove_btn'));
 }
Esempio n. 30
0
 /**
  * {@inheritdoc}
  */
 public function validate(FormInterface $form)
 {
     $error = '';
     $request = $this->request->request;
     $server = $this->request->server;
     $datas = array('privatekey' => $this->privateKey, 'challenge' => $request->get('recaptcha_challenge_field'), 'response' => $request->get('recaptcha_response_field'), 'remoteip' => $server->get('REMOTE_ADDR'));
     if (empty($datas['challenge']) || empty($datas['response'])) {
         $error = 'The captcha is not valid.';
     }
     if (true !== ($answer = $this->check($datas, $form->getAttribute('option_validator')))) {
         $error = sprintf('Unable to check the captcha from the server. (%s)', $answer);
     }
     if (!empty($error)) {
         $form->addError(new FormError($error));
     }
 }