function it_builds_view(FormConfigInterface $config, FormView $view, FormInterface $form, FormInterface $prototype)
 {
     $form->getConfig()->willReturn($config);
     $config->getAttribute('prototypes')->willReturn(['configuration_kind' => $prototype]);
     $prototype->createView($view)->shouldBeCalled();
     $this->buildView($view, $form, []);
 }
 /**
  * @param FormView      $view
  * @param FormInterface $form
  * @param array         $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $sonataAdmin = $form->getConfig()->getAttribute('sonata_admin');
     // avoid to add extra information not required by non admin field
     if ($form->getConfig()->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->vars['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->vars['types'] = $types;
         $view->vars['sonata_admin_enabled'] = true;
         $view->vars['sonata_admin'] = $sonataAdmin;
         $attr = $view->vars['attr'];
         if (!isset($attr['class'])) {
             $attr['class'] = $sonataAdmin['class'];
         }
         $view->vars['attr'] = $attr;
     } else {
         $view->vars['sonata_admin_enabled'] = false;
     }
     $view->vars['sonata_admin'] = $sonataAdmin;
 }
예제 #3
0
 /**
  * {@inheritdoc}
  */
 public function handleRequest(FormInterface $form, $request = null)
 {
     if (null !== $request) {
         throw new UnexpectedTypeException($request, 'null');
     }
     $name = $form->getName();
     $method = $form->getConfig()->getMethod();
     if ($method !== self::getRequestMethod()) {
         return;
     }
     // For request methods that must not have a request body we fetch data
     // from the query string. Otherwise we look for data in the request body.
     if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) {
         if ('' === $name) {
             $data = $_GET;
         } else {
             // Don't submit GET requests if the form's name does not exist
             // in the request
             if (!isset($_GET[$name])) {
                 return;
             }
             $data = $_GET[$name];
         }
     } else {
         // Mark the form with an error if the uploaded size was too large
         // This is done here and not in FormValidator because $_POST is
         // empty when that error occurs. Hence the form is never submitted.
         if ($this->serverParams->hasPostMaxSizeBeenExceeded()) {
             // Submit the form, but don't clear the default values
             $form->submit(null, false);
             $form->addError(new FormError($form->getConfig()->getOption('post_max_size_message'), null, array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize())));
             return;
         }
         $fixedFiles = array();
         foreach ($_FILES as $fileKey => $file) {
             $fixedFiles[$fileKey] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
         }
         if ('' === $name) {
             $params = $_POST;
             $files = $fixedFiles;
         } elseif (array_key_exists($name, $_POST) || array_key_exists($name, $fixedFiles)) {
             $default = $form->getConfig()->getCompound() ? array() : null;
             $params = array_key_exists($name, $_POST) ? $_POST[$name] : $default;
             $files = array_key_exists($name, $fixedFiles) ? $fixedFiles[$name] : $default;
         } else {
             // Don't submit the form if it is not present in the request
             return;
         }
         if (is_array($params) && is_array($files)) {
             $data = array_replace_recursive($params, $files);
         } else {
             $data = $params ?: $files;
         }
     }
     // Don't auto-submit the form unless at least one field is present.
     if ('' === $name && count(array_intersect_key($data, $form->all())) <= 0) {
         return;
     }
     $form->submit($data, 'PATCH' !== $method);
 }
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['parent_field'] = $form->getConfig()->getAttribute('parent_field');
     $view->vars['entity_alias'] = $form->getConfig()->getAttribute('entity_alias');
     $view->vars['no_result_msg'] = $form->getConfig()->getAttribute('no_result_msg');
     $view->vars['empty_value'] = $form->getConfig()->getAttribute('empty_value');
 }
