public function csl_label::render in Bibliography Module 7
Same name and namespace in other branches
- 6.2 modules/CiteProc/CSL.inc \csl_label::render()
- 7.2 modules/CiteProc/CSL.inc \csl_label::render()
Overrides csl_rendering_element::render
File
- modules/
CiteProc/ CSL.inc, line 1542 - CiteProc-PHP.
Class
Code
public function render($data, $mode = NULL) {
$text = '';
$pluralization = NULL;
$form = ($form = $this->form) ? $form : 'long';
// There are two possible locations for a label the first is within a names element which is a bit simpler than the general label case
// within csl_names element case.
if (isset($this->in_names)) {
if ($term = $this->citeproc
->get_locale('term', $this->variable, $form, $this->plural)) {
$text = $term;
}
}
else {
$variables = explode(' ', $this->variable);
switch ($this->plural) {
case 'never':
$pluralization = 'single';
break;
case 'always':
$pluralization = 'multiple';
break;
case 'contextual':
default:
}
foreach ($variables as $variable) {
$field = $this->citeproc
->map_field($variable);
if (isset($data->{$field}) && !empty($data->{$field})) {
if (!isset($this->plural) && empty($pluralization) && is_array($data->{$field})) {
$count = count($data->{$field});
if ($count == 1) {
$pluralization = 'single';
}
elseif ($count > 1) {
$pluralization = 'multiple';
}
}
else {
$pluralization = $this
->evaluateStringPluralism($data, $variable);
}
if ($term = $this->citeproc
->get_locale('term', $variable, $form, $pluralization)) {
$text = $term;
break;
}
}
}
}
if (empty($text)) {
return;
}
if ($this->{'strip-periods'}) {
$text = str_replace('.', '', $text);
}
return $this
->format($text);
}