本文整理汇总了PHP中Symfony\Component\Form\FormInterface::getConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::getConfig方法的具体用法?PHP FormInterface::getConfig怎么用?PHP FormInterface::getConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::getConfig方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
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, []);
}
示例2: buildView
/**
* @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: handleRequest
/**
* {@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);
}
示例4: buildView
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: transform
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;
}
示例6: finishView
/**
* {@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: buildView
/**
* {@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()));
}
示例8: buildView
/**
* {@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: buildView
/**
* {@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: buildView
/**
* @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: buildView
/**
* {@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);
}
}
示例12: handleRequest
/**
* {@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);
}
示例13: testFormCreate
/**
* 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());
}
示例14: isFormFieldSupported
/**
* @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;
}
示例15: finishView
/**
* 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);
}
}