When using Cargo, PageForms allows [[ https://www.mediawiki.org/wiki/Extension:Page_Forms/Input_types#Mapping | mapping ]] values to show different labels to the user than the values that are actually saved in Cargo. When doing this, the page name is used in the where-string to look up the label.
For pages that use multiple templates, this approach does not work. Let's say you have a page (and Cargo table) "Colors", with multiple templates defining ColorName and ColorHexCode. As far as I see, it is not possible to have a form with a field that would save the HexCode to a field in a different table (e.g. Cars), but show the ColorName in the user form.
Below modification (adding a `mapping cargo label` parameter) would allow to do this as follows:
```
{{{field|CarColors
|input type = tokens
|cargo table = Colors
|cargo field = ColorHexCode
|existing values only
|mapping cargo table = Colors
|mapping cargo field = ColorHexCode
|mapping cargo label = ColorName
}}}
```
Patch file for [[ https://github.com/wikimedia/mediawiki-extensions-PageForms/blob/8c769b85b8c1ac7dd9873f4e9e470931077d0317/includes/PF_FormField.php#L697 | /includes/PF_FormField.php ]]:
```
@@ -701,11 +701,19 @@
$value = $index;
}
$labels[$value] = $value;
- $vals = PFValuesUtils::getValuesForCargoField(
- $this->mFieldArgs['mapping cargo table'],
- $this->mFieldArgs['mapping cargo field'],
- '_pageName="' . $value . '"'
- );
+ if ( array_key_exists( 'mapping cargo label', $this->mFieldArgs ) ) {
+ $vals = PFValuesUtils::getValuesForCargoField(
+ $this->mFieldArgs['mapping cargo table'],
+ $this->mFieldArgs['mapping cargo label'],
+ $this->mFieldArgs['mapping cargo field'] . '="' . $value . '"'
+ );
+ } else {
+ $vals = PFValuesUtils::getValuesForCargoField(
+ $this->mFieldArgs['mapping cargo table'],
+ $this->mFieldArgs['mapping cargo field'],
+ '_pageName="' . $value . '"'
+ );
+ }
if ( count( $vals ) > 0 ) {
$labels[$value] = html_entity_decode( trim( $vals[0] ) );
}
```