本文整理汇总了PHP中Symfony\Component\Form\FormInterface::getName方法的典型用法代码示例。如果您正苦于以下问题:PHP FormInterface::getName方法的具体用法?PHP FormInterface::getName怎么用?PHP FormInterface::getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormInterface
的用法示例。
在下文中一共展示了FormInterface::getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process
/**
* @param LineItem $lineItem
*
* @return bool
*/
public function process(LineItem $lineItem)
{
if (in_array($this->request->getMethod(), ['POST', 'PUT'], true)) {
/** @var EntityManagerInterface $manager */
$manager = $this->registry->getManagerForClass('OroB2BShoppingListBundle:LineItem');
$manager->beginTransaction();
// handle case for new shopping list creation
$formName = $this->form->getName();
$formData = $this->request->request->get($formName, []);
if (empty($formData['shoppingList']) && !empty($formData['shoppingListLabel'])) {
$shoppingList = $this->shoppingListManager->createCurrent($formData['shoppingListLabel']);
$formData['shoppingList'] = $shoppingList->getId();
$this->request->request->set($formName, $formData);
}
$this->form->submit($this->request);
if ($this->form->isValid()) {
/** @var LineItemRepository $lineItemRepository */
$lineItemRepository = $manager->getRepository('OroB2BShoppingListBundle:LineItem');
$existingLineItem = $lineItemRepository->findDuplicate($lineItem);
if ($existingLineItem) {
$this->updateExistingLineItem($lineItem, $existingLineItem);
} else {
$manager->persist($lineItem);
}
$manager->flush();
$manager->commit();
return true;
} else {
$manager->rollBack();
}
}
return false;
}
示例2: 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()));
}
示例3: getFormSubmittedData
/**
* @throws \LogicException
*
* @return array
*/
public function getFormSubmittedData()
{
if ('POST' !== $this->request->getMethod()) {
throw new \LogicException('Unable to fetch submitted data, only POST request supported');
}
return $this->request->get($this->form->getName(), []);
}
示例4: buildView
/**
* Pass the image URL to the view.
*
* @param FormView $view
* @param FormInterface $form
* @param array $options
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$data = $form->getParent()->getData();
if ($data instanceof ContentSpec) {
$tmpName = explode('_', $form->getName());
if (count($tmpName) === 3) {
$currentFile = null;
foreach ($data->getTranslations() as $tr) {
if ($tr->getLocale() == $tmpName[1] && ($tr->getField() == 'content' || $tr->getField() == 'data')) {
$contents = json_decode($tr->getContent(), true);
if (isset($contents[$tmpName[2]])) {
$currentFile = $contents[$tmpName[2]];
}
}
}
} else {
$currentFile = $data->getInContent($form->getName());
if (!$currentFile) {
$currentFile = $data->getInData($form->getName());
}
}
if ($currentFile) {
$currentFileWeb = $this->nyrocms->getHandler($data->getContentHandler())->getUploadDir() . '/' . $currentFile;
$view->vars['currentFile'] = $currentFileWeb;
$view->vars['showDelete'] = $options['showDelete'] && is_string($options['showDelete']) ? $options['showDelete'] : false;
}
}
}
示例5: buildView
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);
}
示例6: __construct
/**
* @param FormInterface $form The form
* @param FormAction|null $action The submit action of the form
* @param string|null $method The submit method of the form
* @param string|null $enctype The encryption type of the form
*/
public function __construct(FormInterface $form, FormAction $action = null, $method = null, $enctype = null)
{
$this->form = $form;
$this->action = $action;
$this->method = $method;
$this->enctype = $enctype;
$this->hash = $this->buildHash($this->form->getName(), $action, $method, $enctype);
}
示例7: moveCurrentValueToDefaultLocaleValue
/**
* @param FormView $view
* @param FormInterface $form
* @param array $options
*/
protected function moveCurrentValueToDefaultLocaleValue(FormView $view, FormInterface $form, array $options)
{
$file = $view[$form->getName()]->vars['data'];
$view->vars['label_attr']['data-default-locale-value'] = $this->filePathResolver->fileBasename($file);
$view->vars['label_attr']['data-default-locale-url'] = $this->filePathResolver->fileUrl($file);
$view[$form->getName()]->vars['value'] = null;
$view[$form->getName()]->vars['data'] = null;
$view[$options['remove_name']]->vars['checked'] = true;
}
示例8: 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());
}
示例9: getTarget
/**
* @return FormInterface
*
* @throws ErrorMappingException
*/
public function getTarget()
{
$childNames = explode('.', $this->targetPath);
$target = $this->origin;
foreach ($childNames as $childName) {
if (!$target->has($childName)) {
throw new ErrorMappingException(sprintf('The child "%s" of "%s" mapped by the rule "%s" in "%s" does not exist.', $childName, $target->getName(), $this->targetPath, $this->origin->getName()));
}
$target = $target->get($childName);
}
return $target;
}
示例10: updateTooltip
/**
* @param FormInterface $field
* @param FormView $view
*/
protected function updateTooltip(FormInterface $field, FormView $view)
{
$parentOptions = $field->getParent()->getConfig()->getOptions();
$parentClassName = isset($parentOptions['data_class']) ? $parentOptions['data_class'] : null;
if (!isset($view->vars['tooltip']) && $parentClassName && $this->entityConfigProvider->hasConfig($parentClassName, $field->getName())) {
$tooltip = $this->entityConfigProvider->getConfig($parentClassName, $field->getName())->get('description');
//@deprecated 1.9.0:1.11.0 tooltips.*.yml will be removed. Use Resources/translations/messages.*.yml instead
if ($this->translator->hasTrans($tooltip, self::DEFAULT_TRANSLATE_DOMAIN) || $this->translator->hasTrans($tooltip, self::TOOLTIPS_TRANSLATE_DOMAIN)) {
$view->vars['tooltip'] = $tooltip;
}
}
}
示例11: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
if (!isset($this->buttons[$form->getName()])) {
return;
}
$storedButtons = $this->buttons[$form->getName()];
if (isset($storedButtons['prepend']) && $storedButtons['prepend'] !== null) {
$view->vars['input_group_button_prepend'] = $storedButtons['prepend']->getForm()->createView();
}
if (isset($storedButtons['append']) && $storedButtons['append'] !== null) {
$view->vars['input_group_button_append'] = $storedButtons['append']->getForm()->createView();
}
}
示例12: buildView
/**
* {@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'));
}
示例13: realParseErrors
/**
* This does the actual job. Method travels through all levels of form recursively and gathers errors.
* @param FormInterface $form
* @param array &$results
*
* @return FormError[]
*/
private function realParseErrors(FormInterface $form, array &$results)
{
/*
* first check if there are any errors bound for this element
*/
$errors = $form->getErrors();
if (count($errors)) {
$config = $form->getConfig();
$name = $form->getName();
$label = $config->getOption('label');
$translation = $this->getTranslationDomain($form);
/*
* If a label isn't explicitly set, use humanized field name
*/
if (empty($label)) {
$label = ucfirst(trim(strtolower(preg_replace(['/([A-Z])/', '/[_\\s]+/'], ['_$1', ' '], $name))));
}
$results[] = array('name' => $name, 'label' => $label, 'errors' => $errors);
}
/*
* Then, check if there are any children. If yes, then parse them
*/
$children = $form->all();
if (count($children)) {
foreach ($children as $child) {
if ($child instanceof FormInterface) {
$this->realParseErrors($child, $results);
}
}
}
return $results;
}
示例14: finishView
/**
* {@inheritdoc}
*/
public function finishView(FormView $view, FormInterface $form, array $options)
{
$data = $view->parent->vars['value'];
if (is_object($data)) {
$view->vars['grid_url'] = $this->router->generate('oro_entity_relation', ['id' => $data->getId() ? $data->getId() : 0, 'entityName' => str_replace('\\', '_', get_class($data)), 'fieldName' => $form->getName()]);
}
}
示例15: validate
public function validate(FormInterface $form)
{
if (!$form->isSynchronized()) {
$form->addError(new FormError(sprintf('The value for "%s" is invalid', $form->getName())));
}
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'));
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'));
}
}
}