本文整理汇总了PHP中Nette\Forms\Container::addContainer方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::addContainer方法的具体用法?PHP Container::addContainer怎么用?PHP Container::addContainer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Container
的用法示例。
在下文中一共展示了Container::addContainer方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addDateTime
public static function addDateTime(Nette\Forms\Container $container, $name, $label = NULL, \DateTime $dateTime = NULL, $onNullSetNow = FALSE)
{
$subContainer = $container->addContainer($name);
$date = static::addDate($subContainer, static::DATE, $label);
$time = static::addTime($subContainer, static::TIME);
if ($onNullSetNow && is_null($dateTime)) {
$dateTime = new Nette\Utils\DateTime();
}
if (!is_null($dateTime)) {
$dateValue = $dateTime->format('Y-m-d');
$date->setDefaultValue($dateValue[0] == '-' ? NULL : $dateValue);
$time->setDefaultValue($dateValue[0] == '-' ? NULL : $dateTime->format('H:i:s'));
}
$date->addConditionOn($time, UI\Form::FILLED)->addRule(UI\Form::FILLED, static::$useTranslatorRule ? __('Please, fill date otherwise you lose data.') : $name . '.' . static::$translatorRuleClass . '.filled')->addRule([DateTimeFields::class, 'validateUnixDateTime'], static::$useTranslatorRule ? __('Date must be older than 1970-01-01 00:00') : $name . '.' . static::$translatorRuleClass . '.invalid', new Nette\Utils\DateTime('1970-01-01 00:00'));
}
示例2: generateForm
/**
* @param Base|ListContainer $item
* @param Nette\Forms\Container $formContainer
* @param $name
* @param $parentName
* @param Nette\Forms\Rules $togglingObject
* @param array $userOptions
*/
public function generateForm(Base $item, Nette\Forms\Container &$formContainer, $name, $parentName, $togglingObject, array $userOptions = [])
{
$container = $formContainer->addContainer($name);
$newParent = NULL;
if (!isset($item->configuration['count']) && (!isset($item->configuration['max']) || $item->configuration['max'] > count($item->getChild()))) {
$newParent = $parentName . '__' . $name . Base::NEW_CONTAINER;
$new = $container->addSubmit(Base::NEW_ITEM_BUTTON, $this->getConfigValue('addItemLabel', 'new', $userOptions));
$new->setValidationScope(FALSE)->setAttribute('id', $newParent . Base::NEW_ITEM_BUTTON);
$new->onClick[] = function (Nette\Forms\Controls\SubmitButton $button) use($container) {
if (count($container->getComponent(Base::NEW_ITEM_CONTENT)->getComponents()) < 1) {
/** @var Nette\Forms\Controls\SelectBox $listSelect */
$listSelect = $container->getComponent(self::LIST_BOX);
$items = $listSelect->getItems();
$items[$newItemId = count($items)] = Base::NEW_ITEM_BUTTON_LABEL;
$listSelect->setItems($items);
$listSelect->setValue($newItemId);
$button->getParent()->getComponent(Base::NEW_ITEM_CONTENT)->createOne();
$button->getForm()->onSuccess = [];
}
};
$container->addDynamic($item::NEW_ITEM_CONTENT, function (Nette\Forms\Container $container) use($item, $newParent, $togglingObject, $userOptions) {
$child = isset($this->configuration['child']) ? $this->configuration['child'] : (isset($this->configuration['listItem']) ? $this->configuration['listItem'] : []);
/** @var Nette\Forms\Controls\SelectBox $listSelect */
$listSelect = $container->getParent()->getParent()->getComponent(self::LIST_BOX);
$items = $listSelect->getItems();
if (is_null($togglingObject)) {
$subTogglingObject = $listSelect->addCondition(Nette\Application\UI\Form::EQUAL, count($items) - 1);
} else {
$subTogglingObject = $togglingObject->addConditionOn($listSelect, Nette\Application\UI\Form::EQUAL, count($items) - 1);
}
$newListItem = Contents\Factory::getItemObject(['type' => 'container', 'child' => $child], NULL, $item->subTypes);
$newListItem->generateForm($newListItem, $container, NULL, $newParent, $subTogglingObject, $userOptions);
});
}
if (!isset($item->configuration['count'])) {
$deleteContainer = $container->addContainer(ListContainer::DELETE_ITEM);
}
$listSelect = new Contents\NoValidateSelectBox($this->getConfigValue('listLabel', 'list', $userOptions), NULL);
$container[self::LIST_BOX] = $listSelect;
$listSelect->setOption('id', $parentName . self::LIST_BOX . $name);
if (!is_null($togglingObject)) {
$togglingObject->toggle($listSelect->getOption('id'));
if (!is_null($newParent)) {
$togglingObject->toggle($newParent . Base::NEW_ITEM_BUTTON);
}
}
$items = [];
$listHead = $this->getConfigValue('listHead', NULL, $userOptions);
foreach ($this->getChild() as $childName => $child) {
if (is_null($togglingObject)) {
/** @var Nette\Forms\Rules $subTogglingObject */
$subTogglingObject = $listSelect->addCondition(Nette\Application\UI\Form::EQUAL, $childName);
} else {
/** @var Nette\Forms\Rules $subTogglingObject */
$subTogglingObject = $togglingObject->addConditionOn($listSelect, Nette\Application\UI\Form::EQUAL, $childName);
}
if (!isset($item->configuration['count'])) {
$removeButton = $deleteContainer->addCheckbox($childName, $this->getConfigValue('deleteLabel', 'remove item', $userOptions));
$removeButton->setOption('id', $parentName . '__' . $name . ListContainer::DELETE_ITEM . $childName);
$subTogglingObject->toggle($removeButton->getOption('id'));
}
$child->generateForm($child, $container, $childName, $parentName . '__' . $name, $subTogglingObject, isset($userOptions['child']) && is_array($userOptions['child']) ? ['child' => $userOptions['child']] : []);
try {
$itemName = is_null($listHead) ? $childName : Trejjam\Utils\Utils::getValue($child->getContent(), $listHead);
} catch (Trejjam\Utils\LogicException $e) {
if ($e->getCode() & Trejjam\Utils\Exception::UTILS_KEY_NOT_FOUND) {
$itemName = $childName;
} else {
throw $e;
}
}
if (empty($itemName)) {
$itemName = $childName;
}
$items[$childName] = $itemName;
}
$postedValue = (string) $listSelect->getRawValue();
if ($postedValue != '' && !isset($items[$postedValue])) {
$items[$postedValue] = '';
}
$listSelect->setItems($items);
if (count($items) > 0) {
$listSelect->setDefaultValue('0');
}
$item->applyUserOptions($container, $userOptions);
}
示例3: generateForm
/**
* @param Base|Container $item
* @param Nette\Forms\Container $formContainer
* @param $name
* @param $parentName
* @param Nette\Forms\Rules $togglingObject
* @param array $userOptions
*/
public function generateForm(Base $item, Nette\Forms\Container &$formContainer, $name, $parentName, $togglingObject, array $userOptions = [])
{
$container = is_null($name) ? $formContainer : $formContainer->addContainer($name);
foreach ($this->getChild() as $childName => $child) {
$child->generateForm($child, $container, $childName, $parentName . '__' . $name, $togglingObject, isset($userOptions['child']) && isset($userOptions['child'][$childName]) && is_array($userOptions['child'][$childName]) ? $userOptions['child'][$childName] : []);
}
$item->applyUserOptions($container, $userOptions);
}