本文整理汇总了PHP中Anomaly\Streams\Platform\Ui\Form\FormBuilder类的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilder类的具体用法?PHP FormBuilder怎么用?PHP FormBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了FormBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: guess
/**
* Guess the nullable rule.
*
* @param FormBuilder $builder
*/
public function guess(FormBuilder $builder)
{
$fields = $builder->getFields();
foreach ($fields as &$field) {
// Skip if nullable
if (isset($field['rules']) && in_array('nullable', $field['rules'])) {
continue;
}
/**
* If the field depends on other fields we
* won't add nullable here because validation
* will not be performed on this field.
*/
if (!empty($field['rules'])) {
if (preg_grep("/required_.*/", $field['rules'])) {
continue;
}
}
// If not required then nullable.
if (isset($field['required']) && $field['required'] == false) {
$field['rules'][] = 'nullable';
}
// If not specified then it's nullable
if (!isset($field['required'])) {
$field['rules'][] = 'nullable';
}
}
$builder->setFields($fields);
}
示例2: guess
/**
* Guess the HREF for a button.
*
* @param FormBuilder $builder
*/
public function guess(FormBuilder $builder)
{
$buttons = $builder->getButtons();
$entry = $builder->getFormEntry();
// Nothing to do if empty.
if (!($section = $this->sections->active())) {
return;
}
foreach ($buttons as &$button) {
if (isset($button['attributes']['href'])) {
continue;
}
switch (array_get($button, 'button')) {
case 'cancel':
$button['attributes']['href'] = $section->getHref();
break;
case 'delete':
$button['attributes']['href'] = $section->getHref('delete/' . $entry->getId());
break;
default:
// Determine the HREF based on the button type.
$type = array_get($button, 'button');
if ($type && !str_contains($type, '\\') && !class_exists($type)) {
$button['attributes']['href'] = $section->getHref($type . '/{entry.id}');
}
break;
}
}
$builder->setButtons($buttons);
}
示例3: handle
/**
* Handle the form.
*
* @param FormBuilder $builder
*/
public function handle(FormBuilder $builder)
{
if (!$builder->canSave()) {
return;
}
$builder->saveForm();
}
示例4: translate
/**
* Translate form fields.
*
* @param FormBuilder $builder
*/
public function translate(FormBuilder $builder)
{
$translations = [];
$defaultLocale = config('streams::locales.default');
$enabledLocales = config('streams::locales.enabled');
/*
* For each field if the assignment is translatable
* then duplicate it and set a couple simple
* parameters to assist in rendering.
*/
foreach ($builder->getFields() as $field) {
if (!array_get($field, 'translatable', false)) {
$translations[] = $field;
continue;
}
foreach ($enabledLocales as $locale) {
$translation = $field;
array_set($translation, 'locale', $locale);
array_set($translation, 'hidden', $locale !== $locale);
if ($value = array_get($field, 'values.' . $locale)) {
array_set($translation, 'value', $value);
}
if ($defaultLocale !== $locale) {
array_set($translation, 'hidden', true);
array_set($translation, 'required', false);
array_set($translation, 'rules', array_diff(array_get($translation, 'rules', []), ['required']));
}
$translations[] = $translation;
}
}
$builder->setFields($translations);
}
示例5: guess
/**
* Guess the button from the hint.
*
* @param FormBuilder $builder
*/
public function guess(FormBuilder $builder)
{
$buttons = $builder->getButtons();
$module = $this->modules->active();
/*
* This will break if we can't figure
* out what the active module is.
*/
if (!$module instanceof Module) {
return;
}
foreach ($buttons as &$button) {
if (isset($button['text'])) {
continue;
}
if (!isset($button['button'])) {
continue;
}
$text = $module->getNamespace('button.' . $button['button']);
if (!isset($button['text']) && $this->translator->has($text)) {
$button['text'] = $text;
}
if ((!isset($button['text']) || !$this->translator->has($button['text'])) && $this->config->get('streams::system.lazy_translations')) {
$button['text'] = ucwords($this->string->humanize($button['button']));
}
if (!isset($button['text'])) {
$button['text'] = $text;
}
}
$builder->setButtons($buttons);
}
示例6: handle
/**
* Handle the form.
*/
public function handle()
{
$form = $this->builder->getForm();
$model = $this->builder->getModel();
/**
* If the model is already instantiated
* then use it as is.
*/
if (is_object($model)) {
$form->setModel($model);
return;
}
/**
* If no model is set, try guessing the
* model based on best practices.
*/
if ($model === null) {
$parts = explode('\\', str_replace('FormBuilder', 'Model', get_class($this->builder)));
unset($parts[count($parts) - 2]);
$model = implode('\\', $parts);
$this->builder->setModel($model);
}
/**
* If the model does not exist or
* is disabled then skip it.
*/
if (!$model || !class_exists($model)) {
$this->builder->setModel(null);
return;
}
/**
* Set the model on the form!
*/
$form->setModel(app($model));
}
示例7: save
/**
* Save the form.
*
* @param FormBuilder|ConfigurationFormBuilder $builder
* @return bool|mixed
*/
public function save(FormBuilder $builder)
{
$namespace = $builder->getFormEntry() . '::';
/* @var FieldType $field */
foreach ($builder->getFormFields() as $field) {
$this->configurations->set($namespace . $field->getField(), $builder->getScope(), $builder->getFormValue($field->getInputName()));
}
}
示例8: normalize
/**
* Normalize button input.
*
* @param FormBuilder $builder
*/
public function normalize(FormBuilder $builder)
{
$buttons = $builder->getButtons();
foreach ($buttons as $key => &$button) {
$button = $this->process($key, $button);
}
$builder->setButtons($buttons);
}
示例9: guess
/**
* Guess the field placeholders.
*
* @param FormBuilder $builder
*/
public function guess(FormBuilder $builder)
{
$fields = $builder->getFields();
$prefix = $builder->getFormOption('prefix');
foreach ($fields as &$field) {
array_set($field, 'prefix', array_get($field, 'prefix', $prefix));
}
$builder->setFields($fields);
}
示例10: save
/**
* Save the form.
*
* @param FormBuilder $builder
* @return bool|mixed
*/
public function save(FormBuilder $builder)
{
$form = $builder->getForm();
$namespace = $form->getEntry() . '::';
/* @var FieldType $field */
foreach ($form->getFields() as $field) {
$this->preferences->set($namespace . $field->getField(), $form->getValue($field->getInputName()));
}
}
示例11: all
/**
* Return all the input from the form.
*
* @param FormBuilder $builder
* @return array
*/
public function all(FormBuilder $builder)
{
$input = [];
/* @var FieldType $field */
foreach ($builder->getEnabledFormFields() as $field) {
$input[$field->getInputName()] = $field->getValidationValue();
}
return $input;
}
示例12: handle
/**
* Handle the command.
*
* @param Resolver $resolver
* @param Evaluator $evaluator
*/
public function handle(Resolver $resolver, Evaluator $evaluator)
{
$evaluator->evaluate($resolver->resolve($this->builder->getOptions(), ['builder' => $this->builder]), ['builder' => $this->builder]);
foreach ($this->builder->getOptions() as $key => $value) {
$this->builder->setFormOption($key, $value);
}
}
示例13: handle
/**
* Handle the event.
*/
public function handle(Store $session)
{
/* @var MessageBag $errors */
if ($errors = $session->get($this->builder->getOption('prefix') . 'errors')) {
$this->builder->setFormErrors($errors);
}
}
示例14: handle
/**
* Handle the event.
*/
public function handle()
{
/* @var FieldType $field */
foreach ($this->builder->getFormFields() as $field) {
$field->setValue($field->getPostValue());
}
}
示例15: handle
/**
* Handle the event.
*
* @param Store $session
*/
public function handle(Store $session)
{
/* @var FieldType $field */
foreach ($this->builder->getFormFields() as $field) {
$session->flash($field->getFieldName(), $field->getPostValue());
}
}