本文整理汇总了PHP中Nette\Forms\Controls\BaseControl类的典型用法代码示例。如果您正苦于以下问题:PHP BaseControl类的具体用法?PHP BaseControl怎么用?PHP BaseControl使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BaseControl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
* @param object $object
* @param string $fieldName
* @param BaseControl $control
* @param IClassMetadata $classMetadata
* @throws \NForms\Exceptions\UnexpectedTypeException
* @return bool
*/
public function save($object, $fieldName, BaseControl $control, IClassMetadata $classMetadata)
{
if ($control->isOmitted() || $control->isDisabled()) {
return TRUE;
}
$value = $control->getValue();
if ($classMetadata->hasAssociation($fieldName) && $value !== NULL) {
if ($classMetadata->isSingleValuedAssociation($fieldName)) {
$value = $this->objectManager->find($classMetadata->getAssociationTargetClass($fieldName), $value);
} else {
if (!is_array($value) && (!$value instanceof \ArrayAccess || !$value instanceof \Iterator)) {
throw new UnexpectedTypeException("In mapping association {$classMetadata->getClass()}::\${$fieldName} - expected array or ArrayAccess and Iterator instance, given " . get_class($value) . ".");
}
$collection = array();
foreach ($value as $id) {
$collection[] = $this->objectManager->find($classMetadata->getAssociationTargetClass($fieldName), $id);
}
$value = $collection;
}
}
if ($classMetadata->hasAssociation($fieldName)) {
$classMetadata->setAssociationValue($object, $fieldName, $value);
} else {
if ($control instanceof Nette\Forms\Controls\TextBase && $value === '') {
$value = NULL;
}
$classMetadata->setFieldValue($object, $fieldName, $value);
}
return TRUE;
}
示例2: toPropertyValue
public function toPropertyValue(\Nette\Forms\Controls\BaseControl $control, Builder\Metadata $metadata)
{
$value = $control->getValue();
if ($value !== null) {
$value = $metadata->type === 'float' ? (double) $value : (int) $value;
}
return $value;
}
示例3: label
public static function label(Html $label, BaseControl $control, $isPart)
{
if ($label->getName() === 'label') {
$label->addClass('control-label');
}
if ($control->isRequired()) {
$label->addClass('required');
}
return $label;
}
示例4: addNominalDiscountControl
private function addNominalDiscountControl(BaseControl $priceControl)
{
$errorMessage = 'Nominal discount must be between 0 and original price.';
$control = $this->addText('nominalDiscount', 'Nominal discount');
$control->setType('number')->setAttribute('step', 'any')->setDefaultValue(0)->addRule(self::FLOAT, $errorMessage)->addRule(function (TextInput $input) use($priceControl) {
return $input->getValue() >= 0 && $input->getValue() < $priceControl->getValue();
}, $errorMessage);
if ($this->editedProduct !== null) {
$control->setDefaultValue($this->editedProduct->getNominalDiscount());
}
}
示例5: resolveRequiring
/**
* @param \Nette\Forms\Controls\BaseControl $control
* @param string|null $errorMessage
* @param bool|callable $requiring
*/
private function resolveRequiring(\Nette\Forms\Controls\BaseControl $control, $errorMessage = null, $requiring = false)
{
if ($requiring === true) {
$control->setRequired($errorMessage !== null ? $errorMessage : true);
} elseif (is_callable($requiring)) {
$condition = $requiring($control);
if (!$condition instanceof \Nette\Forms\Rules) {
throw new RequiredFormFieldResolutionException('Requiring call must return instance of \\Nette\\Forms\\Rules.');
}
$condition->setRequired($errorMessage !== null ? $errorMessage : true);
}
}
示例6: getControl
/**
* Generates control's HTML element.
*
* @return string
*/
public function getControl()
{
$items = $this->getItems();
reset($items);
$input = BaseControl::getControl();
return Helpers::createInputList($this->translate ? $this->translate($items) : $items, array_merge($input->attrs, ['id' => NULL, 'checked?' => $this->value, 'disabled:' => $this->disabled, 'required' => NULL, 'data-nette-rules:' => [key($items) => $input->attrs['data-nette-rules']]]), $this->label->attrs, $this->separator);
}
示例7: getControl
/**
* Just remove translations from each option
* @return Nette\Forms\Helpers
*/
public function getControl()
{
$items = $this->prompt === FALSE ? array() : array('' => $this->translate($this->prompt));
foreach ($this->options as $key => $value) {
$items[is_array($value) ? $key : $key] = $value;
}
return Nette\Forms\Helpers::createSelectBox($items, array('selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL))->addAttributes(BaseControl::getControl()->attrs);
}
示例8: getControl
/**
* Generates control's HTML element.
*
* @return Html
*/
public function getControl()
{
$items = $this->getPrompt() === FALSE ? [] : ['' => $this->translate($this->getPrompt())];
foreach ($this->options as $key => $value) {
$items[$this->translate && is_array($value) ? $this->translate($key) : $key] = $this->translate ? $this->translate($value) : $value;
}
return Helpers::createSelectBox($items, ['selected?' => $this->value, 'disabled:' => is_array($this->disabled) ? $this->disabled : NULL])->addAttributes(BaseControl::getControl()->attrs);
}
示例9: createButton
public function createButton()
{
if ($this->button) {
return FALSE;
}
/** @var Nette\Forms\Container $container */
$container = $this->control->lookup('Nette\\Forms\\Container');
$name = $this->control->getName() . self::$buttonSuffix;
$this->button = new SubmitButton("Apply");
$this->button->setValidationScope(false);
$container->addComponent($this->button, $name);
$this->control->getControlPrototype()->addAttributes(array('data-apply-button' => $this->button->getHtmlId()));
return TRUE;
}
示例10: __construct
public function __construct($caption, $publicKey, $privateKey)
{
$this->monitor('Nette\\Forms\\Form');
parent::__construct($caption);
$this->publicKey = $publicKey;
$this->privateKey = $privateKey;
}
示例11: __construct
/**
* @return ShiftPatternDate
*/
public function __construct(Template $template, DateTime $date, $templateFileName)
{
parent::__construct(null);
$this->addRule(__CLASS__ . '::validatePattern', 'Shift pattern is invalid.');
$this->_template = $template;
$this->_template->setFile(__DIR__ . "/{$templateFileName}");
$this->_template->registerHelper('dayName', function ($dayNumber) {
return DateTime::dayName($dayNumber);
});
$this->_template->registerHelper('padTime', function ($t) {
if ($t < 10) {
return '0' . $t;
}
return $t;
});
$this->_template->registerHelper('selectOption', function ($timeUnit, $time, $type) {
$timeUnit = (int) $timeUnit;
list($hour, $minute) = explode(':', $time);
$hour = (int) $hour;
$minute = (int) $minute;
if ($type === 'h') {
return $timeUnit === $hour ? 'selected="selected"' : '';
}
if ($type === 'm') {
return $timeUnit === $minute ? 'selected="selected"' : '';
}
});
// returns curren formated date and moves date one day forward
$this->_template->registerHelper('day', function ($date) {
$day = $date->format('j F');
$date->addDay();
return $day;
});
$this->_date = $date;
}
示例12: __construct
public function __construct($caption = NULL, $side, $border)
{
$this->monitor('Nette\\Forms\\Form');
parent::__construct($caption);
$this->side = $side;
$this->border = $border;
}
示例13: __construct
public function __construct($caption = NULL, $min, $max)
{
$this->monitor('Nette\\Forms\\Form');
parent::__construct($caption);
$this->min = $min;
$this->max = $max;
}
示例14: __construct
public function __construct($label = null, array $entity = NULL, array $config = NULL)
{
parent::__construct($label);
$this->entity = $entity;
$this->labelName = $label;
$this->options = $config;
}
示例15: __construct
/**
* @param ReCaptcha $reCaptcha
* @param Http\Request $httpRequest
* @param string $caption
*/
public function __construct(ReCaptcha $reCaptcha, Http\Request $httpRequest, $caption = NULL)
{
parent::__construct($caption);
$this->setOmitted();
$this->reCaptcha = $reCaptcha;
$this->httpRequest = $httpRequest;
$this->control = $reCaptcha->getHtml();
}