当前位置: 首页>>代码示例>>PHP>>正文


PHP Form::getTranslator方法代码示例

本文整理汇总了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());
 }
开发者ID:josefzajac,项目名称:BootstrapFormRenderer,代码行数:34,代码来源:BootstrapRenderer.php

示例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);
 }
开发者ID:luminousinfoways,项目名称:pccfoas,代码行数:50,代码来源:DefaultFormRenderer.php

示例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);
 }
开发者ID:rostenkowski,项目名称:nette-forms-renderer,代码行数:27,代码来源:BootstrapRenderer.php

示例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);
 }
开发者ID:pipaslot,项目名称:forms,代码行数:26,代码来源:Bootstrap3StackRenderer.php

示例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;
 }
开发者ID:valicek1,项目名称:nestraps,代码行数:43,代码来源:Nestraps.php


注:本文中的Nette\Forms\Form::getTranslator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。