/** * Adds the specified component to the IComponentContainer. * @param IComponent * @param string * @param string * @return void * @throws Nette\InvalidStateException */ public function addComponent(Nette\ComponentModel\IComponent $component, $name, $insertBefore = NULL) { parent::addComponent($component, $name, $insertBefore); if ($this->currentGroup !== NULL && $component instanceof IControl) { $this->currentGroup->add($component); } }
/** * Adds naming container to the form. * @param string name * @return Container */ public function addContainer($name) { $control = new self(); $control->currentGroup = $this->currentGroup; if ($this->currentGroup !== NULL) { $this->currentGroup->add($control); } return $this[$name] = $control; }
public function renderGroup(ControlGroup $group) { $this->assertInForm(); $el = clone $this->prototypes->getControlGroup(); //group label $label = $group->getOption('label'); if ($label) { $this->addContent($el->getPlaceholder('label'), $label); } else { $el->removePlaceholder('label'); } // group description $description = $group->getOption('description'); if ($description) { $this->addContent($el->getPlaceholder('description'), $description); } else { $el->removePlaceholder('description'); } // master element attributes $groupAttrs = $group->getOption('container', Html::el())->setName(NULL); $el->addAttributes($groupAttrs->attrs); // group content $el->addHtml($this->renderPairs($group->getControls())); return $el; }
/** * Adds fieldset group to the form. * @param string caption * @param bool set this group as current * @return ControlGroup */ public function addGroup($caption = NULL, $setAsCurrent = TRUE) { $group = new ControlGroup(); $group->setOption('label', $caption); $group->setOption('visual', TRUE); if ($setAsCurrent) { $this->setCurrentGroup($group); } if (isset($this->groups[$caption])) { return $this->groups[] = $group; } else { return $this->groups[$caption] = $group; } }
/** * @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()); }
/** * @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); }