本文整理汇总了PHP中Nette\Forms\Container::setOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::setOption方法的具体用法?PHP Container::setOption怎么用?PHP Container::setOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Forms\Container
的用法示例。
在下文中一共展示了Container::setOption方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: build
/**
* Build container according given container configuration.
*
* @param IFormConfig $containerConfig
* @param Forms\Container $container
* @throws \NForms\Exceptions\InvalidArgumentException
* @return void
*/
public function build(IFormConfig $containerConfig, Forms\Container $container)
{
// Set container class
if ($container instanceof IContainer) {
$container->setClassName($containerConfig->getTargetClass());
}
if ($container instanceof IOptions) {
$container->setOption(self::VALIDATION_GROUPS_OPTION, $containerConfig->getValidationGroups());
}
// Build container components
foreach ($containerConfig->getAll() as $componentConfig) {
if ($componentConfig instanceof IContainerConfig) {
$component = $this->createContainer($componentConfig, $container);
} elseif ($componentConfig instanceof IControlConfig) {
$component = $this->createControl($componentConfig, $container);
// Disabled?
if ($componentConfig->getDisabled()) {
$component->setDisabled();
}
// Locked?
if ($componentConfig->getReadonly()) {
$control = $component instanceof ApplyButtonWrapper ? $component->getWrappedControl() : $component;
$control->setOmitted();
$control->getControlPrototype()->addAttributes(array('readonly' => TRUE));
$reflection = new \ReflectionClass($control);
$property = $reflection->getProperty('disabled');
$property->setAccessible(TRUE);
$property->setValue($control, TRUE);
}
} else {
throw new InvalidArgumentException("Expected IContainerConfig/IControlConfig given '" . (is_object($componentConfig) ? get_class($componentConfig) : gettype($componentConfig)) . "'.");
}
// Set options
/** @var Forms\Controls\BaseControl|IContainer $component */
$component->setOption(IObjectMapper::FIELD_NAME, $componentConfig->getFieldName());
foreach ($componentConfig->getOptions() as $key => $value) {
$component->setOption($key, $value);
}
}
}