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


PHP FormField::setLabel方法代码示例

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


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

示例1: wfMsgForContent

 function __construct($name, $text)
 {
     $this->name = $name;
     $this->title = wfMsgForContent('formtitlepattern', $name);
     $this->template = array();
     $this->template[0] = wfMsgForContent('formtemplatepattern', $name);
     $this->fields = array();
     $this->namePattern = array();
     $this->instructions = null;
     # XXX: may be some faster ways to do this
     $lines = explode("\n", $text);
     foreach ($lines as $line) {
         if (preg_match('/^(\\w+)=(.*)$/', $line, $matches)) {
             if (strcasecmp($matches[1], 'template') == 0) {
                 $this->template[0] = $matches[2];
             } elseif (preg_match('/template(\\d+)/i', $matches[1], $tmatches)) {
                 $this->template[intval($tmatches[1])] = $matches[2];
             } elseif (strcasecmp($matches[1], 'namePattern') == 0) {
                 $this->namePattern[0] = $matches[2];
             } elseif (preg_match('/namePattern(\\d+)/i', $matches[1], $tmatches)) {
                 $this->namePattern[intval($tmatches[1])] = $matches[2];
             } elseif (strcasecmp($matches[1], 'title') == 0) {
                 $this->title = $matches[2];
             } elseif (strcasecmp($matches[1], 'instructions') == 0) {
                 $this->instructions = $matches[2];
                 wfDebug(__METHOD__ . ": Got instructions: '" . $this->instructions . "'.\n");
             } else {
                 wfDebug(__METHOD__ . ": unknown form attribute '{$matches['1']}'; skipping.\n");
             }
         } elseif (preg_match('/^(\\w+)\\|([^\\|]+)\\|(\\w+)(\\|([^\\|]+)(\\|(.*))?)?$/', $line, $matches)) {
             # XXX: build an inheritance tree for different kinds of fields
             $field = new FormField();
             $field->setName($matches[1]);
             $field->setLabel($matches[2]);
             $field->setFieldType($matches[3]);
             if (count($matches) > 4 && $matches[4]) {
                 $field->setDescription($matches[5]);
                 if (count($matches) > 6 && $matches[6]) {
                     $rawOptions = explode(',', $matches[7]);
                     foreach ($rawOptions as $rawOption) {
                         if (preg_match('/^(\\w+)=(.+)/', $rawOption, $optMatches)) {
                             $field->setOption($optMatches[1], $optMatches[2]);
                         } else {
                             wfDebug(__METHOD__ . ": unrecognized form field option: '{$rawOption}'; skipping.\n");
                         }
                     }
                 }
             }
             $this->fields[$field->name] = $field;
         } else {
             wfDebug(__METHOD__ . ": unrecognized form line: '{$line}'; skipping.\n");
         }
     }
 }
开发者ID:realsoc,项目名称:mediawiki-extensions,代码行数:54,代码来源:Form.body.php

示例2: getFormat

 public function getFormat()
 {
     $fields = AddressFormat::getOrderedAddressFields($this->country->id, true, true);
     $required = array_flip(AddressFormat::getFieldsRequired());
     $format = ['id_address' => (new FormField())->setName('id_address')->setType('hidden'), 'id_customer' => (new FormField())->setName('id_customer')->setType('hidden'), 'back' => (new FormField())->setName('back')->setType('hidden'), 'token' => (new FormField())->setName('token')->setType('hidden'), 'alias' => (new FormField())->setName('alias')->setLabel($this->getFieldLabel('alias'))];
     foreach ($fields as $field) {
         $formField = new FormField();
         $formField->setName($field);
         $fieldParts = explode(':', $field, 2);
         if (count($fieldParts) === 1) {
             if ($field === 'postcode') {
                 if ($this->country->need_zip_code) {
                     $formField->setRequired(true);
                 }
             }
         } elseif (count($fieldParts) === 2) {
             list($entity, $entityField) = $fieldParts;
             // Fields specified using the Entity:field
             // notation are actually references to other
             // entities, so they should be displayed as a select
             $formField->setType('select');
             // Also, what we really want is the id of the linked entity
             $formField->setName('id_' . strtolower($entity));
             if ($entity === 'Country') {
                 $formField->setType('countrySelect');
                 $formField->setValue($this->country->id);
                 foreach ($this->availableCountries as $country) {
                     $formField->addAvailableValue($country['id_country'], $country[$entityField]);
                 }
             } elseif ($entity === 'State') {
                 if ($this->country->contains_states) {
                     $states = State::getStatesByIdCountry($this->country->id);
                     foreach ($states as $state) {
                         $formField->addAvailableValue($state['id_state'], $state[$entityField]);
                     }
                     $formField->setRequired(true);
                 }
             }
         }
         $formField->setLabel($this->getFieldLabel($field));
         if (!$formField->isRequired()) {
             // Only trust the $required array for fields
             // that are not marked as required.
             // $required doesn't have all the info, and fields
             // may be required for other reasons than what
             // AddressFormat::getFieldsRequired() says.
             $formField->setRequired(array_key_exists($field, $required));
         }
         $format[$formField->getName()] = $formField;
     }
     return $this->addConstraints($this->addMaxLength($format));
 }
开发者ID:M03G,项目名称:PrestaShop,代码行数:52,代码来源:CustomerAddressFormatter.php


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