本文整理汇总了PHP中Symfony\Component\Form\Form::getConfig方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getConfig方法的具体用法?PHP Form::getConfig怎么用?PHP Form::getConfig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\Form
的用法示例。
在下文中一共展示了Form::getConfig方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveErrorsToFlashBag
/**
* @param Request $request
* @param
* $form
* @param
* $errors
*/
protected function saveErrorsToFlashBag(Request $request, Form $form)
{
$formClass = get_class($form->getConfig()->getType()->getInnerType());
$errors = [];
foreach ($form->getErrors(TRUE) as $error) {
$cause = $error->getCause();
$errors[] = ['message' => $error->getMessage(), 'messageTemplate' => $error->getMessageTemplate(), 'messageParameters' => $error->getMessageParameters(), 'messagePluralization' => $error->getMessagePluralization(), 'cause' => preg_replace('/data\\.|children\\[(.*?)\\]/', '$1', $cause->getPropertyPath()), 'invalidValue' => $cause->getInvalidValue()];
}
$this->addFlash('validation_error_' . $formClass, $errors);
$this->addFlash('validation_error_request_' . $formClass, $request);
}
示例2: getGroups
/**
* @param Form $form
*
* @return array
*/
protected function getGroups($form)
{
$result = array();
$result['groups'] = $form->getConfig()->getOption('validation_groups');
$result['children'] = array();
/** @var Form $element */
foreach ($form->all() as $name => $element) {
$result['children'][$name] = $this->getGroups($element);
}
return $result;
}
示例3: buildTypeSettingsForm
/**
* @param Form $form Main form.
* @param string $providerName Provider.
*/
protected function buildTypeSettingsForm(Form $form, $providerName)
{
// create sub-form wrapper
$subForm = $form->getConfig()->getFormFactory()->createNamed('properties', 'form', null, array('label' => false, 'auto_initialize' => false));
//Add provider form
if ($providerName && isset($this->providers[$providerName])) {
$provider = $this->providers[$providerName];
// delegate form structure building for specific provider
$provider->buildForm($subForm);
}
$form->add($subForm);
}
示例4: addField
public function addField(Form $form, $parser = null)
{
if ($parser === null) {
return false;
}
$options = $form->getConfig()->getOptions();
$em = $options['em'];
if (!$parser instanceof Newscoop\IngestPluginBundle\Entity\Parser) {
$parser = $em->getRepository('Newscoop\\IngestPluginBundle\\Entity\\Parser')->findOneById($parser);
}
if ($parser->requiresUrl()) {
$form->add('url', 'url', array('label' => 'plugin.ingest.feeds.url', 'required' => true));
}
}
示例5: parseConstraints
/**
* Converts list of constraints objects to a data array
*
* @param array $constraints
*
* @return array
*/
protected function parseConstraints(array $constraints)
{
$result = array();
foreach ($constraints as $item) {
// Translate messages if need and add to result
foreach ($item as $propName => $propValue) {
if (false !== strpos(strtolower($propName), 'message')) {
$item->{$propName} = $this->translateMessage($propValue);
}
}
if ($item instanceof \Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity) {
$item = new UniqueEntity($item, $this->currentElement->getConfig()->getDataClass());
}
$result[get_class($item)][] = $item;
}
return $result;
}
示例6: getRecursiveReadableErrors
/**
* Returns a string representation of all form errors (including children errors).
*
* This method should only be used in ajax calls.
*
* @param Form $form The form to parse
* @param bool $withChildren Do we parse the embedded forms
*
* @return string A string representation of all errors
*/
public function getRecursiveReadableErrors($form, $withChildren = true, $translationDomain = null, $level = 0)
{
$errors = '';
$translationDomain = $translationDomain ? $translationDomain : $form->getConfig()->getOption('translation_domain');
//the errors of the fields
foreach ($form->getErrors() as $error) {
//the view contains the label identifier
$view = $form->createView();
$labelId = $view->vars['label'];
//get the translated label
if ($labelId !== null) {
$label = $this->translator->trans($labelId, [], $translationDomain) . ' : ';
} else {
$label = '';
}
//in case of dev mode, we display the item that is a problem
//getCause cames in Symfony 2.5 version, this is just a fallback to avoid BC with previous versions
if ($this->debug && method_exists($error, 'getCause')) {
$cause = $error->getCause();
if ($cause !== null) {
$causePropertyPath = $cause->getPropertyPath();
$errors .= ' ' . $causePropertyPath;
}
}
//add the error
$errors .= $label . $this->translator->trans($error->getMessage(), [], $translationDomain) . "\n";
}
//do we parse the children
if ($withChildren) {
//we parse the children
foreach ($form->getIterator() as $child) {
$level++;
if ($err = $this->getRecursiveReadableErrors($child, $withChildren, $translationDomain, $level)) {
$errors .= $err;
}
}
}
return $errors;
}
示例7: getConditionBuilder
/**
* Get the conditon builder object for the given form.
*
* @param Form $form
* @return ConditionBuilderInterface
*/
protected function getConditionBuilder(Form $form)
{
$builderClosure = $form->getConfig()->getAttribute('filter_condition_builder');
$builder = new ConditionBuilder();
if ($builderClosure instanceof \Closure) {
$builderClosure($builder);
} else {
$this->buildDefaultConditionNode($form, $builder->root('AND'));
}
return $builder;
}
示例8: getSessionName
private function getSessionName(Form $form)
{
return 'filter_form_' . $form->getConfig()->getName();
}
示例9: load
/**
* @param Request $request
* @param Form $form
* @return $this
*/
public function load(Request $request, Form $form)
{
$this->_load($request, $form->getConfig()->getMethod(), $form->getName());
$form->handleRequest($request);
return $this;
}
示例10: modelizeForm
/**
* @param Form $form
* @param array $metadata
* @param string $prefix
*
* @return array|string
*/
protected function modelizeForm(Form $form, &$metadata, $prefix = null)
{
if ($form->getConfig()->getCompound()) {
$all = $form->all();
$model = [];
foreach ($all as $formField) {
/** @var Form $formField */
$model[$formField->getName()] = $this->modelizeForm($formField, $metadata, null === $prefix ? '' : $prefix . ($prefix ? '.' : '') . $form->getName());
}
ksort($model);
return $model;
} else {
$value = 'string';
if ($form->getConfig()->getOption('choices')) {
$value = array_keys($form->getConfig()->getOption('choices'));
$metadata[$prefix . ($prefix ? '.' : '') . $form->getName()] = ['type' => lcfirst(preg_replace('/^api/', '', $form->getConfig()->getType()->getName())), 'constraints' => $this->buildConstraints($form) + [['type' => 'choices', 'vars' => ['values' => $value]]], 'default' => !is_object($form->getConfig()->getOption('empty_data')) ? $form->getConfig()->getOption('empty_data') : null];
} elseif ($form->getConfig()->getOption('type')) {
/** @var AbstractType $type */
$type = $this->modelizeForm($form->getConfig()->getOption('type'), $metadata, ($prefix ? '.' : '') . $prefix);
unset($type);
$metadata[$prefix . ($prefix ? '.' : '') . $form->getName()] = ['type' => lcfirst(preg_replace('/^api/', '', $form->getConfig()->getType()->getName())), 'constraints' => $this->buildConstraints($form), 'default' => !is_object($form->getConfig()->getOption('empty_data')) ? $form->getConfig()->getOption('empty_data') : null];
$value = [];
} else {
$metadata[$prefix . ($prefix ? '.' : '') . $form->getName()] = ['type' => lcfirst(preg_replace('/^api/', '', $form->getConfig()->getType()->getName())), 'constraints' => $this->buildConstraints($form), 'default' => !is_object($form->getConfig()->getOption('empty_data')) ? $form->getConfig()->getOption('empty_data') : null];
}
return $value;
}
}
示例11: getCsrfToken
/**
* @param Form $form The form to inspect
* @return string The resulting CSRF token
*/
private function getCsrfToken(Form $form)
{
/** @var \Symfony\Component\Form\FormConfigInterface $c */
$c = $form->getConfig();
/** @var \Symfony\Component\Security\CSRF\CsrfTokenManager $tokMgr */
$tokMgr = $c->getOption("csrf_token_manager");
/** @var \Symfony\Component\Security\CSRF\CsrfToken $csrf_token */
$token = $tokMgr->getToken('form');
return $token->getValue();
}
示例12: getFormat
/**
* @param Form $item
* @param array $validationOutput
* @param $camelCasedKey
*
* @return null|string
*/
private function getFormat(Form $item, array $validationOutput, $camelCasedKey)
{
$type = $item->getConfig()->getType()->getInnerType();
if (BooleanType::class === $type) {
return '[false|true|0|1]';
}
return isset($validationOutput[$camelCasedKey]['format']) ? $validationOutput[$camelCasedKey]['format'] : null;
}