当前位置: 首页>>代码示例>>PHP>>正文


PHP Form\FormBuilder类代码示例

本文整理汇总了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);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:34,代码来源:NullableGuesser.php

示例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);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:35,代码来源:HrefGuesser.php

示例3: handle

 /**
  * Handle the form.
  *
  * @param FormBuilder $builder
  */
 public function handle(FormBuilder $builder)
 {
     if (!$builder->canSave()) {
         return;
     }
     $builder->saveForm();
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:12,代码来源:FormHandler.php

示例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);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:37,代码来源:FieldTranslator.php

示例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);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:36,代码来源:TextGuesser.php

示例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));
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:38,代码来源:SetFormModel.php

示例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()));
     }
 }
开发者ID:bloveless,项目名称:configuration-module,代码行数:14,代码来源:ConfigurationFormRepository.php

示例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);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:13,代码来源:ButtonNormalizer.php

示例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);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:14,代码来源:PrefixesGuesser.php

示例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()));
     }
 }
开发者ID:AkibaTech,项目名称:preferences-module,代码行数:15,代码来源:PreferenceFormRepository.php

示例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;
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:15,代码来源:FormInput.php

示例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);
     }
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:13,代码来源:SetFormOptions.php

示例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);
     }
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:10,代码来源:LoadFormErrors.php

示例14: handle

 /**
  * Handle the event.
  */
 public function handle()
 {
     /* @var FieldType $field */
     foreach ($this->builder->getFormFields() as $field) {
         $field->setValue($field->getPostValue());
     }
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:10,代码来源:RepopulateFields.php

示例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());
     }
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:12,代码来源:FlashFieldValues.php


注:本文中的Anomaly\Streams\Platform\Ui\Form\FormBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。