Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DGIR-124 : Add default URL to citation block #61

Merged
merged 3 commits into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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