You are here

public function TMGMTDefaultTranslatorPluginController::escapeText in Translation Management Tool 7

Returns the escaped #text of a data item.

Parameters

array $data_item: A data item with a #text and optional #escape definitions.

Return value

string The text of the data item with translator-specific escape patterns applied.

Overrides TMGMTTranslatorPluginControllerInterface::escapeText

File

plugin/tmgmt.plugin.translator.inc, line 206
Contains the abstract translator base plugin class.

Class

TMGMTDefaultTranslatorPluginController
Default controller class for service plugins.

Code

public function escapeText(array $data_item) {
  if (empty($data_item['#escape'])) {
    return $data_item['#text'];
  }
  $text = $data_item['#text'];
  $escape = $data_item['#escape'];

  // Sort them in reverse order based/ on the position and process them,
  // so that positions don't change.
  krsort($escape, SORT_NUMERIC);
  foreach ($escape as $position => $info) {
    $text = substr_replace($text, $this
      ->getEscapedString($info['string']), $position, strlen($info['string']));
  }
  return $text;
}