Skip to content
Snippets Groups Projects
Commit 33136bd7 authored by Artem Antonov's avatar Artem Antonov
Browse files

CERN Toolbar

parents
No related branches found
No related tags found
No related merge requests found
Showing
with 701 additions and 0 deletions
#cern-toolbar a {
display: inline;
vertical-align: middle;
}
\ No newline at end of file
/*
Remove icons from "External links" module
*/
#cern-toolbar span.ext {
display: none;
}
/* CERN Toolbar CSS - 17/01/13 */
#cern-toolbar {
background-color: #222;
background-color: rgba(30, 30, 30, 0.95);
font-family: 'PT Sans', 'Trebuchet MS', Tahoma, sans-serif;
color: #999;
font-size: 14px;
line-height: 1;
padding: 0 5%;
overflow: hidden;
-moz-box-shadow: inset 0 -1px 0 rgba(100, 100, 100, 0.2);
-webkit-box-shadow: inset 0 -1px 0 rgba(100, 100, 100, 0.2);
box-shadow: inset 0 -1px 0 rgba(100, 100, 100, 0.2);
height: 40px;
}
#cern-toolbar a {
color: #ccc;
text-decoration: none;
padding: 6px 8px;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 5px;
display: inline-block;
}
#cern-toolbar a:hover {
background-color: #000;
color: #fff;
}
#cern-toolbar .active a {
background-color: #f6f6f6;
color: #000;
padding-bottom: 20px;
}
#cern-toolbar .active .cern-account {
background-color: #fff;
}
#cern-toolbar h1 {
float: left;
font-size: 14px;
font-weight: 400;
line-height: 1;
position: relative;
left: -8px;
padding: 6px 0;
letter-spacing: 0.08em;
margin: 0;
}
#cern-toolbar h1 a {
color: #fff;
}
#cern-toolbar h1 span {
color: #999;
letter-spacing: normal;
padding: 0;
}
#cern-toolbar h1 a:hover span {
color: #fff;
}
#cern-toolbar ul {
float: right;
list-style: none;
position: relative;
right: -8px;
margin: 0;
}
#cern-toolbar li {
float: left;
display: block;
margin-left: 1em;
padding: 6px 0;
}
#cern-toolbar .cern-multifactor {
padding-left: 32px;
background-image: url("../img/toolbarsprite.png");
background-repeat: no-repeat;
background-position: 0 -120px;
}
#cern-toolbar .cern-signout {
margin-left: 1em;
}
/* Animations */
#cern-toolbar a, #cern-toolbar a span {
-moz-transition: background-color 0.1s ease-out;
-webkit-transition: background-color 0.1s ease-out;
-ms-transition: background-color 0.1s ease-out;
-o-transition: background-color 0.1s ease-out;
transition: background-color 0.1s ease-out;
}
@media only screen and (max-width:750px) {
#cern-toolbar h1 span {
display: none;
}
#cern-toolbar ul {
border-right: 1px solid #000;
-moz-box-shadow: 1px 0 0 #444;
-webkit-box-shadow: 1px 0 0 #444;
box-shadow: 1px 0 0 #444;
}
#cern-toolbar li {
padding: 0;
margin: 0;
border-left: 1px solid #000;
}
#cern-toolbar li a {
background-image: url("../img/toolbarsprite.png");
background-repeat: no-repeat;
height: 40px;
width: 40px;
-moz-border-radius: 0;
-webkit-border-radius: 0;
border-radius: 0;
text-indent: -5000px;
overflow: hidden;
border-left: 1px solid #444;
}
#cern-toolbar .cern-account {
background-position: 9px 0;
}
#cern-toolbar .cern-directory {
background-position: 9px -40px;
}
#cern-toolbar .cern-signout {
background-position: 9px -80px;
margin-left: 0;
}
#cern-toolbar .active .cern-account {
background-position: -31px 0;
}
#cern-toolbar .active .cern-directory {
background-position: -31px -40px;
}
#cern-toolbar .cern-accountlinks span {
display: none;
}
#cern-toolbar .cern-multifactor {
background-image: none;
padding: 0;
}
}
\ No newline at end of file
assets/img/toolbarsprite.png

