Uploaded image for project: 'In-Portal CMS'
  1. In-Portal CMS
  2. INP-1380

Use named parameters in error messages and add new parameter {field}

    XMLWordPrintable

    Details

    • Change Log Group:
      Added
    • Change Log Message:
      Added ability to use field title in the validation error messages (e.g. "First Name is required" instead of "Field is required").
    • Story Points:
      1
    • Copy Issue Key:
    • Patch Instructions:

      Patches must be submitted through Phabricator.

    • BC Break Details:
      Hide
      • the "%s", "%1$s" and similar are no longer processed inside error message phrases and cause notice

      Solution

      In the "kValidator::GetErrorMsg" method, when "$params" (error message params) array:

      • when error message contains "%" that is followed by non-whitespace symbol we execute old code (get from SVN), where "sprintf" was used
      • otherwise execute current code with " {param_name}" replacement

      At the end both approach should work, since we're not planning to deprecate "%s" approach in error messages.

      Show
      the "%s", "%1$s" and similar are no longer processed inside error message phrases and cause notice Solution In the "kValidator::GetErrorMsg" method, when "$params" (error message params) array: when error message contains "%" that is followed by non-whitespace symbol we execute old code (get from SVN), where "sprintf" was used otherwise execute current code with " {param_name}" replacement At the end both approach should work, since we're not planning to deprecate "%s" approach in error messages.

      Description

      1. locate "SetError" methods calls in the "kValidator" class, where additional parameters are passed to the error (I found 3)
      2. in each found case transform index-based parameter array into associative array by assigning name for each of given parameters
      3. in the "GetErrorMsg" method:

      • add "array_values" before giving error params to "vsprintf" function
      • after call to "ReplaceLanguageTags" we need to add "field" parameter to the error parameters, which value would be translation of this phrase: "la_fld_FieldName" (in Admin Console) and "lu_fld_FieldName" (on Front-End)
      • replace all named parameter occurrences in a string (before "la-la {param_name}

        la-la", after "la-la value_of_param_name_parameter la-la")

      • after named parameter is replaced (check number of actual replacements made) remove it from parameter list

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                alex Alex
                Reporter:
                glebs Gleb Sinkovskiy [Intechnic]
                Developer:
                Gleb Sinkovskiy [Intechnic]
                Reviewer:
                Alex
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: