public function setName($name) { $this->fieldPageID->setName("{$name}[PageID]"); $this->fieldCustomURL->setName("{$name}[CustomURL]"); $this->fieldTitle->setName("{$name}[Title]"); $this->fieldLinkmode->setName("{$name}[Linkmode]"); return parent::setName($name); }
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)); }
/** * (non-PHPdoc) * @see forms/FormField#setName($name) */ function setName($name) { // We need to pass through the name change to the underlying value field. $this->valueField->setName($name); parent::setName($name); return $this; }
public function setName($name) { parent::setName($name); $this->dateField->setName($name . '[date]'); $this->timeField->setName($name . '[time]'); $this->timezoneField->setName($name . '[timezone]'); }
public function setName($name) { foreach ($this->composite_fields as $type => $field) { $field->setName("{$name}[{$type}]"); } return parent::setName($name); }
/** * @return FormField */ public function addPart(FormField $part) { if (strval($part->getName()) === '') { $part->setName(sprintf('%s-%s', $this->getName(), count($this->parts))); } $part->setAttribute('data-part', count($this->parts)); $this->parts[] = $part; return $this; }
/** * Transform a given form field into a composite field, where the translation is editable and the original value * is added as a read-only field. * @param FormField $field * @return CompositeField */ public function transformFormField(FormField $field) { $newfield = $field->performReadOnlyTransformation(); $fieldname = $field->getName(); if ($this->original->isLocalizedField($fieldname)) { $field->setName($this->original->getLocalizedFieldName($fieldname)); $field->setValue($this->original->getLocalizedValue($fieldname)); } return $this->baseTransform($newfield, $field, $fieldname); }
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"); } } }
/** * Update the names of the child fields when updating name of field. * * @param string $name new name to give to the field. * @return $this */ public function setName($name) { $this->passwordField->setName($name . '[_Password]'); $this->confirmPasswordfield->setName($name . '[_ConfirmPassword]'); if ($this->hiddenField) { $this->hiddenField->setName($name . '[_PasswordFieldVisible]'); } return parent::setName($name); }
/** * @param string $name * * @return $this */ public function setName($name) { $this->valueField->setName($name); parent::setName($name); return $this; }
/** * Transform a translatable field to show the field value from the default language * DataObject below the translated field. * * This is a fallback function which handles field types that aren't transformed by * $this->transform{FieldType} functions. * * @param FormField $nonEditableField The readonly field to contain the original value * @param FormField $originalField The original editable field containing the translated value * @return \CompositeField The transformed field */ protected function baseTransform($nonEditableField, $originalField) { $fieldname = $originalField->getName(); $nonEditableField_holder = new CompositeField($nonEditableField); $nonEditableField_holder->setName($fieldname . '_holder'); $nonEditableField_holder->addExtraClass('originallang_holder'); $nonEditableField->setValue($this->original->{$fieldname}); $nonEditableField->setName($fieldname . '_original'); $nonEditableField->addExtraClass('originallang'); $nonEditableField->setTitle(_t('Translatable_Transform.OriginalFieldLabel', 'Original {title}', 'Label for the original value of the translatable field.', array('title' => $originalField->Title()))); $nonEditableField_holder->insertBefore($originalField, $fieldname . '_original'); return $nonEditableField_holder; }
/** * Update the names of the child fields when updating name of field. * * @param string $name new name to give to the field. */ public function setName($name) { $this->children->fieldByName($this->getName() . '[_Password]')->setName($name . '[_Password]'); $this->children->fieldByName($this->getName() . '[_ConfirmPassword]')->setName($name . '[_ConfirmPassword]'); return parent::setName($name); }
function setName($name) { $this->fieldSelectedValue->setName("{$name}[SelectedValue]"); $this->fieldAlternativeValue->setName("{$name}[AlternativeValue]"); return parent::setName($name); }
public function testGetSchemaData() { $field = new FormField('MyField'); $schema = $field->getSchemaData(); $this->assertEquals('MyField', $schema['name']); // Make sure the schema data is up-to-date with object properties. $field->setName('UpdatedField'); $schema = $field->getSchemaData(); $this->assertEquals($field->getName(), $schema['name']); }