seboettg / citeproc-php

Full-featured CSL 1.0.1 processor for PHP
MIT License
75 stars 39 forks source link

Support for container-title-short in american-medical-association.csl #47

Closed NateWr closed 6 years ago

NateWr commented 6 years ago

Please follow the general troubleshooting steps first:

Bug reports:

I am passing the container-title-short CSL metadata to citeproc-php, but the resulting citiation displays the container-title. I've checked the citation style and it should be using container-title-short, and the CSL team has confirmed that style is working as intended.

Used CSL stylesheet:

https://github.com/citation-style-language/styles/blob/44da95bf112739f5a1e217caebcfebf82b65ca3b/american-medical-association.csl#L221

Used CSL metadata

I'm doing this natively in PHP, so I'm building a standard object and passing it directly to $citeProc->render():

stdClass Object
(
    [type] => article-journal
    [id] => 62
    [title] => Elit nulla ultrices amet iaculis lorem non morbi sed sapien
    [container-title] => Journal of Public Knowledge
    [container-title-short] => publicknowledge
    [volume] => 1
    [issue] => 1
    [section] => Articles
    [URL] => http://localhost/ojs/publicknowledge/article/view/62
    [accessed] => stdClass Object
        (
            [raw] => 2018-02-07
        )

    [author] => Array
        (
            [0] => stdClass Object
                (
                    [family] => Corino
                    [given] => Carlo
                )

        )

    [issued] => stdClass Object
        (
            [raw] => 2017-12-05 16:04:07
        )

    [DOI] => 10.1234/publicknowledge.v1i1.62
)
seboettg commented 6 years ago

Hey Nate! Thank you for contributing this issue. I used the following metadata for testing the described behaviour.

{
  "type": "article-journal",
  "id": 62,
  "title": "Elit nulla ultrices amet iaculis lorem non morbi sed sapien",
  "container-title": "Journal of Public Knowledge",
  "container-title-short": "publicknowledge",
  "volume": 1,
  "issue": 1,
  "section": "Articles",
  "URL": "http:\/\/localhost\/ojs\/publicknowledge\/article\/view\/62",
  "accessed": {
    "raw": "2018-02-07"
  },
  "author": [
    {
      "family": "Corino",
      "given": "Carlo"
    }
  ],
  "issued": {
    "raw": "2017-12-05 16:04:07"
  },
  "DOI": "10.1234\/publicknowledge.v1i1.62"
}

Anyway, I determined the problem in the code here:

if (in_array($this->form, ["short", "long"])) {
    $attrWithPrefix = $this->form . ucfirst($this->toRenderTypeValue);
    if (isset($data->{$attrWithPrefix}) && !empty($data->{$attrWithPrefix})) {
        $renderedText = $this->applyTextCase($data->{$attrWithPrefix}, $lang);
    }
}

You append the substring "short" as a suffix to the variable name (according to CSL schema specs) and in my code it will be looked for a prepended substring "short" as a prefix in lowerCamelCase. That's why "container-title-short" is not rendered.

Interestingly, I've tried to apply your described setup on the reference implementation citeproc-js. And the behaviour is the same. You can try it on http://editor.citationstyles.org/ choose the AMA style and insert your metadata using the button example citations.

However, I've solved the problem and all other tests run without errors. But this issue should also be reported on https://github.com/Juris-M/citeproc-js.

Please test it by using dev-issue-47 for citeproc-php in your composer. json.

NateWr commented 6 years ago

The fix worked. Thanks for the very fast turnaround on this!

Do you have an eta on the next release? We're hoping to ship a new version of our platform in late Feb/early Mar and would love to have a release package we can build into it, but I understand that's a pretty short schedule.

seboettg commented 6 years ago

There is no release planing, so I will make a bugfix release now.

seboettg commented 6 years ago

Okay, new version is released. Please close this ticket, if the new version works as expected.

NateWr commented 6 years ago

Works great, thanks!