Page MenuHomePhabricator

PageForms
Open, Needs TriagePublic

Description

When using Cargo, PageForms allows 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 /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] ) );
 			}

Event Timeline

Restricted Application added a subscriber: Aklapper. · View Herald TranscriptNov 22 2020, 4:17 PM

@Platinops: Thanks for taking a look at the code!

You are very welcome to use developer access to submit the proposed code changes as a Git branch directly into Gerrit which makes it easier to review and provide feedback. If you don't want to set up Git/Gerrit, you can also use the Gerrit Patch Uploader. Thanks again.

Peachey88 updated the task description. (Show Details)Nov 22 2020, 7:20 PM