From 49dc651787b57f7496afc5e900e01fd0270429e3 Mon Sep 17 00:00:00 2001 From: Prashant Kanse Date: Mon, 18 Dec 2023 15:08:48 +0530 Subject: [PATCH 1/2] DGIR-124 : Add default URL to citation block --- src/Form/SelectCslForm.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Form/SelectCslForm.php b/src/Form/SelectCslForm.php index fc3a9ee..d3d23cb 100644 --- a/src/Form/SelectCslForm.php +++ b/src/Form/SelectCslForm.php @@ -6,6 +6,8 @@ use Drupal\Core\Form\FormBase; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Routing\RouteMatchInterface; +use Drupal\Core\Url; +use Drupal\path_alias\AliasManagerInterface; use Drupal\islandora_citations\IslandoraCitationsHelper; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -39,13 +41,24 @@ class SelectCslForm extends FormBase { */ protected $entityTypeManager; + /** + * Definition of path alias manager. + * + * @var \Drupal\path_alias\AliasManager + */ + protected $pathAliasManager; + /** * {@inheritdoc} */ - public function __construct(IslandoraCitationsHelper $citationHelper, RouteMatchInterface $route_match, EntityTypeManagerInterface $entity_type_manager) { + public function __construct(IslandoraCitationsHelper $citationHelper, + RouteMatchInterface $route_match, + EntityTypeManagerInterface $entity_type_manager, + AliasManagerInterface $pathAliasManager) { $this->citationHelper = $citationHelper; $this->routeMatch = $route_match; $this->entityTypeManager = $entity_type_manager; + $this->pathAliasManager = $pathAliasManager; } /** @@ -55,7 +68,8 @@ public static function create(ContainerInterface $container) { return new static( $container->get('islandora_citations.helper'), $container->get('current_route_match'), - $container->get('entity_type.manager') + $container->get('entity_type.manager'), + $container->get('path_alias.manager') ); } @@ -190,6 +204,13 @@ private function renderCitation($csl_name): ?array { if (!isset($citationItems[0]->type)) { $citationItems[0]->type = $blockCSLType; } + + // If no data for URL field, pass node url. + if (empty($citationItems[0]->URL)) { + $node_url = $this->pathAliasManager->getAliasByPath('/node/' . $entity->id()); + $citationItems[0]->URL = Url::fromUserInput($node_url)->setAbsolute()->toString();; + } + $style = $this->citationHelper->loadStyle($csl_name); return $this->citationHelper->renderWithCiteproc($citationItems, $style); } From 541845d269f6aa6256de86bd39934d90e2736827 Mon Sep 17 00:00:00 2001 From: Prashant Kanse Date: Mon, 18 Dec 2023 15:11:34 +0530 Subject: [PATCH 2/2] DGIR-124 : Add default URL to citation block --- src/Form/SelectCslForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Form/SelectCslForm.php b/src/Form/SelectCslForm.php index d3d23cb..6a2b2cc 100644 --- a/src/Form/SelectCslForm.php +++ b/src/Form/SelectCslForm.php @@ -208,7 +208,7 @@ private function renderCitation($csl_name): ?array { // If no data for URL field, pass node url. if (empty($citationItems[0]->URL)) { $node_url = $this->pathAliasManager->getAliasByPath('/node/' . $entity->id()); - $citationItems[0]->URL = Url::fromUserInput($node_url)->setAbsolute()->toString();; + $citationItems[0]->URL = Url::fromUserInput($node_url)->setAbsolute()->toString(); } $style = $this->citationHelper->loadStyle($csl_name);