예제 #5
0
 public function transform(FormInterface $form, $extensions = [])
 {
     $data = [];
     $order = 1;
     $required = [];
     foreach ($form->all() as $name => $field) {
         $transformedChild = $this->resolver->resolve($field)->transform($field, $extensions);
         $transformedChild['propertyOrder'] = $order;
         $data[$name] = $transformedChild;
         $order++;
         if ($this->resolver->resolve($field)->isRequired($field)) {
             $required[] = $field->getName();
         }
     }
     $schema = ['title' => $form->getConfig()->getOption('label'), 'type' => 'object', 'properties' => $data];
     if (!empty($required)) {
         $schema['required'] = $required;
     }
     $innerType = $form->getConfig()->getType()->getInnerType();
     if (method_exists($innerType, 'buildLiform')) {
         $schema['liform'] = $innerType->buildLiform($form);
     }
     $this->addCommonSpecs($form, $schema, $extensions);
     return $schema;
 }
 /**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     if ($form->getConfig()->hasAttribute('prototype') && $view->vars['prototype']->vars['multipart']) {
         $view->vars['multipart'] = true;
     }
     $options = $form->getConfig()->getOptions();
     $view->vars['null_locale_enabled'] = $options['null_locale_enabled'];
     $view->vars['null_locale_selected'] = $options['null_locale_selected'];
     $requestLocale = $this->getRequestLocale();
     $view->vars['locale_titles'] = array();
     foreach ($options['locales'] as $locale) {
         $view->vars['locale_titles'][$locale] = \Locale::getDisplayName($locale, $requestLocale);
     }
     $request = $this->getRequest();
     if (null === $request) {
         $current_selected_lang = $options['locales'][0];
     } else {
         $current_selected_lang = $request->cookies->get('current_selected_translation_lang', null);
         $selectedLanguageIsNotValid = $current_selected_lang !== '__all__' && !in_array($current_selected_lang, $options['locales']);
         if ($current_selected_lang === null || $selectedLanguageIsNotValid) {
             $current_selected_lang = $options['locales'][0];
         }
     }
     $view->vars['current_selected_lang'] = $current_selected_lang;
 }
예제 #7
0
파일: BaseType.php 프로젝트: mm999/EduSoho
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $name = $form->getName();
     $blockName = $options['block_name'] ?: $form->getName();
     $translationDomain = $options['translation_domain'];
     if ($view->parent) {
         if ('' !== ($parentFullName = $view->parent->vars['full_name'])) {
             $id = sprintf('%s_%s', $view->parent->vars['id'], $name);
             $fullName = sprintf('%s[%s]', $parentFullName, $name);
             $uniqueBlockPrefix = sprintf('%s_%s', $view->parent->vars['unique_block_prefix'], $blockName);
         } else {
             $id = $name;
             $fullName = $name;
             $uniqueBlockPrefix = '_' . $blockName;
         }
         if (null === $translationDomain) {
             $translationDomain = $view->parent->vars['translation_domain'];
         }
     } else {
         $id = $name;
         $fullName = $name;
         $uniqueBlockPrefix = '_' . $blockName;
         // 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');
     }
     $blockPrefixes = array();
     for ($type = $form->getConfig()->getType(); null !== $type; $type = $type->getParent()) {
         array_unshift($blockPrefixes, $type->getName());
     }
     $blockPrefixes[] = $uniqueBlockPrefix;
     $view->vars = array_replace($view->vars, array('form' => $view, 'id' => $id, 'name' => $name, 'full_name' => $fullName, 'disabled' => $form->isDisabled(), 'label' => $options['label'], 'multipart' => false, 'attr' => $options['attr'], 'block_prefixes' => $blockPrefixes, 'unique_block_prefix' => $uniqueBlockPrefix, 'translation_domain' => $translationDomain, 'cache_key' => $uniqueBlockPrefix . '_' . $form->getConfig()->getType()->getName()));
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['root_node'] = $form->getConfig()->getAttribute('root_node');
     $view->vars['select_root_node'] = $form->getConfig()->getAttribute('select_root_node');
     $view->vars['repository_name'] = $form->getConfig()->getAttribute('repository_name');
     $view->vars['routing_defaults'] = $this->defaults;
 }
예제 #9
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     if ($form->getConfig()->hasAttribute('prototypes')) {
         $view->vars['prototypes'] = array_map(function (FormInterface $prototype) use($view) {
             return $prototype->createView($view);
         }, $form->getConfig()->getAttribute('prototypes'));
     }
 }
예제 #10
0
 /**
  * @inheritdoc
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['enable'] = $form->getConfig()->getAttribute('enable');
     if ($form->getConfig()->getAttribute('enable')) {
         $view->vars['instance'] = $form->getConfig()->getAttribute('instance');
         $view->vars['homeFolder'] = $form->getConfig()->getAttribute('homeFolder');
     }
 }
예제 #11
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['visible'] = $form->getConfig()->getOption('visible');
     $displayText = $form->getConfig()->getOption('display_text');
     if ($view->vars['visible'] && is_callable($displayText)) {
         $view->vars['attr']['data-display-text'] = call_user_func($displayText, $form);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function handleRequest(FormInterface $form, $request = null)
 {
     if (!$request instanceof Request) {
         throw new UnexpectedTypeException($request, 'Symfony\\Component\\HttpFoundation\\Request');
     }
     $name = $form->getName();
     $method = $form->getConfig()->getMethod();
     if ($method !== $request->getMethod()) {
         return;
     }
     // For request methods that must not have a request body we fetch data
     // from the query string. Otherwise we look for data in the request body.
     if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) {
         if ('' === $name) {
             $data = $request->query->all();
         } else {
             // Don't submit GET requests if the form's name does not exist
             // in the request
             if (!$request->query->has($name)) {
                 return;
             }
             $data = $request->query->get($name);
         }
     } else {
         // Mark the form with an error if the uploaded size was too large
         // This is done here and not in FormValidator because $_POST is
         // empty when that error occurs. Hence the form is never submitted.
         $contentLength = $this->serverParams->getContentLength();
         $maxContentLength = $this->serverParams->getPostMaxSize();
         if (!empty($maxContentLength) && $contentLength > $maxContentLength) {
             // Submit the form, but don't clear the default values
             $form->submit(null, false);
             $form->addError(new FormError($form->getConfig()->getOption('post_max_size_message'), null, array('{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize())));
             return;
         }
         if ('' === $name) {
             $params = $request->request->all();
             $files = $request->files->all();
         } elseif ($request->request->has($name) || $request->files->has($name)) {
             $default = $form->getConfig()->getCompound() ? array() : null;
             $params = $request->request->get($name, $default);
             $files = $request->files->get($name, $default);
         } else {
             // Don't submit the form if it is not present in the request
             return;
         }
         if (is_array($params) && is_array($files)) {
             $data = array_replace_recursive($params, $files);
         } else {
             $data = $params ?: $files;
         }
     }
     // Don't auto-submit the form unless at least one field is present.
     if ('' === $name && count(array_intersect_key($data, $form->all())) <= 0) {
         return;
     }
     $form->submit($data, 'PATCH' !== $method);
 }
 /**
  * Test build of form with form type
  */
 public function testFormCreate()
 {
     // Assert fields
     $this->assertField('label', 'pim_translatable_field');
     $this->assertField('sort_order', 'hidden');
     // Assert option class
     $this->assertEquals('Pim\\Bundle\\CatalogBundle\\Entity\\AttributeGroup', $this->form->getConfig()->getDataClass());
     // Assert name
     $this->assertEquals('pim_enrich_attribute_group', $this->form->getName());
 }
 /**
  * @param FormInterface $field
  *
  * @return bool
  */
 private function isFormFieldSupported(FormInterface $field)
 {
     if ($field->getConfig()->getCompound()) {
         if ($field->getConfig()->getType()->getInnerType() instanceof RepeatedType) {
             return true;
         }
         return false;
     }
     return true;
 }
 /**
  * Test build of form with form type
  */
 public function testFormCreate()
 {
     // Assert fields
     $this->assertField('code', 'text');
     $this->assertField('label', 'pim_translatable_field');
     // Assert option class
     $this->assertEquals('Pim\\Bundle\\CatalogBundle\\Entity\\Category', $this->form->getConfig()->getDataClass());
     // Assert name
     $this->assertEquals('pim_category', $this->form->getName());
 }
 /**
  * Adds a CSRF field to the root form view.
  *
  * @param FormView      $view    The form view
  * @param FormInterface $form    The form
  * @param array         $options The options
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     if ($options['csrf_protection'] && !$view->parent && $options['compound']) {
         $factory = $form->getConfig()->getAttribute('csrf_factory');
         $intention = $options['intention'] ?: ($form->getName() ?: get_class($form->getConfig()->getType()->getInnerType()));
         $data = $options['csrf_provider']->generateCsrfToken($intention);
         $csrfForm = $factory->createNamed($options['csrf_field_name'], 'hidden', $data, array('mapped' => false));
         $view->children[$options['csrf_field_name']] = $csrfForm->createView($view);
     }
 }
예제 #17
0
 /**
  * Adds a CSRF field to the root form view.
  *
  * @param FormView      $view    The form view
  * @param FormInterface $form    The form
  * @param array         $options The options
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     if ($options['csrf_protection'] && !$view->parent && $options['compound']) {
         $factory = $form->getConfig()->getFormFactory();
         $tokenId = $options['csrf_token_id'] ?: ($form->getName() ?: get_class($form->getConfig()->getType()->getInnerType()));
         $data = (string) $options['csrf_token_manager']->getToken($tokenId);
         $csrfForm = $factory->createNamed($options['csrf_field_name'], 'Symfony\\Component\\Form\\Extension\\Core\\Type\\HiddenType', $data, array('mapped' => false));
         $view->children[$options['csrf_field_name']] = $csrfForm->createView($view);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars = array_replace($view->vars, array('allow_add' => $options['allow_add'], 'allow_delete' => $options['allow_delete'], 'add_button_text' => $options['add_button_text'], 'delete_button_text' => $options['delete_button_text'], 'sub_widget_col' => $options['sub_widget_col'], 'button_col' => $options['button_col'], 'prototype_name' => $options['prototype_name']));
     if (false === $view->vars['allow_delete']) {
         $view->vars['sub_widget_col'] += $view->vars['button_col'];
     }
     if ($form->getConfig()->hasAttribute('prototype')) {
         $view->vars['prototype'] = $form->getConfig()->getAttribute('prototype')->createView($view);
     }
 }
예제 #19
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['enable'] = $form->getConfig()->getAttribute('enable');
     if ($form->getConfig()->getAttribute('enable')) {
         $view->vars['base_path'] = $form->getConfig()->getAttribute('base_path');
         $view->vars['config'] = json_encode($form->getConfig()->getAttribute('config'));
         $view->vars['plugins'] = $form->getConfig()->getAttribute('plugins');
     }
     parent::buildView($view, $form, $options);
     // Dynamically load CKEditor assets
     if ($this->assetsLoader) {
         $this->assetsLoader->addVendor('ckeditor');
     }
 }
 /**
  * {@inheritdoc}
  */
 public function handleRequest(FormInterface $form, $request = null)
 {
     if (null !== $request) {
         throw new UnexpectedTypeException($request, 'null');
     }
     $name = $form->getName();
     $method = $form->getConfig()->getMethod();
     if ($method !== self::getRequestMethod()) {
         return;
     }
     if ('GET' === $method) {
         if ('' === $name) {
             $data = $_GET;
         } else {
             // Don't submit GET requests if the form's name does not exist
             // in the request
             if (!isset($_GET[$name])) {
                 return;
             }
             $data = $_GET[$name];
         }
     } else {
         $fixedFiles = array();
         foreach ($_FILES as $name => $file) {
             $fixedFiles[$name] = self::stripEmptyFiles(self::fixPhpFilesArray($file));
         }
         if ('' === $name) {
             $params = $_POST;
             $files = $fixedFiles;
         } elseif (array_key_exists($name, $_POST) || array_key_exists($name, $fixedFiles)) {
             $default = $form->getConfig()->getCompound() ? array() : null;
             $params = array_key_exists($name, $_POST) ? $_POST[$name] : $default;
             $files = array_key_exists($name, $fixedFiles) ? $fixedFiles[$name] : $default;
         } else {
             // Don't submit the form if it is not present in the request
             return;
         }
         if (is_array($params) && is_array($files)) {
             $data = array_replace_recursive($params, $files);
         } else {
             $data = $params ?: $files;
         }
     }
     // Don't auto-submit the form unless at least one field is present.
     if ('' === $name && count(array_intersect_key($data, $form->all())) <= 0) {
         return;
     }
     $form->submit($data, 'PATCH' !== $method);
 }
