Browse files

merged branch vicb/form/php-choices (PR #1415)

Commits
-------

2cf7136 [FrameworkBundle][Form] tweak the choice widget PHP template

Discussion
----------

[FrameworkBundle][Form] tweak the choice widget PHP template

* make theming easier,
* factorize code,
* make PHP similar to Twig (easier to maintain)
  • Loading branch information...
2 parents 59f85b4 + 2cf7136 commit bc2f9479e3d294ccc5c1cd89cbe0849d959457a3 @fabpot fabpot committed Jun 23, 2011
View
11 src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_options.html.php
@@ -0,0 +1,11 @@
+<?php foreach ($options as $choice => $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 ($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 ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($label) ?></option>
+ <?php endif ?>
+<?php endforeach ?>
View
24 src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/choice_widget.html.php
@@ -12,29 +12,9 @@
>
<?php if (null !== $empty_value): ?><option value=""><?php echo $view->escape($view['translator']->trans($empty_value)) ?></option><?php endif; ?>
<?php if (count($preferred_choices) > 0): ?>
- <?php foreach ($preferred_choices as $choice => $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 ($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 ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($label) ?></option>
- <?php endif ?>
- <?php endforeach ?>
+ <?php echo $view['form']->renderBlock('choice_options', array('options' => $preferred_choices)) ?>
<option disabled="disabled"><?php echo $separator ?></option>
<?php endif ?>
- <?php foreach ($choices as $choice => $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 ($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 ($view['form']->isChoiceSelected($form, $choice)): ?> selected="selected"<?php endif?>><?php echo $view->escape($label) ?></option>
- <?php endif ?>
- <?php endforeach ?>
+ <?php echo $view['form']->renderBlock('choice_options', array('options' => $choices)) ?>
</select>
<?php endif ?>

1 comment on commit bc2f947

@j
j commented on bc2f947 Jun 23, 2011

I haven't used PHP for my views in a while and stick to twig, but when I did, I can say this looks much better. Great job.

Please sign in to comment.