Differential D14402 Diff 34804 src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/view/PhabricatorApplicationEditHTTPParameterHelpView.php
| Show All 37 Lines | public function render() { | ||||
| // Remove fields which do not expose an HTTP parameter type. | // Remove fields which do not expose an HTTP parameter type. | ||||
| $types = array(); | $types = array(); | ||||
| foreach ($fields as $key => $field) { | foreach ($fields as $key => $field) { | ||||
| $type = $field->getHTTPParameterType(); | $type = $field->getHTTPParameterType(); | ||||
| if ($type === null) { | if ($type === null) { | ||||
| unset($fields[$key]); | unset($fields[$key]); | ||||
| } | } | ||||
| $types[$type][] = $field; | $types[$type->getTypeName()] = $type; | ||||
| } | } | ||||
| $intro = pht(<<<EOTEXT | $intro = pht(<<<EOTEXT | ||||
| When creating objects in the web interface, you can use HTTP parameters to | When creating objects in the web interface, you can use HTTP parameters to | ||||
| prefill fields in the form. This allows you to quickly create a link to a | prefill fields in the form. This allows you to quickly create a link to a | ||||
| form with some of the fields already filled in with default values. | form with some of the fields already filled in with default values. | ||||
| To prefill a form, start by finding the URI for the form you want to prefill. | To prefill a form, start by finding the URI for the form you want to prefill. | ||||
| Show All 35 Lines | EOTEXT | ||||
| $uri, | $uri, | ||||
| $uri); | $uri); | ||||
| $rows = array(); | $rows = array(); | ||||
| foreach ($fields as $field) { | foreach ($fields as $field) { | ||||
| $rows[] = array( | $rows[] = array( | ||||
| $field->getLabel(), | $field->getLabel(), | ||||
| $field->getKey(), | $field->getKey(), | ||||
| $field->getHTTPParameterType(), | $field->getHTTPParameterType()->getTypeName(), | ||||
| $field->getDescription(), | $field->getDescription(), | ||||
| ); | ); | ||||
| } | } | ||||
| $main_table = id(new AphrontTableView($rows)) | $main_table = id(new AphrontTableView($rows)) | ||||
| ->setHeaders( | ->setHeaders( | ||||
| array( | array( | ||||
| pht('Label'), | pht('Label'), | ||||
| ▲ Show 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | |||||
| Field Types | Field Types | ||||
| ----------- | ----------- | ||||
| Fields in this form have the types described in the table below. This table | Fields in this form have the types described in the table below. This table | ||||
| shows how to format values for each field type. | shows how to format values for each field type. | ||||
| EOTEXT | EOTEXT | ||||
| ); | ); | ||||
| // TODO: This should be formalized and modularized. | $types_table = id(new PhabricatorHTTPParameterTypeTableView()) | ||||
| $type_spec = array( | ->setHTTPParameterTypes($types); | ||||
| 'string' => array( | |||||
| 'format' => pht('URL encoded text.'), | |||||
| 'examples' => array( | |||||
| 'v=simple', | |||||
| 'v=properly%20escaped%20text', | |||||
| ), | |||||
| ), | |||||
| 'select' => array( | |||||
| 'format' => pht('Value from allowed set.'), | |||||
| 'examples' => array( | |||||
| 'v=value', | |||||
| ), | |||||
| ), | |||||
| 'list<phid>' => array( | |||||
| 'format' => array( | |||||
| pht('Comma-separated list of PHIDs.'), | |||||
| pht('List of PHIDs, as array.'), | |||||
| ), | |||||
| 'examples' => array( | |||||
| 'v=PHID-XXXX-1111,PHID-XXXX-2222', | |||||
| 'v[]=PHID-XXXX-1111&v[]=PHID-XXXX-2222', | |||||
| ), | |||||
| ), | |||||
| 'phid' => array( | |||||
| 'format' => pht('Single PHID.'), | |||||
| 'examples' => pht('v=PHID-XXX-1111'), | |||||
| ), | |||||
| ); | |||||
| $rows = array(); | |||||
| $br = phutil_tag('br'); | |||||
| foreach ($types as $type => $fields) { | |||||
| $spec = idx($type_spec, $type, array()); | |||||
| $field_list = mpull($fields, 'getKey'); | |||||
| $field_list = phutil_implode_html($br, $field_list); | |||||
| $format_list = idx($spec, 'format', array()); | |||||
| $format_list = phutil_implode_html($br, (array)$format_list); | |||||
| $example_list = idx($spec, 'examples', array()); | |||||
| $example_list = phutil_implode_html($br, (array)$example_list); | |||||
| $rows[] = array( | |||||
| $type, | |||||
| $field_list, | |||||
| $format_list, | |||||
| $example_list, | |||||
| ); | |||||
| } | |||||
| $types_table = id(new AphrontTableView($rows)) | |||||
| ->setNoDataString(pht('This object has no fields with types.')) | |||||
| ->setHeaders( | |||||
| array( | |||||
| pht('Type'), | |||||
| pht('Fields'), | |||||
| pht('Formats'), | |||||
| pht('Examples'), | |||||
| )) | |||||
| ->setColumnClasses( | |||||
| array( | |||||
| 'pri top', | |||||
| 'top', | |||||
| 'top', | |||||
| 'wide top prewrap', | |||||
| )); | |||||
| return array( | return array( | ||||
| $this->renderInstructions($intro), | $this->renderInstructions($intro), | ||||
| $main_table, | $main_table, | ||||
| $this->renderInstructions($aliases_text), | $this->renderInstructions($aliases_text), | ||||
| $alias_table, | $alias_table, | ||||
| $this->renderInstructions($select_text), | $this->renderInstructions($select_text), | ||||
| $select_table, | $select_table, | ||||
| Show All 11 Lines | |||||