예제 #21
0
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['class'] = $form->getConfig()->getAttribute('class');
     $view->vars['parent_field'] = $form->getConfig()->getAttribute('parent_field');
     $view->vars['no_result_msg'] = $form->getConfig()->getAttribute('no_result_msg');
     $view->vars['empty_value'] = $form->getConfig()->getAttribute('empty_value');
     $view->vars['property'] = $form->getConfig()->getAttribute('property');
     $view->vars['em_name'] = $form->getConfig()->getAttribute('em_name');
     $view->vars['query'] = $form->getConfig()->getAttribute('query');
     $view->vars['order_direction'] = $form->getConfig()->getAttribute('order_direction');
     $view->vars['order_property'] = $form->getConfig()->getAttribute('order_property');
 }
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['dataIndeterminate'] = $form->getConfig()->getAttribute('dataIndeterminate');
     $view->vars['dataRadioAllOff'] = $form->getConfig()->getAttribute('dataRadioAllOff');
     $view->vars['dataAnimate'] = $form->getConfig()->getAttribute('dataAnimate');
     $view->vars['dataInverse'] = $form->getConfig()->getAttribute('dataInverse');
     $view->vars['dataSize'] = $form->getConfig()->getAttribute('dataSize');
     $view->vars['dataOnColor'] = $form->getConfig()->getAttribute('dataOnColor');
     $view->vars['dataOffColor'] = $form->getConfig()->getAttribute('dataOffColor');
     $view->vars['dataOnText'] = $form->getConfig()->getAttribute('dataOnText');
     $view->vars['dataOffText'] = $form->getConfig()->getAttribute('dataOffText');
 }
