3 changed files with 8 additions and 122 deletions
@ -1,6 +1,6 @@ |
|||||||
islandora_altmetric.altimetric_settings: |
islandora_altmetric.altmetric_settings: |
||||||
title: Altimetric settings |
title: altmetric settings |
||||||
description: Setting for Altimetric Badge |
description: Setting for altmetric Badge |
||||||
parent: entity.islandora_citations.config_overview |
parent: entity.islandora_citations.config_overview |
||||||
route_name: islandora_altmetric.altimetric_settings |
route_name: islandora_altmetric.altmetric_settings |
||||||
weight: 10 |
weight: 10 |
||||||
|
|||||||
@ -1,7 +1,7 @@ |
|||||||
islandora_altmetric.altimetric_settings: |
islandora_altmetric.altmetric_settings: |
||||||
path: '/admin/config/system/altimetric-settings' |
path: '/admin/config/system/altmetric-settings' |
||||||
defaults: |
defaults: |
||||||
_title: 'Altimetric settings' |
_title: 'altmetric settings' |
||||||
_form: 'Drupal\islandora_altmetric\Form\AltimetricSettingsForm' |
_form: 'Drupal\islandora_altmetric\Form\altmetricSettingsForm' |
||||||
requirements: |
requirements: |
||||||
_permission: 'administer site configuration' |
_permission: 'administer site configuration' |
||||||
|
|||||||
@ -1,114 +0,0 @@ |
|||||||
<?php |
|
||||||
|
|
||||||
declare(strict_types=1); |
|
||||||
|
|
||||||
namespace Drupal\islandora_altmetric\Plugin\Block; |
|
||||||
|
|
||||||
use Drupal\Core\Block\BlockBase; |
|
||||||
use Drupal\Core\Entity\EntityTypeManagerInterface; |
|
||||||
use Drupal\Core\Config\ConfigFactoryInterface; |
|
||||||
use Drupal\Core\Routing\RouteMatchInterface; |
|
||||||
use Drupal\Core\Plugin\ContainerFactoryPluginInterface; |
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface; |
|
||||||
|
|
||||||
/** |
|
||||||
* Provides an islandora altimetric block. |
|
||||||
* |
|
||||||
* @Block( |
|
||||||
* id = "islandora_altmetric_islandora_altimetric", |
|
||||||
* admin_label = @Translation("Islandora Altimetric"), |
|
||||||
* category = @Translation("Custom"), |
|
||||||
* ) |
|
||||||
*/ |
|
||||||
final class IslandoraAltimetricBlock extends BlockBase implements ContainerFactoryPluginInterface { |
|
||||||
|
|
||||||
/** |
|
||||||
* The entity type manager service. |
|
||||||
* |
|
||||||
* @var \Drupal\Core\Entity\EntityTypeManagerInterface |
|
||||||
*/ |
|
||||||
protected $entityTypeManager; |
|
||||||
/** |
|
||||||
* The route match service. |
|
||||||
* |
|
||||||
* @var \Drupal\Core\Routing\RouteMatchInterface |
|
||||||
*/ |
|
||||||
protected $routeMatch; |
|
||||||
|
|
||||||
/** |
|
||||||
* The configuration factory. |
|
||||||
* |
|
||||||
* @var \Drupal\Core\Config\ConfigFactoryInterface |
|
||||||
*/ |
|
||||||
protected $configFactory; |
|
||||||
|
|
||||||
/** |
|
||||||
* Constructs the plugin instance. |
|
||||||
*/ |
|
||||||
public function __construct( |
|
||||||
array $configuration, |
|
||||||
$plugin_id, |
|
||||||
$plugin_definition, |
|
||||||
EntityTypeManagerInterface $entity_typemanager, |
|
||||||
RouteMatchInterface $route_match, |
|
||||||
ConfigFactoryInterface $configFactory |
|
||||||
) { |
|
||||||
$this->routeMatch = $route_match; |
|
||||||
$this->entityTypeManager = $entity_typemanager; |
|
||||||
$this->configFactory = $configFactory; |
|
||||||
parent::__construct($configuration, $plugin_id, $plugin_definition); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* {@inheritdoc} |
|
||||||
*/ |
|
||||||
public static function create(ContainerInterface $container, array $configuration, $plugin_id, $plugin_definition): self { |
|
||||||
return new self( |
|
||||||
$configuration, |
|
||||||
$plugin_id, |
|
||||||
$plugin_definition, |
|
||||||
$container->get('entity_type.manager'), |
|
||||||
$container->get('current_route_match'), |
|
||||||
$container->get('config.factory'), |
|
||||||
); |
|
||||||
} |
|
||||||
|
|
||||||
/** |
|
||||||
* {@inheritdoc} |
|
||||||
*/ |
|
||||||
public function build(): array { |
|
||||||
$config = $this->configFactory->get('islandora_altmetric.settings'); |
|
||||||
$node = $this->routeMatch->getParameter('node'); |
|
||||||
if (!$node) { |
|
||||||
return []; |
|
||||||
} |
|
||||||
$doi_field = $config->get('doi_field') ?? 'field_doi'; |
|
||||||
$doi = $node->$doi_field->value; |
|
||||||
if (!$doi) { |
|
||||||
return []; |
|
||||||
} |
|
||||||
$style = $config->get('style'); |
|
||||||
$markup = <<<EOD |
|
||||||
<div class="altmetric-embed" data-badge-type='$style' data-badge-popover="right" data-doi="$doi"></div> |
|
||||||
<script async src="//badge.altmetric.com/embeds.js"></script> |
|
||||||
EOD; |
|
||||||
|
|
||||||
$build['content'] = [ |
|
||||||
'#markup' => $markup, |
|
||||||
]; |
|
||||||
|
|
||||||
$build['content'] = [ |
|
||||||
'#markup' => $markup, |
|
||||||
'#attached' => [ |
|
||||||
'library' => [ |
|
||||||
'islandora_altmetric/islandora_altmetric', |
|
||||||
], |
|
||||||
], |
|
||||||
]; |
|
||||||
$build['#cache'] = [ |
|
||||||
'max-age' => 0, |
|
||||||
]; |
|
||||||
return $build; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
Loading…
Reference in new issue