本文整理汇总了PHP中Symfony\Component\Form\FormView::get方法的典型用法代码示例。如果您正苦于以下问题:PHP FormView::get方法的具体用法?PHP FormView::get怎么用?PHP FormView::get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormView
的用法示例。
在下文中一共展示了FormView::get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
}
示例2: 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') . '[]');
}
}
示例3: 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') . '[]');
}
}
示例4: 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));
}
示例5: buildView
/**
* @param \Symfony\Component\Form\FormView $view
* @param \Symfony\Component\Form\FormInterface $form
*/
public function buildView(FormView $view, FormInterface $form)
{
$format = $form->getAttribute('format');
$imageSrc = $view->get('image_src');
if ($imageSrc !== null && $format !== null) {
$view->set('image_src', $this->imManager->getUrl($format, $imageSrc));
}
}
示例6: 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);
}
示例7: renderSection
protected function renderSection(FormView $view, $section, array $variables = array())
{
$template = null;
$blocks = $view->get('types');
if ('widget' === $section || 'row' === $section) {
array_unshift($blocks, '_' . $view->get('id'));
}
foreach ($blocks as &$block) {
$block = $block . '_' . $section;
$template = $this->lookupTemplate($block);
if ($template) {
break;
}
}
if (!$template) {
throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $blocks)));
}
if ('widget' === $section || 'row' === $section) {
$view->setRendered();
}
return $this->render($template, array_merge($view->all(), $variables));
}
示例8: getPassword
/**
* Get password.
* TODO: 無理矢理パスワードを取得してる為、もうちょい考えてみる
*/
public function getPassword(FormView $view)
{
$method = 'get' . ucfirst($view->get('name'));
return $view->getParent()->get('value')->{$method}();
}
示例9: render
public function render(FormView $form, $variables, FormRenderer $renderer)
{
return $form->get('multipart') ? 'enctype="multipart/form-data"' : '';
}
示例10: lookupTemplate
/**
* Returns the name of the template to use to render the block
*
* @param FormView $view The form view
* @param string $block The name of the block
*
* @return string|Boolean The template logical name or false when no template is found
*/
protected function lookupTemplate(FormView $view, $block)
{
$file = $block . '.html.php';
$id = $view->get('id');
if (!isset($this->templates[$id][$block])) {
$template = false;
$themes = $view->hasParent() ? array() : $this->resources;
if (isset($this->themes[$id])) {
$themes = array_merge($themes, $this->themes[$id]);
}
for ($i = count($themes) - 1; $i >= 0; --$i) {
if ($this->engine->exists($templateName = $themes[$i] . ':' . $file)) {
$template = $templateName;
break;
}
}
if (false === $template && $view->hasParent()) {
$template = $this->lookupTemplate($view->getParent(), $block);
}
$this->templates[$id][$block] = $template;
}
return $this->templates[$id][$block];
}
示例11: renderSection
/**
* Renders a template.
*
* 1. This function first looks for a block named "_<view id>_<section>",
* 2. if such a block is not found the function will look for a block named
* "<type name>_<section>",
* 3. the type name is recursively replaced by the parent type name until a
* corresponding block is found
*
* @param FormView $view The form view
* @param string $section The section to render (i.e. 'row', 'widget', 'label', ...)
* @param array $variables Additional variables
*
* @return string The html markup
*
* @throws FormException if no template block exists to render the given section of the view
*/
protected function renderSection(FormView $view, $section, array $variables = array())
{
$mainTemplate = in_array($section, array('row', 'widget'));
if ($mainTemplate && $view->isRendered()) {
return '';
}
$template = null;
$types = $view->get('types');
$types[] = '_'.$view->get('proto_id', $view->get('id'));
for ($i = count($types) - 1; $i >= 0; $i--) {
$types[$i] .= '_'.$section;
$template = $this->lookupTemplate($types[$i]);
if ($template) {
$html = $this->render($view, $template, $variables);
if ($mainTemplate) {
$view->setRendered();
}
return $html;
}
}
throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $types)));
}
示例12: render
protected function render(FormView $view, $section, array $variables = array())
{
$mainTemplate = in_array($section, array('widget', 'row'));
if ($mainTemplate && $view->isRendered()) {
return '';
}
$id = '_' . $view->get('proto_id', $view->get('id'));
$template = $id . $section;
$renderer = $this->getRenderer();
if (isset($this->varStack[$template])) {
$typeIndex = $this->varStack[$template]['typeIndex'] - 1;
$types = $this->varStack[$template]['types'];
$this->varStack[$template]['variables'] = array_replace_recursive($this->varStack[$template]['variables'], $variables);
} else {
$types = $view->get('types');
$types[] = $id;
$typeIndex = count($types) - 1;
$this->varStack[$template] = array('variables' => array_replace_recursive($view->all(), $variables), 'types' => $types);
}
do {
$types[$typeIndex] .= '_' . $section;
if (isset($renderer[$types[$typeIndex]])) {
$this->varStack[$template]['typeIndex'] = $typeIndex;
$html = $renderer[$types[$typeIndex]]->render($view, $this->varStack[$template]['variables'], $this);
if ($mainTemplate) {
$view->setRendered();
}
unset($this->varStack[$template]);
return $html;
}
} while (--$typeIndex >= 0);
throw new FormException(sprintf('Unable to render the form as none of the following renderer exist: "%s".', implode('", "', array_reverse($types))));
}
示例13: renderSection
/**
* Renders a template.
*
* 1. This function first looks for a block named "_<view id>_<section>",
* 2. if such a block is not found the function will look for a block named
* "<type name>_<section>",
* 3. the type name is recursively replaced by the parent type name until a
* corresponding block is found
*
* @param FormView $view The form view
* @param string $section The section to render (i.e. 'row', 'widget', 'label', ...)
* @param array $variables Additional variables
*
* @return string The html markup
*
* @throws FormException if no template block exists to render the given section of the view
*/
protected function renderSection(FormView $view, $section, array $variables = array())
{
$mainTemplate = in_array($section, array('row', 'widget'));
if ($mainTemplate && $view->isRendered()) {
return '';
}
$template = null;
$blocks = $view->get('types');
array_unshift($blocks, '_' . $view->get('id'));
foreach ($blocks as &$block) {
$block = $block . '_' . $section;
$template = $this->lookupTemplate($block);
if ($template) {
break;
}
}
if (!$template) {
throw new FormException(sprintf('Unable to render form as none of the following blocks exist: "%s".', implode('", "', $blocks)));
}
$html = $this->render($view, $template, $variables);
if ($mainTemplate) {
$view->setRendered();
}
return $html;
}
示例14: buildView
/**
* {@inheritdoc}
*/
public function buildView(FormView $view, FormInterface $form)
{
$choiceList = $form->getAttribute('choice_list');
$view->set('multiple', $form->getAttribute('multiple'))->set('expanded', $form->getAttribute('expanded'))->set('preferred_choices', $choiceList->getPreferredViews())->set('choices', $choiceList->getRemainingViews())->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') . '[]');
}
}
示例15: isChoiceSelected
/**
*/
public function isChoiceSelected(FormView $view, $choice)
{
return FormUtil::isChoiceSelected($choice, $view->get('value'));
}