예제 #23
0
 /**
  * @param FormView      $view
  * @param FormInterface $form
  * @param array         $options
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $sonataAdmin = $form->getConfig()->getAttribute('sonata_admin');
     $sonataAdminHelp = isset($options['sonata_help']) ? $options['sonata_help'] : null;
     // avoid to add extra information not required by non admin field
     if ($sonataAdmin && $form->getConfig()->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
         $block_prefixes = $view->vars['block_prefixes'];
         $baseName = str_replace('.', '_', $sonataAdmin['admin']->getCode());
         $baseType = $block_prefixes[count($block_prefixes) - 2];
         $blockSuffix = preg_replace('#^_([a-z0-9]{14})_(.++)$#', '$2', array_pop($block_prefixes));
         $block_prefixes[] = sprintf('%s_%s', $baseName, $baseType);
         $block_prefixes[] = sprintf('%s_%s_%s', $baseName, $sonataAdmin['name'], $baseType);
         $block_prefixes[] = sprintf('%s_%s_%s_%s', $baseName, $sonataAdmin['name'], $baseType, $blockSuffix);
         if (isset($sonataAdmin['block_name']) && $sonataAdmin['block_name'] !== false) {
             $block_prefixes[] = $sonataAdmin['block_name'];
         }
         $view->vars['block_prefixes'] = $block_prefixes;
         $view->vars['sonata_admin_enabled'] = true;
         $view->vars['sonata_admin'] = $sonataAdmin;
         $attr = $view->vars['attr'];
         if (!isset($attr['class']) && isset($sonataAdmin['class'])) {
             $attr['class'] = $sonataAdmin['class'];
         }
         $view->vars['attr'] = $attr;
     } else {
         $view->vars['sonata_admin_enabled'] = false;
     }
     $view->vars['sonata_help'] = $sonataAdminHelp;
     $view->vars['sonata_admin'] = $sonataAdmin;
 }
 /**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     $config = $form->getConfig();
     $view->vars['depends_on_parent_field'] = $config->getOption('depends_on_parent_field');
     $view->vars['data_route'] = $config->getOption('data_route');
     $view->vars['data_route_parameter'] = $config->getOption('data_route_parameter');
 }
예제 #25
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['feeCalculatorsConfigurations'] = array();
     foreach ($form->getConfig()->getAttribute('feeCalculatorsConfigurations') as $type => $feeCalculatorConfiguration) {
         $view->vars['feeCalculatorsConfigurations'][$type] = $feeCalculatorConfiguration->createView($view);
     }
 }
예제 #26
0
 /**
  * {@inheritdoc}
  */
 public function buildView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['prototypes'] = [];
     foreach ($form->getConfig()->getAttribute('prototypes') as $type => $prototype) {
         $view->vars['prototypes'][$type] = $prototype->createView($view);
     }
 }
