Skip to content

Commit

Permalink
Merge pull request #61 from Prashant-bd/dgir-124
Browse files Browse the repository at this point in the history
DGIR-124 : Add default URL to citation block
  • Loading branch information
chrismacdonaldw authored Dec 18, 2023
2 parents b2914c7 + ad1db8a commit 93ce388
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Form/SelectCslForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 Psr\Log\LoggerInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand Down Expand Up @@ -43,6 +45,13 @@ class SelectCslForm extends FormBase {
*/
protected $entityTypeManager;

/**
* Definition of path alias manager.
*
* @var \Drupal\path_alias\AliasManager
*/
protected $pathAliasManager;

/**
* The logger service.
*
Expand All @@ -56,10 +65,12 @@ class SelectCslForm extends FormBase {
public function __construct(IslandoraCitationsHelper $citationHelper,
RouteMatchInterface $route_match,
EntityTypeManagerInterface $entity_type_manager,
AliasManagerInterface $pathAliasManager,
LoggerInterface $logger) {
$this->citationHelper = $citationHelper;
$this->routeMatch = $route_match;
$this->entityTypeManager = $entity_type_manager;
$this->pathAliasManager = $pathAliasManager;
$this->logger = $logger;
}

Expand All @@ -71,6 +82,7 @@ public static function create(ContainerInterface $container) {
$container->get('islandora_citations.helper'),
$container->get('current_route_match'),
$container->get('entity_type.manager'),
$container->get('path_alias.manager'),
$container->get('logger.factory')->get('islandora_citations')
);
}
Expand Down Expand Up @@ -234,6 +246,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);
}
Expand Down

0 comments on commit 93ce388

Please sign in to comment.