Project

General

Profile

Revision 0f129a6f

ID0f129a6f839fddb958d1217ddaa1bd8319b06991
Parent afe99f4d
Child dbc2bfa9

Added by Andreas Kohlbecker over 1 year 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.
modules/cdm_dataportal/includes/name.inc
364 364
      $taggedName = $taggedNameNew;
365 365
      unset($taggedNameNew);
366 366
    }
367
    $name = '<span class="' . $taxonName->class . '">' . $doubtful_marker_markup . $name_encasement . cdm_tagged_text_to_markup($taggedName, 'span', ' ', $skiptags) . $name_encasement . '</span>';
367
    $name = '<span class="' . $taxonName->class . '">' . $doubtful_marker_markup . $name_encasement . cdm_tagged_text_to_markup($taggedName, $skiptags) . $name_encasement . '</span>';
368 368
  }
369 369
  else {
370 370
    $name = '<span class="' . $taxonName->class . '_titleCache">' . $doubtful_marker_markup . $name_encasement . $taxonName->titleCache . $name_encasement . '</span>';
......
451 451
  // Fill with status.
452 452
  if(isset($renderTemplate['statusPart']['status'])){
453 453
    if (isset($nom_status_tagged_text[0])) {
454
        array_setr('status', '<span class="nomenclatural_status">' . cdm_tagged_text_to_markup($nom_status_tagged_text, 'span', '', array('postSeparator')) . '</span>', $renderTemplate);
454
        array_setr('status', '<span class="nomenclatural_status">' . cdm_tagged_text_to_markup($nom_status_tagged_text, array('postSeparator')) . '</span>', $renderTemplate);
455 455
    }
456 456
  }
457 457

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)