diff --git a/src/Form/SelectCslForm.php b/src/Form/SelectCslForm.php index ed2ca9d..6552aeb 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 Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; @@ -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. * @@ -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; } @@ -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') ); } @@ -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); }