本文整理汇总了PHP中Nette\Forms\Form::getTranslator方法的典型用法代码示例。如果您正苦于以下问题:PHP Form::getTranslator方法的具体用法?PHP Form::getTranslator怎么用?PHP Form::getTranslator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Form
的用法示例。
在下文中一共展示了Form::getTranslator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: processGroup
/**
* @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());
}
示例2: renderBody
/**
* 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);
}
示例3: buildGroup
/**
* @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);
}
示例4: prepareForm
/**
* 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);
}
示例5: render
/**
* 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;
}