3.3 KiB

bundle: CERN
name: CERN Toolbar
type: module
description: CERN Toolbar
core: 8.x
package: CERN
dependencies:
- cookieconsent
cern_toolbar:
version: 1.x
css:
component:
assets/css/screen.css: {}
\ No newline at end of file
cern_toolbar.settings:
title: CERN Toolbar
parent: system.admin_config_ui
description: 'Configurations of the CERN Toolbar'
route_name: cern_toolbar.cern_toolbar_settings_form
<?php
/**
* @file
* Contains cern_toolbar.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function cern_toolbar_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
// Main module help for the cern_toolbar module.
case 'help.page.cern_toolbar':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('This module enables the CERN toolbar on the top of the site.') . '</p>';
$output .= '<p>' . t('This module is not configurable: find more information about the CERN Toolbar at') . ' ' . l('http://ux.web.cern.ch/assets/cern-toolbar', 'http://ux.web.cern.ch/assets/cern-toolbar') . '</p>';
return $output;
default:
}
}
/**
* Implements hook_theme().
*/
function cern_toolbar_theme() {
return [
'cern_toolbar' => [
'render element' => 'element',
'variables' => ['toolbar_links' => NULL, 'attributes' => []],
],
];
}
/**
* Implements hook_theme_registry_alter().
*/
function cern_toolbar_theme_registry_alter(&$theme_registry) {
$theme_registry['cookieconsent']['path'] = drupal_get_path('module', 'cern_toolbar').'/templates/';
}
/**
* Implements hook_page_top().
*/
function cern_toolbar_page_top(array &$page_top) {
$page_top['cern_toolbar'] = [
'#type' => 'cern_toolbar',
];
}
administer cern toolbar:
title: 'Administer CERN Toolbar'
description: 'Allow to change CERN Toolbar settings'
cern_toolbar.cern_toolbar_settings_form:
path: '/admin/config/user-interface/cern-toolbar'
defaults:
_form: '\Drupal\cern_toolbar\Form\CernToolbarSettingsForm'
_title: 'CERN Toolbar Settings'
requirements:
_permission: 'administer cern toolbar'
{
"name": "drupal/cern_toolbar",
"type": "drupal-module",
"description": "CERN Toolbar",
"keywords": ["Drupal"],
"license": "GPL-2.0+",
"homepage": "https://www.drupal.org/project/cern_toolbar",
"minimum-stability": "dev",
"support": {
"issues": "https://www.drupal.org/project/issues/cern_toolbar",
"source": "http://cgit.drupalcode.org/cern_toolbar"
},
"require": { }
}
cern_toolbar:
<?php
namespace Drupal\cern_toolbar\Element;
use Drupal\Component\Utility\Html;
use Drupal\Core\Link;
use Drupal\Core\Url;
use Drupal\Core\Render\Element\RenderElement;
use Drupal\Core\Render\Element;
use Drupal\simplesamlphp_auth\Service\SimplesamlphpAuthManager;
use function Sodium\add;
/**
* Provides a render element for the default Drupal toolbar.
*
* @RenderElement("cern_toolbar")
*/
class CernToolbar extends RenderElement {
/**
* {@inheritdoc}
*/
public function getInfo() {
$class = get_class($this);
return [
'#pre_render' => [
[$class, 'preRenderToolbar'],
],
'#theme' => 'cern_toolbar',
'#attached' => [
'library' => [
'cern_toolbar/cern_toolbar',
],
],
// Metadata for the toolbar wrapping element.
'#attributes' => [
// The id cannot be simply "toolbar" or it will clash with the
// simpletest tests listing which produces a checkbox with attribute
// id="toolbar".
'id' => 'cern-toolbar',
'role' => 'group',
'aria-label' => $this->t('CERN Toolbar'),
],
// Metadata for the administration bar.
'#bar' => [
'#heading' => $this->t('Toolbar items'),
'#attributes' => [
'id' => 'toolbar-bar',
'role' => 'navigation',
'aria-label' => $this->t('Toolbar items'),
],
],
];
}
/**
* Builds the Toolbar as a structured array ready for drupal_render().
*
* Since building the toolbar takes some time, it is done just prior to
* rendering to ensure that it is built only if it will be displayed.
*
* @param array $element
* A renderable array.
*
* @return array
* A renderable array.
*
* @see toolbar_page_top()
*/
public static function preRenderToolbar($element) {
$items_toolbar_links = [];
if(\Drupal::currentUser()->isAnonymous()) {
$element['#attributes']['class'] = 'user-not-authenticated';
$items_toolbar_links[] = [
'#markup' => '<span class="cern-signin">'.t('Sign in').'</span>',
'#wrapper_attributes' => [
'class' => [
'sign-in-button',
],
]
];
$items_toolbar_links[] = [
'#type' => 'link',
'#title'=> t('As CERN account'),
'#url'=> Url::fromRoute('user.login'),
'#wrapper_attributes' => [
'class' => [
'cern-account-links',
],
],
'#attributes' => ['class' => 'cern-account'],
];
$config = \Drupal::config('cern_toolbar.settings');
$additional_links_count = count($config->getRawData());
if($additional_links_count > 0) {
for ($i = 0; $i < $additional_links_count / 2; $i++) {
$items_toolbar_links[] = [
'#type' => 'link',
'#title' => $config->get('additional_link_title_'.$i),
'#url' => \Drupal\Core\Url::fromUri($config->get('additional_link_'.$i)),
'#wrapper_attributes' => [
'class' => [
'cern-account-links',
],
],
];
}
}
} else {
$element['#attributes']['class'] = 'user-authenticated';
if (\Drupal::moduleHandler()->moduleExists('simplesamlphp_auth')) {
$simpleSamlPHPAuthManager = self::getSimpleSamlPHPAuthManager();
$simplesaml_attributes = $simpleSamlPHPAuthManager->getAttributes();
$username = $simplesaml_attributes['login'][0];
$federation = $simplesaml_attributes['http://schemas.xmlsoap.org/claims/Federation'][0];
$email_address = $simplesaml_attributes['http://schemas.xmlsoap.org/claims/UPN'][0];
$authlevel = $simplesaml_attributes['http://schemas.xmlsoap.org/claims/AuthLevel'][0];
$fullname = $simplesaml_attributes['fullname'][0];
$identity_class = $simplesaml_attributes['identityclass'][0];
} else {
$fullname = \Drupal::currentUser()->getDisplayName();
$username = \Drupal::currentUser()->getAccountName();
$federation = 'Drupal';
$authlevel = 'Core';
$identity_class = NULL;
}
$account_info = [
'#type' => 'link',
'#title'=> t('%username %federation', [
'%username' => $username,
'%federation' => $federation,
]),
'#url'=> URL::fromUri('http://cern.ch/account'),
'#attributes' => [
'class' => 'account',
'title' => t('Signed in as: %fullname (%username) using %auth_level authentication',
[
'%fullname' => $fullname,
'%username' => $username,
'%auth_level' => $authlevel,
]
)
],
'#prefix' => '<span>'.t('Signed in as:'),
'#suffix' => '</span>'
];
switch ($identity_class) {
case 'CERN Registered':
//<a href="http://cern.ch/account" title="Signed in as Joe Bloggs (jbloggs)">Signed in as: jbloggs (CERN)</a>
// this is the default string
break;
case 'CERN Shared':
//<a href="http://cern.ch/account" title="Signed in as Joe Bloggs (libframe)">Signed in as: libframe (CERN)</a>
// this is the default string
break;
case 'HEP Trusted':
//Signed in as: username (Institute name)</li>
$account_info = [
'#markup'=> t('Signed in as: %username %federation',
['%username' => $username, '%federation' => $federation]),
];
break;
case 'Verified External':
$account_info = [
'#type' => 'link',
'#title'=> $email_address,
'#url'=> '//cern.ch/account',
'#attributes' => [
'class' => 'account',
'title' => t('Signed in with a verified external account')
],
'#prefix' => '<span>'.t('Signed in as:'),
'#suffix' => '</span>'
];
break;
case 'Unverified External':
//Signed in as: johnnylongname@yahoo.fr (Facebook)
$account_info = [
'#markup'=> t('Signed in as: %email_address %federation',
['%email_address' => $email_address, '%federation' => $federation]),
];
break;
default:
// this is the default string
break;
}
$items_toolbar_links[] = $account_info;
$items_toolbar_links[] = [
'#type' => 'link',
'#title'=> t('Sign out'),
'#url'=> Url::fromRoute('user.logout'),
'#attributes' => [
'class' => 'cern-signout',
'title' => t('Sign out of your account'),
],
];
}
$items_toolbar_links[] = [
'#type' => 'link',
'#title'=> t('Directory'),
'#url'=> URL::fromUri('//cern.ch/directory'),
'#attributes' => [
'class' => 'cern-directory',
'title' => t('Search CERN resources and browse the directory'),
],
'#wrapper_attributes' => [
'class' => [
'cern-directory-link',
],
],
];
$element['#toolbar_links'] = [
'#theme' => 'item_list',
'#list_type' => 'ul',
'#title' => '',
'#items' => $items_toolbar_links,
'#attributes' => ['class' => 'cern-signedin'],
];
return $element;
}
/**
* @return SimplesamlphpAuthManager
*/
public static function getSimpleSamlPHPAuthManager() {
return \Drupal::service('simplesamlphp_auth.manager');
}
}
<?php
namespace Drupal\cern_toolbar\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Link;
/**
* Class CernToolbarSettingsForm.
*/
class CernToolbarSettingsForm extends FormBase {
/**
* {@inheritdoc}
*/
public function getFormId() {
return 'cern_toolbar_settings_form';
}
/**
* {@inheritdoc}
*/
public function buildForm(array $form, FormStateInterface $form_state) {
$form['description'] = [
'#type' => 'item',
'#markup' => $this->t('This form contains the configuration of the top CERN Toolbar.'),
];
$config = \Drupal::config('cern_toolbar.settings');
// Gather the number of additional links in the form already.
$num_additional_links = $form_state->get('num_additional_links');
// We have to ensure that there is at least one name field.
if ($num_additional_links === NULL) {
$num_additional_links = count($config->getRawData());
$num_additional_links = $num_additional_links > 0 ? $num_additional_links / 2 : 1;
$additional_link_field = $form_state->set('num_additional_links', $num_additional_links);
}
$form['#tree'] = TRUE;
$form['additional_links_fieldset'] = [
'#type' => 'fieldset',
'#title' => $this->t('Additional Links'),
'#prefix' => '<div id="additional-links-fieldset-wrapper">',
'#suffix' => '</div>',
];
for ($i = 0; $i < $num_additional_links; $i++) {
$form['additional_links_fieldset']['additional_link_'.$i] = [
'#type' => 'url',
'#required' => TRUE,
'#title' => '#'. ($i+1) .' '.$this->t('Additional link url'),
'#description' => $this->t('Enter additional sign in link URL'),
'#default_value' => $config->get('additional_link_'.$i),
];
$form['additional_links_fieldset']['additional_link_title_'.$i] = [
'#type' => 'textfield',
'#required' => TRUE,
'#title' => '#'. ($i+1) .' '.$this->t('Additional link title'),
'#description' => $this->t('Enter additional sign in link title'),
'#default_value' => $config->get('additional_link_title_'.$i),
];
}
$form['additional_links_fieldset']['actions'] = [
'#type' => 'actions',
];
$form['additional_links_fieldset']['actions']['add_additional_link'] = [
'#type' => 'submit',
'#value' => t('Add one more'),
'#submit' => ['::addOne'],
'#ajax' => [
'callback' => '::addmoreCallback',
'wrapper' => 'additional-links-fieldset-wrapper',
],
];
// If there is more than one name, add the remove button.
if ($num_additional_links > 1) {
$form['additional_links_fieldset']['actions']['remove_name'] = [
'#type' => 'submit',
'#value' => t('Remove one'),
'#submit' => ['::removeCallback'],
'#ajax' => [
'callback' => '::addmoreCallback',
'wrapper' => 'additional-links-fieldset-wrapper',
],
];
}
$form['cookies_fieldset'] = [
'#type' => 'fieldset',
'#title' => $this->t('Cookies settings'),
];
$form['cookies_fieldset']['cookieconsent'] = [
'#markup' => $this->t('To configure the cookies banner please enter the configuration of the module '. Link::createFromRoute('Cookie Consent', 'cookieconsent.cookieconsent_admin_form')->toString())
];
$form_state->setCached(FALSE);
$form['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Submit'),
];
return $form;
}
/**
* {@inheritdoc}
*/
public function validateForm(array &$form, FormStateInterface $form_state) {
parent::validateForm($form, $form_state);
}
/**
* {@inheritdoc}
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$config = \Drupal::service('config.factory')->getEditable('cern_toolbar.settings');
$config->delete();
foreach($form_state->getValue('additional_links_fieldset') as $key => $value){
if (strpos($key, 'additional_link') !== FALSE) {
$config->set($key, $value);
}
}
$config->save();
}
/**
* Callback for both ajax-enabled buttons.
*
* Selects and returns the fieldset with the additional links in it.
*/
public function addmoreCallback(array &$form, FormStateInterface $form_state) {
return $form['additional_links_fieldset'];
}
/**
* Submit handler for the "add-one-more" button.
*
* Increments the max counter and causes a rebuild.
*/
public function addOne(array &$form, FormStateInterface $form_state) {
$additional_link_field = $form_state->get('num_additional_links');
$add_button = $additional_link_field + 1;
$form_state->set('num_additional_links', $add_button);
$form_state->setRebuild();
}
/**
* Submit handler for the "remove one" button.
*
* Decrements the max counter and causes a form rebuild.
*/
public function removeCallback(array &$form, FormStateInterface $form_state) {
$additional_link_field = $form_state->get('num_additional_links');
if ($additional_link_field > 1) {
$remove_button = $additional_link_field - 1;
$form_state->set('num_additional_links', $remove_button);
}
$form_state->setRebuild();
}
}
<div {{ attributes }}>
<h1>
<a href="//home.cern" title="{{ 'CERN' | t }}">
{{ 'CERN' | t }}
<span>{{ 'Accelerating science' | t }}</span>
</a>
</h1>
{{ toolbar_links }}
</div>
\ No newline at end of file
{#
/**
* @file
* Default template for cookieconsent.
*
* Available variables:
* - dismiss : The text used on the dismiss button.
* - message : The message shown by the plugin.
* - target : The target of the link to your cookie policy. Use to open a link in a new window, or specific frame,
if you wish.
* - link : The url of your cookie policy. If it’s set to null, the link is hidden.
* - learn_more : The text shown on the link to the cookie policy (requires the link option to also be set)
*
* @ingroup themeable
*/
#}
<div class="cc_banner cc_container cc_container--open">
<a href="#null" data-cc-event="click:dismiss" target="_blank" class="cc_btn cc_btn_accept_all">{{ dismiss }}</a>
<p class="cc_message">{{message}} <a data-cc-if="options.link" target="{{ target }}" class="cc_more_info" href="{{ link }}">{{ learn_more }}</a></p>
</div>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment