Skip to content

Commit

Permalink
moved some FormView methods to FormUtil where they really belongs
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jun 8, 2011
1 parent b15dbe3 commit 925e14d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Resources/views/Form/choice_widget.html.php
Expand Up @@ -15,27 +15,27 @@
<?php if (!$multiple && !$required): ?><option value=""><?php echo $empty_value; ?></option><?php endif; ?>
<?php if (count($preferred_choices) > 0): ?>
<?php foreach ($preferred_choices as $choice => $label): ?>
<?php if ($form->isChoiceGroup($label)): ?>
<?php if ($view['form']->isChoiceGroup($label)): ?>
<optgroup label="<?php echo $view->escape($choice) ?>">
<?php foreach ($label as $nestedChoice => $nestedLabel): ?>
<option value="<?php echo $view->escape($nestedChoice) ?>"<?php if ($form->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($nestedLabel) ?></option>
<option value="<?php echo $view->escape($nestedChoice) ?>"<?php if ($view['form']->isChoiceSelected($form, $nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($nestedLabel) ?></option>
<?php endforeach ?>
</optgroup>
<?php else: ?>
<option value="<?php echo $view->escape($choice) ?>"<?php if ($form->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($label) ?></option>
<option value="<?php echo $view->escape($choice) ?>"<?php if ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($label) ?></option>
<?php endif ?>
<?php endforeach ?>
<option disabled="disabled"><?php echo $separator ?></option>
<?php endif ?>
<?php foreach ($choices as $choice => $label): ?>
<?php if ($form->isChoiceGroup($label)): ?>
<?php if ($view['form']->isChoiceGroup($label)): ?>
<optgroup label="<?php echo $view->escape($choice) ?>">
<?php foreach ($label as $nestedChoice => $nestedLabel): ?>
<option value="<?php echo $view->escape($nestedChoice) ?>"<?php if ($form->isChoiceSelected($nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($nestedLabel) ?></option>
<option value="<?php echo $view->escape($nestedChoice) ?>"<?php if ($view['form']->isChoiceSelected($form, $nestedChoice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($nestedLabel) ?></option>
<?php endforeach ?>
</optgroup>
<?php else: ?>
<option value="<?php echo $view->escape($choice) ?>"<?php if ($form->isChoiceSelected($choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($label) ?></option>
<option value="<?php echo $view->escape($choice) ?>"<?php if ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($label) ?></option>
<?php endif ?>
<?php endforeach ?>
</select>
Expand Down
11 changes: 11 additions & 0 deletions Templating/Helper/FormHelper.php
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Templating\EngineInterface;
use Symfony\Component\Form\FormView;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Util\FormUtil;

/**
*
Expand All @@ -38,6 +39,16 @@ public function __construct(EngineInterface $engine)
$this->varStack = new \SplObjectStorage();
}

public function isChoiceGroup($label)
{
return FormUtil::isChoiceGroup($label);
}

public function isChoiceSelected(FormView $view, $choice)
{
return FormUtil::isChoiceSelected($choice, $view->get('value'));
}

/**
* Renders the attributes for the current view.
*
Expand Down

0 comments on commit 925e14d

Please sign in to comment.