-
Notifications
You must be signed in to change notification settings - Fork 4
Use named parameters to simplify the FieldHelper::control() function (CFM-269) #92
Merged
+79
−80
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -78,18 +78,24 @@ public function banner(string $info): string { | |
| * @param string $fieldName Form field | ||
| * @param array $options FormHelper control options | ||
| * @param string $labelText Label text (fieldName language key used by default) | ||
| * @param array $config Custom FormHelper configuration options | ||
| * @param string $ctrlCode Control code passed in from wrapper functions | ||
| * @param string $cssClass Start li css class passed in from wrapper functions | ||
| * @param string $beforeField Markup to be placed before/above the field | ||
| * @param string $afterField Markup to be placed after/below the field | ||
| * @param string $prefix Field prefix - used for API Usernames | ||
| * @param bool $labelIsTextOnly For fields that should not include <label> markup | ||
| * @return string HTML for control | ||
| */ | ||
|
|
||
| public function control(string $fieldName, | ||
| array $options=[], | ||
| string $labelText=null, | ||
| array $config=[], | ||
| string $ctrlCode=null, | ||
| string $cssClass=''): string { | ||
| array $options = [], | ||
| string $labelText = null, | ||
| string $ctrlCode = null, | ||
| string $cssClass = '', | ||
| string $beforeField = '', | ||
| string $afterField = '', | ||
| string $prefix = '', | ||
| bool $labelIsTextOnly = false): string { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is just adding space around the " = " for easier reading. |
||
| $coptions = $options; | ||
| $coptions['label'] = false; | ||
| $coptions['readonly'] = | ||
|
|
@@ -107,18 +113,11 @@ public function control(string $fieldName, | |
| $fieldMap = $this->getView()->get('vv_field_types'); | ||
| $fieldType = $fieldMap[$fieldName]; | ||
|
|
||
| // Collect any supplemental markup and/or JavaScript to pass along for field construction. | ||
| // Suppliment is an array: supplement['beforeField' => 'string', 'afterField' => 'string']. | ||
| $fieldSupplement = !empty($config['supplement']) ? $config['supplement'] : []; | ||
|
|
||
| // For special fields that should not include <label> markup, allow fields to make the label text only | ||
| $labelIsTextOnly = !empty($config['labelIsTextOnly']) ? $config['labelIsTextOnly'] : false; | ||
|
|
||
| // Remove prefix from field value | ||
| if(isset($config['prefix'], $this->getView()->get('vv_obj')->$fieldName)) { | ||
| if(!empty($prefix) && !empty($this->getView()->get('vv_obj')->$fieldName)) { | ||
| $vv_obj = $this->getView()->get('vv_obj'); | ||
| $fieldValue = $vv_obj->$fieldName; | ||
| $fieldValueTemp = str_replace($config['prefix'], '', $fieldValue); | ||
| $fieldValueTemp = str_replace($prefix, '', $fieldValue); | ||
| $vv_obj->$fieldName = $fieldValueTemp; | ||
| $this->getView()->set('vv_obj', $vv_obj); | ||
| } | ||
|
|
@@ -174,9 +173,9 @@ public function control(string $fieldName, | |
|
|
||
| return $this->startLine($liClass) | ||
| . $this->formNameDiv($fieldName, $labelText, $fieldType, $labelIsTextOnly) | ||
| . ( !empty($config['prefix']) ? | ||
| $this->formInfoWithPrefixDiv($controlCode, $config['prefix'], $fieldSupplement) : | ||
| $this->formInfoDiv($controlCode, $fieldSupplement) ) | ||
| . ( !empty($prefix) ? | ||
| $this->formInfoWithPrefixDiv($controlCode, $prefix, $beforeField, $afterField) : | ||
| $this->formInfoDiv($controlCode, $beforeField, $afterField) ) | ||
| . $this->endLine(); | ||
| } | ||
|
|
||
|
|
@@ -261,7 +260,7 @@ public function dateControl(string $fieldName, string $dateType=DateTypeEnum::St | |
| $liClass = "fields-datepicker"; | ||
|
|
||
| // Pass everything to the generic control() function | ||
| return $this->control($fieldName, $coptions, '', [], $controlCode, $liClass); | ||
| return $this->control($fieldName, $coptions, ctrlCode: $controlCode, cssClass: $liClass); | ||
| } | ||
|
|
||
| /** | ||
|
|
@@ -293,18 +292,21 @@ protected function endLine(): string { | |
| * | ||
| * @since COmanage Registry v5.0.0 | ||
| * @param string $content Content HTML | ||
| * @param string $supplement Supplemental markup to place before and/or after the field control | ||
| * @param string $beforeField Markup to be placed before/above the field | ||
| * @param string $afterField Markup to be placed after/below the field | ||
| * @return string Form Info HTML | ||
| */ | ||
|
|
||
| protected function formInfoDiv(string $content, array $supplement): string { | ||
| protected function formInfoDiv(string $content, | ||
| string $beforeField = '', | ||
| string $afterField = ''): string { | ||
| $div = '<div class="field-info">' . PHP_EOL; | ||
| if(!empty($supplement['beforeField'])) { | ||
| $div .= $supplement['beforeField'] . PHP_EOL; | ||
| if(!empty($beforeField)) { | ||
| $div .= $beforeField . PHP_EOL; | ||
| } | ||
| $div .= $content . PHP_EOL; | ||
| if(!empty($supplement['afterField'])) { | ||
| $div .= $supplement['afterField'] . PHP_EOL; | ||
| if(!empty($afterField)) { | ||
| $div .= $afterField . PHP_EOL; | ||
| } | ||
| $div .= '</div>' . PHP_EOL; | ||
|
|
||
|
|
@@ -315,25 +317,29 @@ protected function formInfoDiv(string $content, array $supplement): string { | |
| * Generate a form info (control, value) box with a non editable prefix. | ||
| * | ||
| * @since COmanage Registry v5.0.0 | ||
| * @param string $content Content HTML | ||
| * @param string $prefix Prefix value | ||
| * @param string $supplement Supplemental markup to place before and/or after the field control | ||
| * @return string Form Info HTML | ||
| * @param string $content Content HTML | ||
| * @param string $prefix Prefix value | ||
| * @param string $beforeField Markup to be placed before/above the field | ||
| * @param string $afterField Markup to be placed after/below the field | ||
| * @return string Form Info HTML | ||
| */ | ||
|
|
||
| protected function formInfoWithPrefixDiv(string $context, string $prefix, array $supplement): string { | ||
| protected function formInfoWithPrefixDiv(string $context, | ||
| string $prefix, | ||
| string $beforeField = '', | ||
| string $afterField = ''): string { | ||
| $div = '<div class="field-info">' . PHP_EOL; | ||
| if(!empty($supplement['beforeField'])) { | ||
| $div .= $supplement['beforeField'] . PHP_EOL; | ||
| if(!empty($beforeField)) { | ||
| $div .= $beforeField . PHP_EOL; | ||
| } | ||
| $div .= '<div class="input-group mb-3">' . PHP_EOL; | ||
| $div .= '<div class="input-group-prepend">' . PHP_EOL; | ||
| $div .= '<span class="input-group-text" id="basic-addon3">' . $prefix . '</span>'; | ||
| $div .= '</div>' . PHP_EOL; | ||
| $div .= $context; | ||
| $div .= '</div>'; | ||
| if(!empty($supplement['afterField'])) { | ||
| $div .= $supplement['afterField'] . PHP_EOL; | ||
| if(!empty($afterField)) { | ||
| $div .= $afterField . PHP_EOL; | ||
| } | ||
| $div .= '</div>'; | ||
|
|
||
|
|
@@ -467,15 +473,15 @@ protected function formNameDiv(string $fieldName, string $labelText=null, string | |
| * @param string $status Status text | ||
| * @param array $link Link information, including 'url', 'label', 'class', 'confirm' | ||
| * @param string $labelText Label text (fieldName language key used by default) | ||
| * @param array $config Custom FormHelper configuration options | ||
| * @param boolean $labelIsTextOnly true if <label> wrapper should not be included in the markup | ||
| * @return string | ||
| */ | ||
|
|
||
| public function statusControl(string $fieldName, | ||
| string $status, | ||
| array $link=[], | ||
| string $labelText=null, | ||
| array $config=[]): string { | ||
| array $link=[], | ||
| string $labelText = null, | ||
| bool $labelIsTextOnly = false): string { | ||
| $linkHtml = $status; | ||
|
|
||
| if($link) { | ||
|
|
@@ -500,9 +506,6 @@ public function statusControl(string $fieldName, | |
| ); | ||
| } | ||
| } | ||
|
|
||
| // For special fields that should not include <label> markup, allow fields to make the label text only | ||
| $labelIsTextOnly = !empty($config['labelIsTextOnly']) ? $config['labelIsTextOnly'] : false; | ||
|
|
||
| return $this->startLine() | ||
| . $this->formNameDiv($fieldName, $labelText, 'string', $labelIsTextOnly) | ||
|
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$config contained array elements now represented by the new parameters just below; we've flattened all this out for clarity and to provide default values.