Skip to content

Commit

Permalink
Display 'import to my site' button on BNF server. DDFHER-181
Browse files Browse the repository at this point in the history
If the editor has been redirected to the server from the BNF login, the
context from the site they come from, has been saved to a cookie.
If that is the case, we show a floating (fixed) button on nodes, that
links back to the original site, along with the UUID.
If the article has already been imported, the original site will display
a warning.
  • Loading branch information
rasben committed Jan 2, 2025
1 parent 8d2c556 commit 8d27ffe
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
44 changes: 44 additions & 0 deletions web/modules/custom/bnf/bnf_server/bnf_server.module
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

use Drupal\bnf_server\Controller\LoginController;
use Drupal\node\Entity\Node;

/**
* Implements hook_preprocess_HOOK().
*
* Displaying the "import content to my site" button on nodes, if the user
* has logged in and has the callback cookie context.
*/
function bnf_server_preprocess_page(array &$variables): void {
$node = $variables['node'] ?? NULL;
$cookies = \Drupal::request()->cookies;
$url = $cookies->get(LoginController::COOKIE_CALLBACK_URL);
$name = $cookies->get(LoginController::COOKIE_SITE_NAME);

if (!$url || !($node instanceof Node)) {
return;
}

$variables['page']['content']['import_link'] = [
'#theme' => 'bnf_server_import_link',
'#label' => $node->label(),
'#name' => $name ?? t('my site', [], ['context' => 'BNF']),
'#url' => "$url/admin/bnf/import/{$node->uuid()}",
'#cache' => ['max-age' => 0],
];
}

/**
* Implements hook_theme().
*/
function bnf_server_theme(): array {
return [
'bnf_server_import_link' => [
'variables' => [
'url' => NULL,
'name' => NULL,
'label' => NULL,
],
],
];
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{# Super simple styling, placing the button fixed on the screen. #}
<style>
.bnf-import-link {
position: fixed;
right: 1em;
bottom: 1em;
z-index: 999;
}
</style>

<div class="bnf-import-link">
<a class="btn-primary btn-filled btn-large" href="{{ url }}">
{{ 'Import "@label" to @name'|trans({'@label': label, '@name': name}, {"context": "BNF"}) }}
</a>
</div>

0 comments on commit 8d27ffe

Please sign in to comment.