本文整理汇总了PHP中Symfony\Component\Form\FormFactory::createNamedBuilder方法的典型用法代码示例。如果您正苦于以下问题:PHP FormFactory::createNamedBuilder方法的具体用法?PHP FormFactory::createNamedBuilder怎么用?PHP FormFactory::createNamedBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormFactory
的用法示例。
在下文中一共展示了FormFactory::createNamedBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testLayout
/**
* @dataProvider layoutProvider
*/
public function testLayout($formOptions, $formItems, $expectedBlocks)
{
$formBuilder = $this->factory->createNamedBuilder('test', 'form', null, $formOptions);
$this->buildForm($formBuilder, $formItems);
$formView = $formBuilder->getForm()->createView();
$result = $this->builder->build($formView);
$expected = $this->getBlocks($expectedBlocks);
$this->assertEquals($expected, $result->toArray());
}
示例2: buildForm
/**
* Builds form given success and fail urls
*
* @param $responseRoute
* @return FormBuilder
*/
public function buildForm($responseRoute)
{
$formBuilder = $this->formFactory->createNamedBuilder(null);
$orderId = $this->paymentBridge->getOrderId() . '#' . date('Ymdhis');
$fields = array('usuario' => $this->user, 'gran_total' => $this->paymentBridge->getAmount(), 'referencia' => $this->paymentBridge->getOrderDescription(), 'url_respuesta' => $responseRoute);
//echo $this->cps;die();
$formKey = $this->encryptor->encrypt(implode('', $fields));
$formBuilder->setAction($this->gateway)->setMethod('POST')->add('usuario', 'hidden', array('data' => $this->user))->add('gran_total', 'hidden', array('data' => $this->paymentBridge->getAmount()))->add('referencia_ext', 'hidden', array('data' => $this->paymentBridge->getOrderDescription()))->add('url_respuesta', 'hidden', array('data' => $responseRoute))->add('key', 'hidden', array('data' => $formKey))->add('order_id', 'hidden', array('data' => $orderId))->add('Submit', 'hidden', array('data' => 'Pagar'));
return $formBuilder;
}
示例3: buildForm
/**
* Builds form given return, success and fail urls.
*
* @return FormView
*/
public function buildForm()
{
$formBuilder = $this->formFactory->createNamedBuilder(null);
$orderId = $this->paymentBridge->getOrderId();
$orderCurrency = $this->paymentBridge->getCurrency();
$this->checkCurrency($orderCurrency);
/**
* Creates the success return route, when coming back
* from PayPal web checkout.
*/
$successReturnUrl = $this->urlFactory->getSuccessReturnUrlForOrderId($orderId);
/**
* Creates the cancel payment route, when cancelling
* the payment process from PayPal web checkout.
*/
$cancelReturnUrl = $this->urlFactory->getCancelReturnUrlForOrderId($orderId);
/**
* Creates the IPN payment notification route,
* which is triggered after PayPal processes the
* payment and returns the validity of the transaction.
*
* For forther information
*
* https://developer.paypal.com/docs/classic/ipn/integration-guide/IPNandPDTVariables/
* https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNIntro/
*/
$processUrl = $this->urlFactory->getProcessUrlForOrderId($orderId);
$formBuilder->setAction($this->urlFactory->getApiEndpoint())->setMethod('POST')->add('business', 'hidden', ['data' => $this->business])->add('return', 'hidden', ['data' => $successReturnUrl])->add('cancel_return', 'hidden', ['data' => $cancelReturnUrl])->add('notify_url', 'hidden', ['data' => $processUrl])->add('currency_code', 'hidden', ['data' => $orderCurrency])->add('env', 'hidden', ['data' => '']);
/**
* Create a PayPal cart line for each order line.
*
* Project specific PaymentBridgeInterface::getExtraData
* should return an array of this form
*
* ['items' => [
* 0 => [ 'item_name' => 'Item 1', 'amount' => 1234, 'quantity' => 2 ],
* 1 => [ 'item_name' => 'Item 2', 'amount' => 2345, 'quantity' => 1 ],
* ]]
*
* The 'items' key consists of an array with the basic information
* of each line of the order. Amount is the price of the product,
* not the total of the order line
*/
$cartData = $this->paymentBridge->getExtraData();
$itemsData = $cartData['items'];
$iteration = 1;
foreach ($itemsData as $orderLine) {
$formBuilder->add('item_name_' . $iteration, 'hidden', ['data' => $orderLine['item_name']])->add('amount_' . $iteration, 'hidden', ['data' => $orderLine['amount'] / 100])->add('quantity_' . $iteration, 'hidden', ['data' => $orderLine['quantity']]);
++$iteration;
}
if (isset($cartData['discount_amount_cart'])) {
$formBuilder->add('discount_amount_cart', 'hidden', ['data' => $cartData['discount_amount_cart'] / 100]);
}
return $formBuilder->getForm()->createView();
}
示例4: testRender
public function testRender()
{
$options = array('block_config' => array('first' => array('priority' => 1, 'title' => 'First Block', 'subblocks' => array('first' => array(), 'second' => array('title' => 'Second SubBlock')), 'description' => 'some desc'), 'second' => array('priority' => 2)));
$builder = $this->factory->createNamedBuilder('test', 'form', null, $options);
$builder->add('text_1', null, array('block' => 'first', 'subblock' => 'second'));
$builder->add('text_2', null, array('block' => 'first'));
$builder->add('text_3', null, array('block' => 'second'));
$builder->add('text_4', null, array('block' => 'third'));
$builder->add('text_5', null, array('block' => 'third', 'subblock' => 'first'));
$builder->add('text_6', null);
$formView = $builder->getForm()->createView();
$result = $this->renderer->render($this->twig, array('form' => $formView), $formView);
$this->assertEquals($this->testFormConfig, $result);
}
示例5: createFormBuilder
/**
* Obtains any form metadata from the entity and adds itself to the form
* @param null $data
* @param string $name
* @param array $options
* @return \Symfony\Component\Form\FormBuilderInterface
*/
public function createFormBuilder($data = null, $name = '', array $options = array())
{
if (array_key_exists('method', $options)) {
$method = $options['method'];
unset($options['method']);
}
// Build the $form
$formBuilder = $this->factory->createNamedBuilder($name, FormType::class, $data, $options);
if (isset($method)) {
$formBuilder->setMethod($method);
}
// Read the entity meta data and add to the form
if (empty($this->drivers)) {
return $formBuilder;
}
// Look to the readers to find metadata
foreach ($this->drivers as $driver) {
$metadata = $driver->getMetadata($data);
if (!empty($metadata)) {
break;
}
}
if (empty($metadata)) {
return $formBuilder;
}
// Configure the form
$fields = $metadata->getFields();
foreach ($fields as $field) {
// TODO: Detect "new x()" in field value or type option for AbstractType creation
// TODO: Detect references to "%service.id%" for service constructor dependency
$fieldOptions = $field->options;
if (in_array($formBuilder->getMethod(), ['POST']) && array_key_exists('onCreate', $fieldOptions)) {
if ($fieldOptions['onCreate']) {
$fieldOptions = array_replace($fieldOptions, $fieldOptions['onCreate']);
} else {
continue;
}
} elseif (in_array($formBuilder->getMethod(), ['PUT', 'PATCH']) && array_key_exists('onEdit', $fieldOptions)) {
if ($fieldOptions['onEdit']) {
$fieldOptions = array_replace($fieldOptions, $fieldOptions['onEdit']);
} else {
continue;
}
}
unset($fieldOptions['onCreate']);
unset($fieldOptions['onEdit']);
$formBuilder->add($field->name, $field->value, $fieldOptions);
}
return $formBuilder;
}
示例6: getDatalist
/**
* @return DatalistInterface
*/
public function getDatalist()
{
$datalist = new Datalist($this->getDatalistConfig());
// Add fields
foreach ($this->fields as $fieldName => $fieldConfig) {
$field = $this->createField($fieldName, $fieldConfig);
$field->setDatalist($datalist);
$datalist->addField($field);
}
// Add search form
if (null !== $this->getOption('search')) {
$searchFormBuilder = $this->formFactory->createNamedBuilder('', FormType::class, null, ['csrf_protection' => false]);
$searchFilter = $this->createFilter('search', ['type' => 'search', 'options' => ['search_fields' => $datalist->getOption('search')]]);
$searchFilter->getType()->buildForm($searchFormBuilder, $searchFilter, $searchFilter->getOptions());
$searchFilter->setDatalist($datalist);
$datalist->setSearchFilter($searchFilter);
$datalist->setSearchForm($searchFormBuilder->getForm());
}
// Add filters and filter form
$filterFormBuilder = $this->formFactory->createNamedBuilder('', FormType::class, null, ['translation_domain' => $datalist->getOption('translation_domain'), 'csrf_protection' => false]);
foreach ($this->filters as $filterName => $filterConfig) {
$filter = $this->createFilter($filterName, $filterConfig);
$filter->setDatalist($datalist);
$filter->getType()->buildForm($filterFormBuilder, $filter, $filter->getOptions());
$datalist->addFilter($filter);
}
$datalist->setFilterForm($filterFormBuilder->getForm());
// Add actions
foreach ($this->actions as $actionName => $actionConfig) {
$action = $this->createAction($actionName, $actionConfig);
$action->setDatalist($datalist);
$datalist->addAction($action);
}
return $datalist;
}
示例7: array
function it_returns_form_builder_with_additional_file_options_and_file_constraints(FormFactory $factory, FormBuilder $form, NotBlank $constraint)
{
$this->addConstraint($constraint);
$this->setFormOptions(array('file_type' => 'fsi_image', 'file_options' => array('file_option' => 'value')));
$factory->createNamedBuilder('fileValue', 'fsi_removable_file', null, array('label' => false, 'required' => false, 'file_type' => 'fsi_image', 'file_options' => array('file_option' => 'value', 'constraints' => array($constraint))))->shouldBeCalled()->willReturn($form);
$this->getFormBuilder($factory)->shouldReturn($form);
}
示例8: getFilterForm
/**
* @return Form|\Symfony\Component\Form\Form
*/
public function getFilterForm()
{
if (null === $this->filterForm) {
$this->filterForm = $this->buildFilterForm($this->formFactory->createNamedBuilder($this->getTableId() . '_filter')->add('dofilter', 'button'))->getForm();
}
return $this->filterForm;
}
示例9: getBaseDatagrid
/**
* {@inheritdoc}
*/
public function getBaseDatagrid(AdminInterface $admin, array $values = array())
{
$defaultOptions = array();
if ($this->csrfTokenEnabled) {
$defaultOptions['csrf_protection'] = false;
}
$formBuilder = $this->formFactory->createNamedBuilder('filter', 'form', array(), $defaultOptions);
return new Datagrid($admin->createQuery(), $admin->getList(), $this->getPager(), $formBuilder, $values);
}
示例10: buildForm
/**
* Builds form given return, success and fail urls
*
* @return \Symfony\Component\Form\FormView
*/
public function buildForm()
{
$orderId = $this->paymentBridge->getOrderId();
$extraData = $this->paymentBridge->getExtraData();
$formBuilder = $this->formFactory->createNamedBuilder(null);
if (array_key_exists('transaction_type', $extraData)) {
$Ds_Merchant_TransactionType = $extraData['transaction_type'];
} else {
$Ds_Merchant_TransactionType = '0';
}
/*
* Creates the return route for Redsys
*/
$Ds_Merchant_MerchantURL = $this->urlFactory->getReturnRedsysUrl($orderId);
/*
* Creates the return route, when coming back
* from Redsys web checkout and proccess is Ok
*/
$Ds_Merchant_UrlOK = $this->urlFactory->getReturnUrlOkForOrderId($orderId);
/*
* Creates the cancel payment route, when coming back
* from Redsys web checkout and proccess is error
*/
$Ds_Merchant_UrlKO = $this->urlFactory->getReturnUrlKoForOrderId($orderId);
$Ds_Merchant_Amount = $this->paymentBridge->getAmount();
$Ds_Merchant_Order = $this->formatOrderNumber($this->paymentBridge->getOrderNumber());
$Ds_Merchant_MerchantCode = $this->merchantCode;
$Ds_Merchant_Currency = $this->currencyTranslation($this->paymentBridge->getCurrency());
$Ds_Merchant_Terminal = $extraData['terminal'];
$merchantParameters = [];
$merchantParameters['DS_MERCHANT_AMOUNT'] = $Ds_Merchant_Amount;
$merchantParameters['DS_MERCHANT_MERCHANTCODE'] = $Ds_Merchant_MerchantCode;
$merchantParameters['DS_MERCHANT_CURRENCY'] = $Ds_Merchant_Currency;
$merchantParameters['DS_MERCHANT_TERMINAL'] = $Ds_Merchant_Terminal;
$merchantParameters['DS_MERCHANT_ORDER'] = $Ds_Merchant_Order;
$merchantParameters['DS_MERCHANT_MERCHANTURL'] = $Ds_Merchant_MerchantURL;
$merchantParameters['DS_MERCHANT_URLOK'] = $Ds_Merchant_UrlOK;
$merchantParameters['DS_MERCHANT_URLKO'] = $Ds_Merchant_UrlKO;
$merchantParameters['DS_MERCHANT_TRANSACTIONTYPE'] = $Ds_Merchant_TransactionType;
if (array_key_exists('product_description', $extraData)) {
$merchantParameters['DS_MERCHANT_PRODUCTDESCRIPTION'] = $extraData['product_description'];
}
if (array_key_exists('merchant_titular', $extraData)) {
$merchantParameters['DS_MERCHANT_TITULAR'] = $extraData['merchant_titular'];
}
if (array_key_exists('merchant_name', $extraData)) {
$merchantParameters['DS_MERCHANT_MERCHANTNAME'] = $extraData['merchant_name'];
}
if (array_key_exists('merchant_data', $extraData)) {
$merchantParameters['DS_MERCHANT_MERCHANTDATA'] = $extraData['merchant_data'];
}
$merchantParameters = base64_encode(json_encode($merchantParameters));
$Ds_Merchant_MerchantSignature = $this->redsysSignature->sign($Ds_Merchant_Order, $this->secretKey, $merchantParameters);
$formBuilder->setAction($this->url)->setMethod('POST')->add('DS_MERCHANTPARAMETERS', 'hidden', array('data' => $merchantParameters))->add('DS_SIGNATUREVERSION', 'hidden', array('data' => $this->redsysSignature->getSignatureVersion()))->add('DS_SIGNATURE', 'hidden', array('data' => $Ds_Merchant_MerchantSignature));
return $formBuilder->getForm()->createView();
}
示例11: createForm
public function createForm($path)
{
$fb = $this->formFactory->createNamedBuilder(self::FORM_NAME, 'form', $this->translationTree);
$this->generateFormChildren($fb, $this->translationTree);
$fb->add('submit', 'submit');
$this->form = $fb->getForm();
$array_path = explode('/--/', $path);
$this->filterForm($this->form, $array_path);
return $this;
}
示例12: buildForm
/**
* Builds form given return, success and fail urls.
*
* @return FormView
*/
public function buildForm()
{
$orderId = $this->paymentBridge->getOrderId();
$extraData = $this->paymentBridge->getExtraData();
$formBuilder = $this->formFactory->createNamedBuilder(null);
if (array_key_exists('transaction_type', $extraData)) {
$Ds_Merchant_TransactionType = $extraData['transaction_type'];
} else {
$Ds_Merchant_TransactionType = '0';
}
/**
* Creates the return route for Redsys.
*/
$Ds_Merchant_MerchantURL = $this->urlFactory->getReturnRedsysUrl();
/**
* Creates the return route, when coming back
* from Redsys web checkout and proccess is Ok.
*/
$Ds_Merchant_UrlOK = $this->urlFactory->getReturnUrlOkForOrderId($orderId);
/**
* Creates the cancel payment route, when coming back
* from Redsys web checkout and proccess is error.
*/
$Ds_Merchant_UrlKO = $this->urlFactory->getReturnUrlKoForOrderId($orderId);
/**
* Creates the merchant signature.
*/
$Ds_Merchant_Amount = $this->paymentBridge->getAmount();
$Ds_Merchant_Order = $this->formatOrderNumber($this->paymentBridge->getOrderNumber());
$Ds_Merchant_MerchantCode = $this->merchantCode;
$Ds_Merchant_Currency = $this->getCurrencyCodeByIso($this->paymentBridge->getCurrency());
$Ds_Merchant_MerchantSignature = $this->shopSignature($Ds_Merchant_Amount, $Ds_Merchant_Order, $Ds_Merchant_MerchantCode, $Ds_Merchant_Currency, $Ds_Merchant_TransactionType, $Ds_Merchant_MerchantURL, $this->secretKey);
$Ds_Merchant_Terminal = $extraData['terminal'];
$formBuilder->setAction($this->url)->setMethod('POST')->add('Ds_Merchant_Amount', 'hidden', ['data' => $Ds_Merchant_Amount])->add('Ds_Merchant_MerchantSignature', 'hidden', ['data' => $Ds_Merchant_MerchantSignature])->add('Ds_Merchant_MerchantCode', 'hidden', ['data' => $this->merchantCode])->add('Ds_Merchant_Currency', 'hidden', ['data' => $Ds_Merchant_Currency])->add('Ds_Merchant_Terminal', 'hidden', ['data' => $Ds_Merchant_Terminal])->add('Ds_Merchant_Order', 'hidden', ['data' => $Ds_Merchant_Order])->add('Ds_Merchant_MerchantURL', 'hidden', ['data' => $Ds_Merchant_MerchantURL])->add('Ds_Merchant_UrlOK', 'hidden', ['data' => $Ds_Merchant_UrlOK])->add('Ds_Merchant_UrlKO', 'hidden', ['data' => $Ds_Merchant_UrlKO]);
/**
* Optional form fields.
*/
if (array_key_exists('transaction_type', $extraData)) {
$formBuilder->add('Ds_Merchant_TransactionType', 'hidden', ['data' => $Ds_Merchant_TransactionType]);
}
if (array_key_exists('product_description', $extraData)) {
$formBuilder->add('Ds_Merchant_ProductDescription', 'hidden', ['data' => $extraData['product_description']]);
}
if (array_key_exists('merchant_titular', $extraData)) {
$formBuilder->add('Ds_Merchant_Titular', 'hidden', ['data' => $extraData['merchant_titular']]);
}
if (array_key_exists('merchant_name', $extraData)) {
$formBuilder->add('Ds_Merchant_MerchantName', 'hidden', ['data' => $extraData['merchant_name']]);
}
if (array_key_exists('merchant_data', $extraData)) {
$formBuilder->add('Ds_Merchant_MerchantData', 'hidden', ['data' => $extraData['merchant_data']]);
}
return $formBuilder->getForm()->createView();
}
示例13: getBaseDatagrid
/**
* {@inheritdoc}
*/
public function getBaseDatagrid(AdminInterface $admin, array $values = array())
{
$pager = $this->getPager($admin->getPagerType());
$pager->setCountColumn($admin->getModelManager()->getIdentifierFieldNames($admin->getClass()));
$defaultOptions = array();
if ($this->csrfTokenEnabled) {
$defaultOptions['csrf_protection'] = false;
}
$formBuilder = $this->formFactory->createNamedBuilder('filter', 'form', array(), $defaultOptions);
return new Datagrid($admin->createQuery(), $admin->getList(), $pager, $formBuilder, $values);
}
示例14: buildForm
/**
* Builds form given return, success and fail urls
*
* @return \Symfony\Component\Form\FormView
*/
public function buildForm()
{
$orderId = $this->paymentBridge->getOrderId();
$extraData = $this->paymentBridge->getExtraData();
$formBuilder = $this->formFactory->createNamedBuilder(null);
if (array_key_exists('transaction_type', $extraData)) {
$Ds_Merchant_TransactionType = $extraData['transaction_type'];
} else {
$Ds_Merchant_TransactionType = '0';
}
/*
* Creates the return route for Redsys
*/
$Ds_Merchant_MerchantURL = $this->urlFactory->getReturnRedsysUrl();
/*
* Creates the return route, when coming back
* from Redsys web checkout and proccess is Ok
*/
$Ds_Merchant_UrlOK = $this->urlFactory->getReturnUrlOkForOrderId($orderId);
/*
* Creates the cancel payment route, when coming back
* from Redsys web checkout and proccess is error
*/
$Ds_Merchant_UrlKO = $this->urlFactory->getReturnUrlKoForOrderId($orderId);
$Ds_Merchant_Amount = $this->paymentBridge->getAmount();
$Ds_Merchant_Order = $this->formatOrderNumber($this->paymentBridge->getOrderNumber());
$Ds_Merchant_MerchantCode = $this->merchantCode;
$Ds_Merchant_Terminal = $this->merchantTerminal;
$Ds_Merchant_Currency = $this->currencyTranslation($this->paymentBridge->getCurrency());
$Ds_Signature_version = "HMAC_SHA256_V1";
$this->setParameter("DS_MERCHANT_AMOUNT", $Ds_Merchant_Amount);
$this->setParameter("DS_MERCHANT_ORDER", $Ds_Merchant_Order);
$this->setParameter("DS_MERCHANT_MERCHANTCODE", $Ds_Merchant_MerchantCode);
$this->setParameter("DS_MERCHANT_CURRENCY", $Ds_Merchant_Currency);
$this->setParameter("DS_MERCHANT_TERMINAL", $Ds_Merchant_Terminal);
$this->setParameter("DS_MERCHANT_TRANSACTIONTYPE", $Ds_Merchant_TransactionType);
if (array_key_exists('product_description', $extraData)) {
$this->setParameter("Ds_Merchant_ProductDescription", $extraData['product_description']);
}
if (array_key_exists('merchant_titular', $extraData)) {
$this->setParameter("Ds_Merchant_Titular", $extraData['merchant_titular']);
}
if (array_key_exists('merchant_name', $extraData)) {
$this->setParameter("Ds_Merchant_MerchantName", $extraData['merchant_name']);
}
$this->setParameter("DS_MERCHANT_MERCHANTURL", $Ds_Merchant_MerchantURL);
$this->setParameter("DS_MERCHANT_URLOK", $Ds_Merchant_UrlOK);
$this->setParameter("DS_MERCHANT_URLKO", $Ds_Merchant_UrlKO);
$Ds_Merchant_MerchantSignature = $this->shopSignature($Ds_Merchant_Order, $this->secretKey);
$formBuilder->setAction($this->url)->setMethod('POST')->add('Ds_SignatureVersion', 'hidden', array("data" => $Ds_Signature_version))->add('Ds_MerchantParameters', 'hidden', array("data" => $this->merchantParams()))->add('Ds_Signature', 'hidden', array("data" => $Ds_Merchant_MerchantSignature));
return $formBuilder->getForm()->createView();
}
示例15: createNamedFormBuilder
public function createNamedFormBuilder($formName, Report $report, $data = array())
{
$formBuilder = $this->formFactory->createNamedBuilder($formName, FormType::class, $data, array('csrf_protection' => false));
foreach ($report->getParameters() as $parameter) {
$options = $this->buildOptions($parameter);
if (isset($data[$parameter->getName()])) {
$options['data'] = $data[$parameter->getName()];
}
$className = '\\Symfony\\Component\\Form\\Extension\\Core\\Type\\' . ucfirst($parameter->getType()) . 'Type';
if (class_exists($parameter->getType())) {
$type = $parameter->getType();
} else {
if (class_exists($className)) {
$type = $className;
} else {
$type = TextType::class;
}
}
$formBuilder->add($parameter->getName(), $type, $options);
}
$formBuilder->add('Search', SubmitType::class, array('attr' => array('class' => 'btn btn-primary')));
return $formBuilder;
}