當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。