8000 [Form] Moved the access to templating helpers out of the choice loop … · Lumbendil/symfony@5dc3c39 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5dc3c39

Browse files
committed
[Form] Moved the access to templating helpers out of the choice loop for performance reasons (PHP +100ms)
1 parent 0ef9acb commit 5dc3c39

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
<?php $translatorHelper = $view['translator']; // outside of the loop for performance reasons! ?>
2+
<?php $formHelper = $view['form']; ?>
13
<?php foreach ($choices as $index => $choice): ?>
24
<?php if (is_array($choice)): ?>
3-
<optgroup label="<?php echo $view->escape($view['translator']->trans($index, array(), $translation_domain)) ?>">
4-
<?php echo $view['form']->block('choice_widget_options', array('choices' => $choice)) ?>
5+
<optgroup label="<?php echo $view->escape($translatorHelper->trans($index, array(), $translation_domain)) ?>">
6+
<?php echo $formHelper->block('choice_widget_options', array('choices' => $choice)) ?>
57
</optgroup>
68
<?php else: ?>
7-
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($choice->isSelected($value)): ?> selected="selected"<?php endif?>><?php echo $view->escape($view['translator']->trans($choice->label, array(), $translation_domain)) ?></option>
9+
<option value="<?php echo $view->escape($choice->value) ?>"<?php if ($choice->isSelected($value)): ?> selected="selected"<?php endif?>><?php echo $view->escape($translatorHelper->trans($choice->label, array(), $translation_domain)) ?></option>
810
<?php endif ?>
911
<?php endforeach ?>

0 commit comments

Comments
 (0)
0