From 367701c75caa06b423e706cb6f99c3b175c7caa2 Mon Sep 17 00:00:00 2001 From: ajstanley Date: Thu, 19 Dec 2024 19:06:25 +0000 Subject: [PATCH] allowed for nids --- src/Plugin/Block/CoinUrlBlock.php | 4 ++++ src/Service/RoblibCoinsService.php | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Plugin/Block/CoinUrlBlock.php b/src/Plugin/Block/CoinUrlBlock.php index b3fd1fd..9416e95 100644 --- a/src/Plugin/Block/CoinUrlBlock.php +++ b/src/Plugin/Block/CoinUrlBlock.php @@ -9,6 +9,7 @@ use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\Core\Routing\RouteMatchInterface; use Drupal\roblib_coins\Service\RoblibCoinsService; use Symfony\Component\DependencyInjection\ContainerInterface; +use Drupal\node\NodeInterface; /** * Provides a coin url block. @@ -52,6 +53,9 @@ final class CoinUrlBlock extends BlockBase implements ContainerFactoryPluginInte */ public function build(): array { $node = $this->routeMatch->getParameter('node'); + if (is_string($node)) { + $node = $this->roblibCoinsMintCoinService->nodeFromNid($node); + } $markup = $this->roblibCoinsMintCoinService->mintCoin($node); $build['content'] = [ '#markup' => "$markup", diff --git a/src/Service/RoblibCoinsService.php b/src/Service/RoblibCoinsService.php index cc4c9a0..f0d25f8 100644 --- a/src/Service/RoblibCoinsService.php +++ b/src/Service/RoblibCoinsService.php @@ -5,7 +5,6 @@ namespace Drupal\roblib_coins\Service; use Drupal\node\NodeInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Url; -use Drupal\Core\Link; use Drupal\Core\Config\ConfigFactoryInterface; /** @@ -119,4 +118,11 @@ class RoblibCoinsService { } + /** + * Loads and returns node from supplied nid. + */ + public function nodeFromNid($nid) { + return $this->entityTypeManager->getStorage('node')->load($nid); + } + }