Loading islandora_csl.info.yml +2 −1 Original line number Diff line number Diff line name: 'Citation Style Language' type: module description: 'Generate Citation Style Language citations for islandora repository objects' package: 'Custom' core_version_requirement: ^8 || ^9 dependencies: Loading islandora_csl.module +4 −7 Original line number Diff line number Diff line Loading @@ -5,14 +5,11 @@ * Contains islandora_csl.module. */ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\islandora_csl\Encoder\CslEncoder; use Seboettg\CiteProc\StyleSheet; use Seboettg\CiteProc\CiteProc; use Drupal\islandora\Form\IslandoraSettingsForm; /** * Implements hook_theme(). Loading @@ -34,10 +31,10 @@ function islandora_csl_theme() { function islandora_csl_entity_extra_field_info() { $extra_field = []; $bundles = [ // entity_type => [bundle1, bundle2] // entity_type => [bundle1, bundle2]. 'node' => [ 'islandora_object' ] 'islandora_object', ], ]; foreach ($bundles as $entity_type => $bundles) { foreach ($bundles as $bundle) { Loading @@ -60,7 +57,7 @@ function islandora_csl_entity_view(array &$build, EntityInterface $entity, Entit $route_match_item = \Drupal::routeMatch()->getParameters()->get($entity->getEntityTypeId()); // Ensure the entity matches the route. if ($entity === $route_match_item) { // TODO: if you want other bundles than islandora object, check that here // @todo if you want other bundles than islandora object, check that here. if ($entity->bundle() == 'islandora_object' && $display->getComponent('field_islandora_csl')) { $entity_array = $entity->toArray(); Loading src/Encoder/CslEncoder.php +16 −10 Original line number Diff line number Diff line Loading @@ -3,8 +3,6 @@ namespace Drupal\islandora_csl\Encoder; use Symfony\Component\Serializer\Encoder\EncoderInterface; use Drupal\taxonomy\Entity\Term; use Drupal\node\Entity\Node;; /** * CSL format encoder. Loading @@ -25,25 +23,27 @@ class CslEncoder implements EncoderInterface { return $format === self::$format; } /** * {@inheritdoc} */ public function encode($data, $format = '', array $context = []) { $result = []; foreach ($data as $field => $values) { if (empty($values)) continue; if (empty($values)) { continue; } switch ($field) { case 'title': $result['title'] = strip_tags($values[0]['value']); break; case 'field_linked_agent': foreach ($values as $value) { $author = Term::load($value['target_id']); $author = $this->entityTypeManager->getStorage('taxonomy_term')->load($value['target_id']); if ($author) { if ($author->vid->value == 'person') { // assummes format GIVEN [MIDDLE] FAMILY // TODO: improve // Assummes format GIVEN [MIDDLE] FAMILY. // @todo improve. $components = explode(" ", $author->label()); $family = array_pop($components); $given = implode(" ", $components); Loading @@ -60,18 +60,23 @@ class CslEncoder implements EncoderInterface { } } break; case 'field_publication': $term = Term::load($values[0]['target_id']); if ($term) $result['publisher'] = $term->label(); $term = $this->entityTypeManager->getStorage('taxonomy_term')->load($values[0]['target_id']); if ($term) { $result['publisher'] = $term->label(); } break; case 'field_edtf_date_issued': case 'field_edtf_date': $value = strip_tags($values[0]['value']); $result['issued']['date-parts'][] = explode('-', $value); break; case 'nid': $nid = $values[0]['value']; $node = Node::load($nid); $node = $this->nodeStorage->load($nid); if ($node) { $result['id'] = $nid; $result['URL'] = $node->toUrl('canonical', ['absolute' => TRUE])->toString(); Loading @@ -82,4 +87,5 @@ class CslEncoder implements EncoderInterface { return json_encode($result); } } Loading
islandora_csl.info.yml +2 −1 Original line number Diff line number Diff line name: 'Citation Style Language' type: module description: 'Generate Citation Style Language citations for islandora repository objects' package: 'Custom' core_version_requirement: ^8 || ^9 dependencies: Loading
islandora_csl.module +4 −7 Original line number Diff line number Diff line Loading @@ -5,14 +5,11 @@ * Contains islandora_csl.module. */ use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\Core\Entity\Display\EntityViewDisplayInterface; use Drupal\Core\Entity\EntityInterface; use Drupal\islandora_csl\Encoder\CslEncoder; use Seboettg\CiteProc\StyleSheet; use Seboettg\CiteProc\CiteProc; use Drupal\islandora\Form\IslandoraSettingsForm; /** * Implements hook_theme(). Loading @@ -34,10 +31,10 @@ function islandora_csl_theme() { function islandora_csl_entity_extra_field_info() { $extra_field = []; $bundles = [ // entity_type => [bundle1, bundle2] // entity_type => [bundle1, bundle2]. 'node' => [ 'islandora_object' ] 'islandora_object', ], ]; foreach ($bundles as $entity_type => $bundles) { foreach ($bundles as $bundle) { Loading @@ -60,7 +57,7 @@ function islandora_csl_entity_view(array &$build, EntityInterface $entity, Entit $route_match_item = \Drupal::routeMatch()->getParameters()->get($entity->getEntityTypeId()); // Ensure the entity matches the route. if ($entity === $route_match_item) { // TODO: if you want other bundles than islandora object, check that here // @todo if you want other bundles than islandora object, check that here. if ($entity->bundle() == 'islandora_object' && $display->getComponent('field_islandora_csl')) { $entity_array = $entity->toArray(); Loading
src/Encoder/CslEncoder.php +16 −10 Original line number Diff line number Diff line Loading @@ -3,8 +3,6 @@ namespace Drupal\islandora_csl\Encoder; use Symfony\Component\Serializer\Encoder\EncoderInterface; use Drupal\taxonomy\Entity\Term; use Drupal\node\Entity\Node;; /** * CSL format encoder. Loading @@ -25,25 +23,27 @@ class CslEncoder implements EncoderInterface { return $format === self::$format; } /** * {@inheritdoc} */ public function encode($data, $format = '', array $context = []) { $result = []; foreach ($data as $field => $values) { if (empty($values)) continue; if (empty($values)) { continue; } switch ($field) { case 'title': $result['title'] = strip_tags($values[0]['value']); break; case 'field_linked_agent': foreach ($values as $value) { $author = Term::load($value['target_id']); $author = $this->entityTypeManager->getStorage('taxonomy_term')->load($value['target_id']); if ($author) { if ($author->vid->value == 'person') { // assummes format GIVEN [MIDDLE] FAMILY // TODO: improve // Assummes format GIVEN [MIDDLE] FAMILY. // @todo improve. $components = explode(" ", $author->label()); $family = array_pop($components); $given = implode(" ", $components); Loading @@ -60,18 +60,23 @@ class CslEncoder implements EncoderInterface { } } break; case 'field_publication': $term = Term::load($values[0]['target_id']); if ($term) $result['publisher'] = $term->label(); $term = $this->entityTypeManager->getStorage('taxonomy_term')->load($values[0]['target_id']); if ($term) { $result['publisher'] = $term->label(); } break; case 'field_edtf_date_issued': case 'field_edtf_date': $value = strip_tags($values[0]['value']); $result['issued']['date-parts'][] = explode('-', $value); break; case 'nid': $nid = $values[0]['value']; $node = Node::load($nid); $node = $this->nodeStorage->load($nid); if ($node) { $result['id'] = $nid; $result['URL'] = $node->toUrl('canonical', ['absolute' => TRUE])->toString(); Loading @@ -82,4 +87,5 @@ class CslEncoder implements EncoderInterface { return json_encode($result); } }