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


PHP FormBuilder::setFields方法代码示例

本文整理汇总了PHP中Anomaly\Streams\Platform\Ui\Form\FormBuilder::setFields方法的典型用法代码示例。如果您正苦于以下问题:PHP FormBuilder::setFields方法的具体用法?PHP FormBuilder::setFields怎么用?PHP FormBuilder::setFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Anomaly\Streams\Platform\Ui\Form\FormBuilder的用法示例。


在下文中一共展示了FormBuilder::setFields方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: fill

 /**
  * Fill in fields.
  *
  * @param FormBuilder $builder
  */
 public function fill(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $stream = $builder->getFormStream();
     /**
      * If no Stream, skip it.
      */
     if (!$stream) {
         if (array_search('*', $fields) !== false) {
             unset($fields[array_search('*', $fields)]);
             $builder->setFields($fields);
         }
         return;
     }
     /**
      * Fill with everything by default.
      */
     $fill = $stream->getAssignments()->fieldSlugs();
     /**
      * Loop over field configurations and unset
      * them from the fill fields.
      *
      * If we come across the fill marker then
      * set the position.
      */
     foreach ($fields as $parameters) {
         if (is_string($parameters) && $parameters === '*') {
             continue;
         }
         unset($fill[array_search($parameters['field'], $fill)]);
     }
     /**
      * If we have a fill marker then splice
      * in the remaining fill fields in place
      * of the fill marker.
      */
     if (($position = array_search('*', $fields)) !== false) {
         array_splice($fields, $position, null, $fill);
         unset($fields[array_search('*', $fields)]);
     }
     $builder->setFields($fields);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:47,代码来源:FieldFiller.php

示例5: guess

 /**
  * Guess the field instructions.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     if (!($readOnly = $builder->isReadOnly())) {
         return;
     }
     foreach ($fields as &$field) {
         $field['read_only'] = true;
         $field['disabled'] = true;
     }
     $builder->setFields($fields);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:17,代码来源:ReadOnlyGuesser.php

示例6: guess

 /**
  * Guess the field instructions.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $mode = $builder->getFormMode();
     foreach ($fields as &$field) {
         // Guess based on the form mode if applicable.
         if (in_array((string) ($disabled = array_get($field, 'disabled', null)), ['create', 'edit'])) {
             $field['disabled'] = $disabled === $mode;
         }
     }
     $builder->setFields($fields);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:17,代码来源:DisabledGuesser.php

示例7: guess

 /**
  * Guess the field instructions.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $entry = $builder->getFormEntry();
     if (!is_object($entry)) {
         return;
     }
     foreach ($fields as &$field) {
         $field['translatable'] = $entry->isTranslatedAttribute($field['field']);
     }
     $builder->setFields($fields);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:17,代码来源:TranslatableGuesser.php

示例8: guess

 /**
  * Guess the field unique rule.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $entry = $builder->getFormEntry();
     foreach ($fields as &$field) {
         $unique = array_pull($field, 'rules.unique');
         /*
          * No unique? Continue...
          */
         if (!$unique || $unique === false) {
             continue;
         }
         /*
          * If unique is a string then
          * it's set explicitly.
          */
         if ($unique && is_string($unique)) {
             $field['rules']['unique'] = 'unique:' . $unique;
             continue;
         }
         /*
          * If unique is true then
          * automate the rule.
          */
         if ($unique && $unique === true) {
             $unique = 'unique:' . $entry->getTable() . ',' . $field['field'];
             if ($entry instanceof EntryInterface) {
                 $unique .= ',' . $entry->getId();
             }
             $field['rules']['unique'] = $unique;
             continue;
         }
         /*
          * If unique is an array then use
          * the default automation and add to it.
          */
         if ($unique && is_array($unique)) {
             $unique = 'unique:' . $entry->getTable() . ',' . $field['field'];
             if ($entry instanceof EntryInterface) {
                 $unique .= ',' . $entry->getId();
             }
             $keys = array_keys($unique);
             $values = array_values($unique);
             foreach ($keys as $column) {
                 $unique .= ',' . $column . ',' . $column . ',' . array_shift($values);
             }
             $field['rules']['unique'] = $unique;
             continue;
         }
     }
     $builder->setFields($fields);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:57,代码来源:UniqueGuesser.php

