本文整理汇总了PHP中Symfony\Component\Form\FormView::set方法的典型用法代码示例。如果您正苦于以下问题:PHP FormView::set方法的具体用法?PHP FormView::set怎么用?PHP FormView::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormView
的用法示例。
在下文中一共展示了FormView::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$view->set('widget', $form->getAttribute('widget'));
if ('single_text' === $form->getAttribute('widget')) {
$view->set('type', 'datetime');
}
}
示例2: buildView
/**
* @param \Symfony\Component\Form\FormView $view
* @param \Symfony\Component\Form\FormInterface $form
*/
public function buildView(FormView $view, FormInterface $form)
{
$sonataAdmin = $form->getAttribute('sonata_admin');
// avoid to add extra information not required by non admin field
if ($form->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->get('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->set('types', $types);
$view->set('sonata_admin_enabled', true);
$view->set('sonata_admin', $sonataAdmin);
$attr = $view->get('attr', array());
if (!isset($attr['class'])) {
$attr['class'] = $sonataAdmin['class'];
}
$view->set('attr', $attr);
} else {
$view->set('sonata_admin_enabled', false);
}
$view->set('sonata_admin', $sonataAdmin);
}
示例3: buildView
public function buildView(FormView $view, FormInterface $form, array $options)
{
foreach ($options as $key => $value) {
$view->set($key, $value);
}
$view->set('countries', $this->_getCountryList());
}
示例4: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$configs = $form->getAttribute('configs');
$datas = $form->getClientData();
if (!empty($datas)) {
if ($form->getAttribute('multiple')) {
$datas = is_scalar($datas) ? explode(',', $datas) : $datas;
$value = array();
foreach ($datas as $data) {
if (!$data instanceof File) {
$data = new File($form->getAttribute('rootDir') . '/' . $data);
}
$value[] = $configs['folder'] . '/' . $data->getFilename();
}
$value = implode(',', $value);
} else {
if (!$datas instanceof File) {
$datas = new File($form->getAttribute('rootDir') . '/' . $datas);
}
$value = $configs['folder'] . '/' . $datas->getFilename();
}
$view->set('value', $value);
}
$view->set('type', 'hidden')->set('configs', $form->getAttribute('configs'));
}
示例5: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$view->set('value', $form->getAttribute('value'))->set('checked', (bool) $form->getClientData());
if ($view->hasParent()) {
$view->set('full_name', $view->getParent()->get('full_name'));
}
}
示例6: buildView
public function buildView(FormView $view, FormInterface $form, array $options)
{
$view->set('parent_field', $form->getAttribute('parent_field'));
$view->set('entity_alias', $form->getAttribute('entity_alias'));
$view->set('no_result_msg', $form->getAttribute('no_result_msg'));
$view->set('empty_value', $form->getAttribute('empty_value'));
}
示例7: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$view
->set('allow_add', $form->getAttribute('allow_add'))
->set('allow_delete', $form->getAttribute('allow_delete'))
;
if ($form->hasAttribute('prototype')) {
$view->set('prototype', $form->getAttribute('prototype'));
}
}
示例8: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form, array $options)
{
$choiceList = $form->getAttribute('choice_list');
// We should not load anything right now when loading via ajax
$view->set('multiple', $form->getAttribute('multiple'))->set('expanded', $form->getAttribute('expanded'))->set('preferred_choices', array())->set('choices', array())->set('separator', '-------------------')->set('empty_value', $form->getAttribute('empty_value'));
if ($view->get('multiple') && !$view->get('expanded')) {
// Add "[]" to the name in case a select tag with multiple options is
// displayed. Otherwise only one of the selected options is sent in the
// POST request.
$view->set('full_name', $view->get('full_name') . '[]');
}
}
示例9: buildView
public function buildView(FormView $view, FormInterface $form)
{
$choices = $form->getAttribute('choice_list')->getChoices();
$preferred = array_flip($form->getAttribute('preferred_choices'));
$view->set('multiple', $form->getAttribute('multiple'))->set('expanded', $form->getAttribute('expanded'))->set('preferred_choices', array_intersect_key($choices, $preferred))->set('choices', array_diff_key($choices, $preferred))->set('separator', '-------------------')->set('empty_value', '');
if ($view->get('multiple') && !$view->get('expanded')) {
// Add "[]" to the name in case a select tag with multiple options is
// displayed. Otherwise only one of the selected options is sent in the
// POST request.
$view->set('full_name', $view->get('full_name') . '[]');
}
}
示例10: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
if (!$this->enabled) {
return;
}
if ($this->secure) {
$server = self::RECAPTCHA_API_SECURE_SERVER;
} else {
$server = self::RECAPTCHA_API_SERVER;
}
$view->set('url_challenge', $server . '/challenge?k=' . $this->publicKey);
$view->set('url_noscript', $server . '/noscript?k=' . $this->publicKey);
$view->set('public_key', $this->publicKey);
$view->set('ewz_recaptcha_enabled', $this->enabled);
}
示例11: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$value = $form->getClientData();
// set string representation
if (true === $value) {
$value = 'true';
} else {
if (false === $value) {
$value = 'false';
} else {
if (null === $value) {
$value = 'null';
} else {
if (is_array($value)) {
$value = implode(', ', $value);
} else {
if ($value instanceof \DateTime) {
$value = $value->format('Y-m-d H:i:s');
} else {
if (is_object($value)) {
if (method_exists($value, '__toString')) {
$value = $value->__toString();
} else {
$value = get_class($value);
}
}
}
}
}
}
}
$view->set('value', (string) $value);
}
示例12: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$values = $view->get('value');
$selecteds = array_flip($values);
$choices_selected = $choices_unselected = array();
//Rebuilds choices
foreach ($this->choices as $key => $choice) {
if (isset($selecteds[$key])) {
$choices_selected[$key] = $choice;
} else {
$choices_unselected[$key] = $choice;
}
}
$view->set('choices_selected', $choices_selected);
$view->set('choices_unselected', $choices_unselected);
}
示例13: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$name = $form->getName();
$readOnly = $form->getAttribute('read_only');
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;
}
// Complex fields are read-only if themselves or their parent is.
$readOnly = $readOnly || $view->getParent()->get('read_only');
} else {
$id = $name;
$fullName = $name;
// 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');
}
$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('read_only', $readOnly)->set('errors', $form->getErrors())->set('value', $form->getClientData())->set('disabled', $form->isDisabled())->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'));
}
示例14: zform
public function zform(\Symfony\Component\Form\FormView $field)
{
$attr = $field->get('attr', array());
$attr['class'] = 'zTextForm';
$field->set('attr', $attr);
return $this->helper->render(array('field' => $field, 'id' => 1));
}
示例15: 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'));
}