diff --git a/composer.json b/composer.json
index c7372bb521..4af67296db 100644
--- a/composer.json
+++ b/composer.json
@@ -30,10 +30,11 @@
],
"require": {
"php": ">=7.4",
- "academicpuma/locales": "1.0.0",
"az-digital/arizona-bootstrap": "2.0.23",
"bower-asset/bootstrap-datepicker": "1.9.0",
"bower-asset/chosen": "1.8.7",
+ "citation-style-language/locales": "0.0.5",
+ "citation-style-language/styles": "0.0.199",
"composer/installers": "^1.9",
"cweagans/composer-patches": "^1.7",
"drupal/access_unpublished": "1.5.0",
@@ -113,7 +114,7 @@
"npm-asset/blazy": "1.8.2",
"npm-asset/jquery-ui-touch-punch": "0.2.3",
"npm-asset/slick-carousel": "1.8.0",
- "seboettg/citeproc-php": "2.5.1"
+ "seboettg/citeproc-php": "2.6.0"
},
"require-dev": {
"az-digital/az-quickstart-dev": "~1"
@@ -123,9 +124,6 @@
"dev-main": "2.7.x-dev"
},
"patches": {
- "seboettg/citeproc-php": {
- "allow citeproc academicpuma scoping": "https://gist.githubusercontent.com/tadean/aa6b130f49882ba955321847f4fa6fc8/raw/a4e9ba97a9d7f9812a218b55018dfa4b02082379/citeproc_academicpuma_az_publication.patch"
- },
"drupal/antibot": {
"drupalSettings not updated on rendering form in Ajax (3205217)": "https://www.drupal.org/files/issues/2021-03-24/3205217-1.patch"
},
diff --git a/modules/custom/az_publication/az_publication.module b/modules/custom/az_publication/az_publication.module
index 2ecdf292c0..c6431b135f 100644
--- a/modules/custom/az_publication/az_publication.module
+++ b/modules/custom/az_publication/az_publication.module
@@ -17,6 +17,8 @@ use Drupal\Core\Link;
use Symfony\Component\HttpFoundation\Request;
use Drupal\node\NodeInterface;
use Drupal\az_publication\Plugin\views\argument\AZCitationStyleArgument;
+use Seboettg\CiteProc\StyleSheet;
+use Seboettg\CiteProc\Exception\CiteProcException;
/**
* Implements hook_entity_extra_field_info().
@@ -159,7 +161,22 @@ function az_publication_node_view(array &$build, EntityInterface $entity, Entity
$style = "az_publication.az_citation_style." . $style_context;
// Load style if available.
$config = \Drupal::config($style);
- $style_info = $config->get('style');
+ $style_info = '';
+ $csl_style_name = $config->get('style');
+ $custom_style = $config->get('custom');
+ // Known styles from CSL package.
+ if (!empty($csl_style_name)) {
+ try {
+ $style_info = StyleSheet::loadStyleSheet($csl_style_name);
+ }
+ catch (CiteProcException $e) {
+ $style_info = '';
+ }
+ }
+ // Custom stylesheet.
+ if (!empty($custom_style)) {
+ $style_info = $custom_style;
+ }
if (!empty($style_info)) {
// Add cache tag based on citation mode.
diff --git a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_ama.yml b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_ama.yml
index 817dcf0c6d..4658da96ba 100644
--- a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_ama.yml
+++ b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_ama.yml
@@ -3,4 +3,5 @@ status: true
dependencies: { }
id: az_ama
label: 'American Medical Association Style (AMA)'
-style: "\r\n\r\n"
+style: american-medical-association
+custom: ''
diff --git a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_apa.yml b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_apa.yml
index 27bdabd5a1..6907621e50 100644
--- a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_apa.yml
+++ b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_apa.yml
@@ -3,4 +3,5 @@ status: true
dependencies: { }
id: az_apa
label: 'American Psychological Association Style (APA)'
-style: "\r\n\r\n"
+style: apa
+custom: ''
diff --git a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_bluebook.yml b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_bluebook.yml
index 4382c3cc8c..cbc2b5d37c 100644
--- a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_bluebook.yml
+++ b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_bluebook.yml
@@ -3,4 +3,5 @@ status: true
dependencies: { }
id: az_bluebook
label: 'Bluebook Law Review Style'
-style: "\r\n\r\n"
+style: ''
+custom: "\r\n\r\n"
diff --git a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_chicago.yml b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_chicago.yml
index abc5eda5a0..dcff9b9276 100644
--- a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_chicago.yml
+++ b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_chicago.yml
@@ -3,4 +3,5 @@ status: true
dependencies: { }
id: az_chicago
label: 'Chicago Manual of Style (CMOS)'
-style: "\r\n\r\n"
+style: chicago-fullnote-bibliography
+custom: ''
diff --git a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_ieee.yml b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_ieee.yml
index 9918b38553..0773ee8d7a 100644
--- a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_ieee.yml
+++ b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_ieee.yml
@@ -3,4 +3,5 @@ status: true
dependencies: { }
id: az_ieee
label: 'Institute of Electrical and Electronics Engineers Style (IEEE)'
-style: "\r\n\r\n"
+style: ieee
+custom: ''
diff --git a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_mla.yml b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_mla.yml
index 9981f25412..7bade6f1e9 100644
--- a/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_mla.yml
+++ b/modules/custom/az_publication/config/install/az_publication.az_citation_style.az_mla.yml
@@ -3,4 +3,5 @@ status: true
dependencies: { }
id: az_mla
label: 'Modern Language Association Style (MLA)'
-style: "\r\n\r\n"
+style: modern-language-association
+custom: ''
diff --git a/modules/custom/az_publication/config/schema/az_citation_style.schema.yml b/modules/custom/az_publication/config/schema/az_citation_style.schema.yml
index 337a9075db..a37f1abb46 100644
--- a/modules/custom/az_publication/config/schema/az_citation_style.schema.yml
+++ b/modules/custom/az_publication/config/schema/az_citation_style.schema.yml
@@ -11,5 +11,8 @@ az_publication.az_citation_style.*:
style:
type: string
label: 'Style'
+ custom:
+ type: string
+ label: 'Custom Citation Style Language'
uuid:
type: string
diff --git a/modules/custom/az_publication/src/Entity/AZQuickstartCitationStyle.php b/modules/custom/az_publication/src/Entity/AZQuickstartCitationStyle.php
index af4ff5d6d1..61a095266b 100644
--- a/modules/custom/az_publication/src/Entity/AZQuickstartCitationStyle.php
+++ b/modules/custom/az_publication/src/Entity/AZQuickstartCitationStyle.php
@@ -32,7 +32,8 @@
* config_export = {
* "id",
* "label",
- * "style"
+ * "style",
+ * "custom"
* },
* config_prefix = "az_citation_style",
* admin_permission = "administer site configuration",
@@ -90,4 +91,21 @@ public function setStyle($style) {
return $this;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function getCustom() {
+ return $this
+ ->get('custom');
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function setCustom($custom) {
+ $this
+ ->set('custom', $custom);
+ return $this;
+ }
+
}
diff --git a/modules/custom/az_publication/src/Entity/AZQuickstartCitationStyleInterface.php b/modules/custom/az_publication/src/Entity/AZQuickstartCitationStyleInterface.php
index 3fdcc90e43..fae98c9e38 100644
--- a/modules/custom/az_publication/src/Entity/AZQuickstartCitationStyleInterface.php
+++ b/modules/custom/az_publication/src/Entity/AZQuickstartCitationStyleInterface.php
@@ -27,4 +27,22 @@ public function getStyle();
*/
public function setStyle($style);
+ /**
+ * Returns the custom csl stylesheet.
+ *
+ * @return string
+ * The custom CSL stylesheet of this citation style.
+ */
+ public function getCustom();
+
+ /**
+ * Sets the custom csl stylesheet.
+ *
+ * @param string $custom
+ * The desired custom CSL stylesheet.
+ *
+ * @return $this
+ */
+ public function setCustom($custom);
+
}
diff --git a/modules/custom/az_publication/src/Form/AZQuickstartCitationStyleForm.php b/modules/custom/az_publication/src/Form/AZQuickstartCitationStyleForm.php
index 70867ceff1..2e8d902b2c 100644
--- a/modules/custom/az_publication/src/Form/AZQuickstartCitationStyleForm.php
+++ b/modules/custom/az_publication/src/Form/AZQuickstartCitationStyleForm.php
@@ -4,6 +4,8 @@
use Drupal\Core\Entity\EntityForm;
use Drupal\Core\Form\FormStateInterface;
+use Seboettg\CiteProc\StyleSheet;
+use Seboettg\CiteProc\Exception\CiteProcException;
/**
* Class AZQuickstartCitationStyleForm provides a form for editing CSL styles.
@@ -37,20 +39,71 @@ public function form(array $form, FormStateInterface $form_state) {
];
$form['style'] = [
+ '#type' => 'textfield',
+ '#title' => $this->t('Citation Style Language Style'),
+ '#size' => 60,
+ '#maxlength' => 128,
+ '#default_value' => $az_citation_style->getStyle(),
+ '#description' => $this->t('The name of a known CSL stylesheet in the Citation Style Language standard, e.g. apa. For reference, consult the Citation Style Language project and GitHub repository.', [
+ '@csl' => 'https://citationstyles.org/',
+ '@csl-repo' => 'https://github.com/citation-style-language/styles',
+ ]),
+ '#required' => FALSE,
+ ];
+
+ $open = !empty($az_citation_style->getCustom());
+
+ $form['custom_container'] = [
+ '#type' => 'details',
+ '#open' => $open,
+ '#title' => $this
+ ->t('Custom Citation Style Language'),
+ ];
+
+ $form['custom_container']['custom'] = [
'#type' => 'textarea',
'#title' => $this->t('Citation Style Language'),
'#rows' => 15,
- '#default_value' => $az_citation_style->getStyle(),
- '#description' => $this->t('A stylesheet in Citation Style Language (CSL). For reference, consult the Citation Style Language project and GitHub repository.', [
+ '#default_value' => $az_citation_style->getCustom(),
+ '#description' => $this->t('A custom stylesheet in Citation Style Language (CSL). This field is only necessary if you have a custom citation style. For reference, consult the Citation Style Language project and GitHub repository.', [
'@csl' => 'https://citationstyles.org/',
'@csl-repo' => 'https://github.com/citation-style-language/styles',
]),
- '#required' => TRUE,
+ '#required' => FALSE,
];
return $form;
}
+ /**
+ * {@inheritdoc}
+ */
+ public function validateForm(array &$form, FormStateInterface $form_state) {
+ $values = $form_state->getValues();
+ if (empty($values['style']) && empty($values['custom'])) {
+ $form_state->setErrorByName('style', $this->t('You must enter either a CSL stylesheet name or custom CSL.'));
+ }
+ if (!empty($values['style']) && !empty($values['custom'])) {
+ $form_state->setErrorByName('style', $this->t('You must enter either a CSL stylesheet name or custom CSL, not both.'));
+ }
+ if (!empty($values['style'])) {
+ try {
+ $style = StyleSheet::loadStyleSheet($values['style']);
+ }
+ catch (CiteProcException $e) {
+ $form_state->setErrorByName('style', $this->t('The stylesheet name is not valid.'));
+ }
+ }
+ if (!empty($values['custom'])) {
+ libxml_use_internal_errors(TRUE);
+ $doc = simplexml_load_string($values['custom']);
+ if ($doc === FALSE) {
+ $form_state->setErrorByName('custom', $this->t('A custom CSL stylesheet must be valid XML.'));
+ }
+ libxml_clear_errors();
+ }
+ }
+
/**
* {@inheritdoc}
*/