示例9: populate

 /**
  * Populate the fields with entry values.
  *
  * @param FormBuilder $builder
  */
 public function populate(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $entry = $builder->getFormEntry();
     foreach ($fields as &$field) {
         /*
          * If the field is not already set
          * then get the value off the entry.
          */
         if (!isset($field['value']) && $entry instanceof EloquentModel && $entry->getId()) {
             if ($locale = array_get($field, 'locale')) {
                 $field['value'] = $entry->translateOrDefault($locale)->{$field['field']};
             } else {
                 $field['value'] = $entry->{$field['field']};
             }
         }
         /*
          * If the field has a default value
          * and the entry does not exist yet
          * then use the default value.
          */
         if (isset($field['config']['default_value']) && $entry instanceof EloquentModel && !$entry->getId()) {
             $field['value'] = $field['config']['default_value'];
         }
         /*
          * If the field has a default value
          * and there is no entry then
          * use the default value.
          */
         if (isset($field['config']['default_value']) && !$entry) {
             $field['value'] = $field['config']['default_value'];
         }
         /*
          * If the field is an assignment then
          * use it's config for the default value.
          */
         if (!isset($field['value']) && $entry instanceof EntryInterface && ($type = $entry->getFieldType($field['field']))) {
             $field['value'] = array_get($type->getConfig(), 'default_value');
         }
         /*
          * Lastly if we have flashed data from a front end
          * form handler then use that value for the field.
          */
         if ($this->session->has($field['prefix'] . $field['field'])) {
             $field['value'] = $this->session->pull($field['prefix'] . $field['field']);
         }
     }
     $builder->setFields($fields);
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:54,代码来源:FieldPopulator.php

示例10: normalize

 /**
  * Normalize field input.
  *
  * @param FormBuilder $builder
  */
 public function normalize(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     foreach ($fields as $slug => &$field) {
         /*
          * If the field is a wild card marker
          * then just continue.
          */
         if ($field == '*') {
             continue;
         }
         /*
          * If the slug is numeric and the field
          * is a string then use the field as is.
          */
         if (is_numeric($slug) && is_string($field)) {
             $field = ['field' => $field];
         }
         /*
          * If the slug is a string and the field
          * is a string too then use the field as the
          * type and the field as well.
          */
         if (!is_numeric($slug) && is_string($slug) && is_string($field)) {
             $field = ['field' => $slug, 'type' => $field];
         }
         /*
          * If the field is an array and does not
          * have the field parameter set then
          * use the slug.
          */
         if (is_array($field) && !isset($field['field'])) {
             $field['field'] = $slug;
         }
         /*
          * If the field is required then it must have
          * the rule as well.
          */
         if (array_get($field, 'required') === true) {
             $field['rules'] = array_unique(array_merge(array_get($field, 'rules', []), ['required']));
         }
     }
     $builder->setFields(array_values($fields));
 }
开发者ID:huglester,项目名称:streams-platform,代码行数:49,代码来源:FieldNormalizer.php

示例11: guess

 /**
  * Guess the field required flag.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $mode = $builder->getFormMode();
     $entry = $builder->getFormEntry();
     foreach ($fields as &$field) {
         // Guess based on the assignment if possible.
         if (!isset($field['required']) && $entry instanceof EntryInterface && ($assignment = $entry->getAssignment($field['field']))) {
             $field['required'] = array_get($field, 'required', $assignment->isRequired());
         }
         // Guess based on the form mode if applicable.
         if (in_array($required = array_get($field, 'required'), ['create', 'edit'])) {
             $field['required'] = $required === $mode;
         }
         // Guess based on the rules.
         if (in_array('required', array_get($field, 'rules', []))) {
             $field['required'] = true;
         }
     }
     $builder->setFields($fields);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:26,代码来源:RequiredGuesser.php

示例12: guess

 /**
  * Guess the field placeholders.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $stream = $builder->getFormStream();
     foreach ($fields as &$field) {
         $locale = array_get($field, 'locale');
         /**
          * If the placeholder are already set then use it.
          */
         if (isset($field['placeholder'])) {
             if (str_is('*::*', $field['placeholder'])) {
                 $field['placeholder'] = trans($field['placeholder'], [], null, $locale);
             }
             continue;
         }
         /**
          * If we don't have a field then we
          * can not really guess anything here.
          */
         if (!isset($field['field'])) {
             continue;
         }
         /**
          * No stream means we can't
          * really do much here.
          */
         if (!$stream instanceof StreamInterface) {
             continue;
         }
         $assignment = $stream->getAssignment($field['field']);
         $object = $stream->getField($field['field']);
         /**
          * No assignment means we still do
          * not have anything to do here.
          */
         if (!$assignment instanceof AssignmentInterface) {
             continue;
         }
         /**
          * Next try using the fallback assignment
          * placeholder system as generated verbatim.
          */
         $placeholder = $assignment->getPlaceholder() . '.default';
         if (!isset($field['placeholder']) && str_is('*::*', $placeholder) && trans()->has($placeholder, $locale)) {
             $field['placeholder'] = trans($placeholder, [], null, $locale);
         }
         /**
          * Next try using the default assignment
          * placeholder system as generated verbatim.
          */
         $placeholder = $assignment->getPlaceholder();
         if (!isset($field['placeholder']) && str_is('*::*', $placeholder) && trans()->has($placeholder, $locale) && is_string($translated = trans($placeholder, [], null, $locale))) {
             $field['placeholder'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['placeholder']) && $placeholder && !str_is('*::*', $placeholder)) {
             $field['placeholder'] = $placeholder;
         }
         /**
          * Next try using the default field
          * placeholder system as generated verbatim.
          */
         $placeholder = $object->getPlaceholder();
         if (!isset($field['placeholder']) && str_is('*::*', $placeholder) && trans()->has($placeholder, $locale) && is_string($translated = trans($placeholder, [], null, $locale))) {
             $field['placeholder'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['placeholder']) && $placeholder && !str_is('*::*', $placeholder)) {
             $field['placeholder'] = $placeholder;
         }
     }
     $builder->setFields($fields);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:82,代码来源:PlaceholdersGuesser.php

