Browse Source

allowed for nids

main
ajstanley 2 years ago
parent
commit
367701c75c
  1. 4
      src/Plugin/Block/CoinUrlBlock.php
  2. 8
      src/Service/RoblibCoinsService.php

4
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' => "<span class = 'coin-url'>$markup</span>",

8
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);
}
}

Loading…
Cancel
Save