Project

General

Profile

« Previous | Next » 

Revision 0f129a6f

Added by Andreas Kohlbecker over 5 years ago

fix #7605 fixing probelms with space around separators by hamonizing with cdmlib reference implementation

View differences:

modules/cdm_dataportal/cdm_api/cdm_api.module
236 236
 *
237 237
 * @param array $taggedtxt
238 238
 *   Array with text items to convert.
239
 * @param string $tag
240
 *   Html tag name to convert the items into, default is 'span'.
241
 * @param string $glue
242
 *   The string by which the chained text tokens are concatenated together.
243
 *   Default is a blank character.
239
 * @param array $skiptags
240
 *   Array of tag names to skip
244 241
 *
245 242
 * @return string
246 243
 *   A string with HTML.
247 244
 */
248
function cdm_tagged_text_to_markup(array $taggedtxt, $tag = 'span', $glue = ' ', $skiptags = array()) {
245
function cdm_tagged_text_to_markup(array $taggedtxt, $skiptags = array()) {
246

  
247
  $tag = 'span';
249 248
  $out = '';
250
  $i = 0;
249
  $was_separator = false;
251 250
  foreach ($taggedtxt as $tt) {
252
    if (!in_array($tt->type, $skiptags) && strlen($tt->text) > 0) {
251
    if (!in_array($tt->type, $skiptags) && $tt->text) {
253 252
      $class_attr = $tt->type;
253

  
254 254
      if(isset($tt->entityReference)){
255 255
        $class_attr .= " " . html_class_attribute_ref($tt->entityReference);
256 256
      }
257
      $out .= (strlen($out) > 0 && ++$i < count($taggedtxt) ? $glue : '')
258
        . '<' . $tag . ' class="' . $class_attr . '">'
257
      $is_separator = is_tagged_text_sepatator_type($tt->type);
258
      $glue = !$is_separator && !$was_separator ? ' ' : '';
259
      $out .= '<' . $tag . ' class="' . $class_attr . '">'
259 260
        . t('@text', array('@text' => $tt->text))
260
        . '</' . $tag . '>';
261
        . '</' . $tag . '>'
262
        . $glue;
263
      $was_separator = $is_separator;
261 264
    }
262 265
  }
263 266
  return $out;
264 267
}
265 268

  
269
/**
270
 * See cdmlib: boolean eu.etaxonomy.cdm.strategy.cache.TagEnum.isSeparator();
271
 *
272
 * @return bool
273
 */
274
function is_tagged_text_sepatator_type($tagged_text_type){
275
    static $separator_names = array('separator', 'postSeparator');
276
		$result = array_search($tagged_text_type, $separator_names) !== false;
277
    return $result;
278
}
279

  
266 280

  
267 281
/**
268 282
 * Finds the text tagged with $tag_type in an array of taggedText instances.

Also available in: Unified diff