示例13: guess


//.........这里部分代码省略.........
 {
     $fields = $builder->getFields();
     $stream = $builder->getFormStream();
     foreach ($fields as &$field) {
         $locale = array_get($field, 'locale');
         /**
          * If the label are already set then use it.
          */
         if (isset($field['label'])) {
             if (str_is('*::*', $field['label'])) {
                 $field['label'] = trans($field['label'], [], null, $locale);
             }
             continue;
         }
         /**
          * If we don't have a field then we
          * can not really guess anything here.
          */
         if (!isset($field['field'])) {
             continue;
         }
         /**
          * No stream means we can't
          * really do much here.
          */
         if (!$stream instanceof StreamInterface) {
             continue;
         }
         $assignment = $stream->getAssignment($field['field']);
         $object = $stream->getField($field['field']);
         /**
          * No assignment means we still do
          * not have anything to do here.
          */
         if (!$assignment instanceof AssignmentInterface) {
             continue;
         }
         /**
          * Next try using the fallback assignment
          * label system as generated verbatim.
          */
         $label = $assignment->getLabel() . '.default';
         if (!isset($field['label']) && str_is('*::*', $label) && trans()->has($label, $locale)) {
             $field['label'] = trans($label, [], null, $locale);
         }
         /**
          * Next try using the default assignment
          * label system as generated verbatim.
          */
         $label = $assignment->getLabel();
         if (!isset($field['label']) && str_is('*::*', $label) && trans()->has($label, $locale) && is_string($translated = trans($label, [], null, $locale))) {
             $field['label'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['label']) && $label && !str_is('*::*', $label)) {
             $field['label'] = $label;
         }
         /**
          * Next try using the generic assignment
          * label system without the stream identifier.
          */
         $label = explode('.', $assignment->getLabel());
         array_pop($label);
         $label = implode('.', $label);
         if (!isset($field['label']) && str_is('*::*', $label) && trans()->has($label, $locale) && is_string($translated = trans($label, [], null, $locale))) {
             $field['label'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['label']) && $label && !str_is('*::*', $label)) {
             $field['label'] = $label;
         }
         /**
          * Next try using the default field
          * label system as generated verbatim.
          */
         $label = $object->getName();
         if (!isset($field['label']) && str_is('*::*', $label) && trans()->has($label, $locale) && is_string($translated = trans($label, [], null, $locale))) {
             $field['label'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['label']) && $label && !str_is('*::*', $label)) {
             $field['label'] = $label;
         }
         /**
          * If the field is still untranslated and
          * we're not debugging then humanize the slug
          * in leu of displaying an untranslated key.
          */
         if (!isset($field['label']) && $this->config->get('streams::system.lazy_translations')) {
             $field['label'] = $this->string->humanize($field['field']);
         }
     }
     $builder->setFields($fields);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:101,代码来源:LabelsGuesser.php

示例14: parse

 /**
  * Parse the form fields.
  *
  * @param FormBuilder $builder
  */
 public function parse(FormBuilder $builder)
 {
     $entry = $builder->getFormEntry();
     $builder->setFields($this->parser->parse($builder->getFields(), compact('entry')));
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:10,代码来源:FieldParser.php

示例15: guess

 /**
  * Guess the field warnings.
  *
  * @param FormBuilder $builder
  */
 public function guess(FormBuilder $builder)
 {
     $fields = $builder->getFields();
     $stream = $builder->getFormStream();
     foreach ($fields as &$field) {
         $locale = array_get($field, 'locale');
         /**
          * If the warning is already set then use it.
          */
         if (isset($field['warning'])) {
             if (str_is('*::*', $field['warning'])) {
                 $field['warning'] = trans($field['warning'], [], null, $locale);
             }
             continue;
         }
         /**
          * If we don't have a field then we
          * can not really guess anything here.
          */
         if (!isset($field['field'])) {
             continue;
         }
         /**
          * No stream means we can't
          * really do much here.
          */
         if (!$stream || !$stream->getAssignment($field['field'])) {
             $warning = "module::field.{$field['field']}.warning";
             if (str_is('*::*', $warning) && trans()->has($warning)) {
                 $field['warning'] = trans($warning, [], null, $locale);
             }
             continue;
         }
         $assignment = $stream->getAssignment($field['field']);
         $object = $stream->getField($field['field']);
         /**
          * No assignment means we still do
          * not have anything to do here.
          */
         if (!$assignment) {
             continue;
         }
         /**
          * Next try using the fallback assignment
          * warning system as generated verbatim.
          */
         $warning = $assignment->getWarning() . '.default';
         if (!isset($field['warning']) && str_is('*::*', $warning) && trans()->has($warning, $locale)) {
             $field['warning'] = trans($warning, [], null, $locale);
         }
         /**
          * Next try using the default assignment
          * warning system as generated verbatim.
          */
         $warning = $assignment->getWarning();
         if (!isset($field['warning']) && str_is('*::*', $warning) && trans()->has($warning, $locale) && is_string($translated = trans($warning, [], null, $locale))) {
             $field['warning'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['warning']) && $warning && !str_is('*::*', $warning)) {
             $field['warning'] = $warning;
         }
         /**
          * Next try using the default field
          * warning system as generated verbatim.
          */
         $warning = $object->getWarning();
         if (!isset($field['warning']) && str_is('*::*', $warning) && trans()->has($warning, $locale) && is_string($translated = trans($warning, [], null, $locale))) {
             $field['warning'] = $translated;
         }
         /**
          * Check if it's just a standard string.
          */
         if (!isset($field['warning']) && $warning && !str_is('*::*', $warning)) {
             $field['warning'] = $warning;
         }
     }
     $builder->setFields($fields);
 }
开发者ID:jacksun101,项目名称:streams-platform,代码行数:86,代码来源:WarningsGuesser.php


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