예제 #27
0
 function it_builds_view(FormView $view, FormInterface $form, FormConfigInterface $formConfig)
 {
     $form->getConfig()->shouldBeCalled()->willReturn($formConfig);
     $formConfig->getAttribute('prototypes')->shouldBeCalled()->willReturn(['type' => $form]);
     $form->createView($view)->shouldBeCalled();
     $this->buildView($view, $form, []);
 }
예제 #28
0
 /**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     $view->vars['widget'] = $options['widget'];
     // Change the input to a HTML5 date input if
     //  * the widget is set to "single_text"
     //  * the format matches the one expected by HTML5
     if ('single_text' === $options['widget'] && self::HTML5_FORMAT === $options['format']) {
         $view->vars['type'] = 'date';
     }
     if ($form->getConfig()->hasAttribute('formatter')) {
         $pattern = $form->getConfig()->getAttribute('formatter')->getPattern();
         // remove special characters unless the format was explicitly specified
         if (!is_string($options['format'])) {
             $pattern = preg_replace('/[^yMd]+/', '', $pattern);
         }
         // 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]+)[^yMd]*([yMd]+)$/', $pattern)) {
             $pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
         } else {
             // default fallback
             $pattern = '{{ year }}{{ month }}{{ day }}';
         }
         $view->vars['date_pattern'] = $pattern;
     }
 }
 /**
  * Test method related
  */
 public function testFormCreate()
 {
     // Assert default options
     $expectedOptions = array('entity_class' => false, 'field' => false, 'locales' => array('en_US', 'fr_FR'), 'required_locale' => array(), 'translation_class' => false, 'widget' => 'text');
     // Assert options
     $options = $this->form->getConfig()->getOptions();
     $expectedOptions['entity_class'] = self::OPT_ENTITY_CLASS;
     $expectedOptions['field'] = self::OPT_NAME;
     $expectedOptions['translation_class'] = self::OPT_TRANSLATION_CLASS;
     foreach ($expectedOptions as $expectedKey => $expectedValue) {
         $this->assertArrayHasKey($expectedKey, $options);
         $this->assertEquals($expectedValue, $options[$expectedKey]);
     }
     // Assert name
     $this->assertEquals('pim_translatable_field', $this->form->getName());
 }
 /**
  * Navigates to the Root form to define if cascading should be done.
  *
  * @param FormInterface $form
  * @return boolean
  */
 public function getRootFormCascadeOption(FormInterface $form)
 {
     if (!$form->isRoot()) {
         return $this->getRootFormCascadeOption($form->getParent());
     }
     return $form->getConfig()->getOption('cascade_filter', false);
 }