Returns translate adapter.
public getTranslator ( ) : Nette\Localization\ITranslator | null | ||
Результат | Nette\Localization\ITranslator | null |
/** * @internal * @param \Nette\Forms\ControlGroup $group * @return object */ public function processGroup(\Nette\Forms\ControlGroup $group) { if (!$group->getOption('visual') || !$group->getControls()) { return NULL; } $groupLabel = $group->getOption('label'); $groupDescription = $group->getOption('description'); // If we have translator, translate! if ($translator = $this->form->getTranslator()) { if (!$groupLabel instanceof Html) { $groupLabel = $translator->translate($groupLabel); } if (!$groupDescription instanceof Html) { $groupDescription = $translator->translate($groupDescription); } } $controls = array_filter($group->getControls(), function (Controls\BaseControl $control) { return !$control->getOption('rendered') && !$control instanceof Controls\HiddenField; }); if (!$controls) { return NULL; // do not render empty groups } $groupAttrs = $group->getOption('container', Html::el())->setName(NULL); /** @var Html $groupAttrs */ $groupAttrs->attrs += array_diff_key($group->getOptions(), array_fill_keys(array('container', 'label', 'description', 'visual', 'template'), NULL)); // fake group return (object) (array('controls' => $controls, 'label' => $groupLabel, 'description' => $groupDescription, 'attrs' => $groupAttrs) + $group->getOptions()); }
/** * Renders form body. * @return string */ public function renderBody() { $s = $remains = ''; $defaultContainer = $this->getWrapper('group container'); $translator = $this->form->getTranslator(); foreach ($this->form->getGroups() as $group) { if (!$group->getControls() || !$group->getOption('visual')) { continue; } $container = $group->getOption('container', $defaultContainer); $container = $container instanceof Html ? clone $container : Html::el($container); $id = $group->getOption('id'); if ($id) { $container->id = $id; } $s .= "\n" . $container->startTag(); $text = $group->getOption('label'); if ($text instanceof Html) { $s .= $this->getWrapper('group label')->add($text); } elseif (is_string($text)) { if ($translator !== NULL) { $text = $translator->translate($text); } $s .= "\n" . $this->getWrapper('group label')->setText($text) . "\n"; } $text = $group->getOption('description'); if ($text instanceof Html) { $s .= $text; } elseif (is_string($text)) { if ($translator !== NULL) { $text = $translator->translate($text); } $s .= $this->getWrapper('group description')->setText($text) . "\n"; } $s .= $this->renderControls($group); $remains = $container->endTag() . "\n" . $remains; if (!$group->getOption('embedNext')) { $s .= $remains; $remains = ''; } } $s .= $remains . $this->renderControls($this->form); $container = $this->getWrapper('form container'); $container->setHtml($s); return $container->render(0); }
/** * @param \Nette\Forms\ControlGroup $group * * @return object */ protected function buildGroup(Nette\Forms\ControlGroup $group) { if (!$group->getOption('visual') || !$group->getControls()) { return NULL; } $groupLabel = $group->getOption('label'); $groupDescription = $group->getOption('description'); // If we have translator, translate! if ($translator = $this->form->getTranslator()) { if (!$groupLabel instanceof Html) { $groupLabel = $translator->translate($groupLabel); } if (!$groupDescription instanceof Html) { $groupDescription = $translator->translate($groupDescription); } } $controls = $group->getControls(); // fake group return (object) array('template' => $group->getOption('template'), 'controls' => array_filter($controls, function (Controls\BaseControl $control) { return !$control->getOption('rendered') && !$control instanceof Controls\HiddenField; }), 'label' => $groupLabel, 'description' => $groupDescription); }
/** * Make form and controls compatible with Twitter Bootstrap * @param Form $form */ protected function prepareForm(Form $form) { $form->getElementPrototype()->class[] = 'form-horizontal'; $translator = $form->getTranslator(); foreach ($form->controls as $control) { /** @var BaseControl $control */ if ($control instanceof HiddenField) { continue; } elseif ($control instanceof Button) { $control->controlPrototype->class[] = "btn-block btn-lg"; } else { if ($control->getLabel()) { $control->setAttribute('placeholder', $control->caption); if (empty($control->controlPrototype->attrs['title'])) { $control->setAttribute('title', $translator ? $translator->translate($control->caption) : $control->caption); } $control->getLabelPrototype()->attrs["style"] = "display:none"; } } } BootstrapHelper::ApplyBootstrapToControls($form); }
/** * Render the templates * * @param \Nette\Forms\Form $form * @return void */ public function render(\Nette\Forms\Form $form) { if ($form === $this->form) { // don't forget for second run, @hosiplan! ;) foreach ($this->form->getControls() as $control) { $control->setOption('rendered', FALSE); } echo $this->template; return; } // Store the current form instance $this->form = $form; // Translator available? if ($translator = $form->getTranslator()) { // intentional = $this->template->setTranslator($translator); } // Pre-proccess form $errors = $form->getErrors(); foreach ($form->getControls() as $control) { $control->setOption('rendered', FALSE); if (!$control->getOption('blockname', FALSE)) { $ex = explode('\\', get_class($control)); $control->setOption('blockname', end($ex)); } if ($this->errorsAtInputs) { $errors = array_diff($errors, $control->errors); } } // Assign to template $this->template->form = $form; $this->template->errors = $errors; $this->template->renderer = $this; $this->template->errorsAtInputs = $this->errorsAtInputs; // And echo the output echo $this->template; }