-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display 'import to my site' button on BNF server. DDFHER-181
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
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
], | ||
], | ||
]; | ||
} |
15 changes: 15 additions & 0 deletions
15
web/modules/custom/bnf/bnf_server/templates/bnf-server-import-link.html.twig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |