本文整理汇总了PHP中Symfony\Component\Form\FormBuilder::setRequired方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilder::setRequired方法的具体用法?PHP FormBuilder::setRequired怎么用?PHP FormBuilder::setRequired使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Form\FormBuilder
的用法示例。
在下文中一共展示了FormBuilder::setRequired方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: buildForm
public function buildForm(FormBuilder $builder, array $options)
{
if (null === $options['property_path']) {
$options['property_path'] = $builder->getName();
}
if (false === $options['property_path'] || '' === $options['property_path']) {
$options['property_path'] = null;
} else {
$options['property_path'] = new PropertyPath($options['property_path']);
}
$builder->setRequired($options['required'])
->setReadOnly($options['read_only'])
->setErrorBubbling($options['error_bubbling'])
->setEmptyData($options['empty_data'])
->setAttribute('by_reference', $options['by_reference'])
->setAttribute('property_path', $options['property_path'])
->setAttribute('error_mapping', $options['error_mapping'])
->setAttribute('max_length', $options['max_length'])
->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))
->setData($options['data'])
->addValidator(new DefaultValidator());
if ($options['trim']) {
$builder->addEventSubscriber(new TrimListener());
}
}
示例2: buildForm
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilder $builder, array $options)
{
if (null === $options['property_path']) {
$options['property_path'] = $builder->getName();
}
if (false === $options['property_path'] || '' === $options['property_path']) {
$options['property_path'] = null;
} else {
$options['property_path'] = new PropertyPath($options['property_path']);
}
if (!is_array($options['attr'])) {
throw new FormException('The "attr" option must be "array".');
}
$builder->setRequired($options['required'])->setDisabled($options['disabled'])->setErrorBubbling($options['error_bubbling'])->setEmptyData($options['empty_data'])->setAttribute('read_only', $options['read_only'])->setAttribute('by_reference', $options['by_reference'])->setAttribute('property_path', $options['property_path'])->setAttribute('error_mapping', $options['error_mapping'])->setAttribute('max_length', $options['max_length'])->setAttribute('pattern', $options['pattern'])->setAttribute('label', $options['label'] ?: $this->humanize($builder->getName()))->setAttribute('attr', $options['attr'] ?: array())->setAttribute('invalid_message', $options['invalid_message'])->setAttribute('invalid_message_parameters', $options['invalid_message_parameters'])->setAttribute('translation_domain', $options['translation_domain'])->setAttribute('virtual', $options['virtual'])->setData($options['data'])->setDataMapper(new PropertyPathMapper($options['data_class']))->addEventSubscriber(new ValidationListener());
if ($options['trim']) {
$builder->addEventSubscriber(new TrimListener());
}
}