DrupalTranslator::processParameters

protected DrupalTranslator::processParameters(array $parameters)

Processes the parameters array for use with t().

File

core/lib/Drupal/Core/Validation/DrupalTranslator.php, line 72

Class

DrupalTranslator
Translates strings using Drupal's translation system.

Namespace

Drupal\Core\Validation

Code

protected function processParameters(array $parameters) {
  $return = array();
  foreach ($parameters as $key => $value) {
    // We allow the values in the parameters to be safe string objects. This
    // can be useful when we want to use parameter values that are
    // TranslatableMarkup.
    if ($value instanceof MarkupInterface) {
      $value = (string) $value;
    }
    if (is_object($value)) {
      // t() does not work with objects being passed as replacement strings.
    }
    // Check for symfony replacement patterns in the form "{{ name }}".
    elseif (strpos($key, '{{ ') === 0 && strrpos($key, ' }}') == strlen($key) - 3) {
      // Transform it into a Drupal pattern using the format %name.
      $key = '%' . substr($key, 3, strlen($key) - 6);
      $return[$key] = $value;
    }
    else {
      $return[$key] = $value;
    }
  }
  return $return;
}
doc_Drupal
2016-10-29 09:03:08
Comments
Leave a Comment

Please login to continue.