Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EPIC User Profile #47

Open
wants to merge 18 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions modules/oe_whitelabel_user_profile/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# OpenEuropa Whitelabel User Profile

The scope of this module is to provide alterations and additional functionality for the theming of the OpenEuropa Library User Profile feature.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
name: OpenEuropa Whitelabel User Profile
type: module
description: Adds additional functionality to the User Profile feature.
package: OpenEuropa Whitelabel Theme
core_version_requirement: ^8.9 || ^9.1
dependencies:
- cas:cas
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
services:
oe_whitelabel_user_profile.event_subscriber:
class: Drupal\oe_whitelabel_user_profile\EventSubscriber\EuLoginAttributesToUserFieldsSubscriber
tags:
- { name: event_subscriber }
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_whitelabel_user_profile\EventSubscriber;

use Drupal\cas\Event\CasPostLoginEvent;
use Drupal\cas\Event\CasPreRegisterEvent;
use Drupal\cas\Service\CasHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Copies the EU Login attributes to user fields.
*/
class EuLoginAttributesToUserFieldsSubscriber implements EventSubscriberInterface {

/**
* Array mapping of EU Login attributes with user account fields.
*/
const USER_EU_LOGIN_ATTRIBUTE_MAPPING = [
'mail' => 'email',
'field_first_name' => 'firstName',
'field_last_name' => 'lastName',
'field_organization' => 'domain',
];

/**
* {@inheritdoc}
*/
public static function getSubscribedEvents() {
return [
CasHelper::EVENT_POST_LOGIN => 'updateUserData',
CasHelper::EVENT_PRE_REGISTER => 'processUserProperties',
];
}

/**
* Updates the user data based on the information taken from EU Login.
*
* @param \Drupal\cas\Event\CasPostLoginEvent $event
* The triggered event.
*/
public function updateUserData(CasPostLoginEvent $event): void {
$properties = self::convertEuLoginAttributesToFieldValues($event->getCasPropertyBag()->getAttributes());
$account = $event->getAccount();
foreach ($properties as $name => $value) {
$account->set($name, $value);
}
$account->save();
}

/**
* Adds user properties based on the information taken from EU Login.
*
* @param \Drupal\cas\Event\CasPreRegisterEvent $event
* The triggered event.
*/
public function processUserProperties(CasPreRegisterEvent $event): void {
$attributes = $event->getCasPropertyBag()->getAttributes();
$event->setPropertyValues(self::convertEuLoginAttributesToFieldValues($attributes));
}

/**
* Converts the EU Login attributes into a Drupal field/values array.
*
* @param array $attributes
* An array containing a series of EU Login attributes.
*
* @return array
* An associative array of field values indexed by the field name.
*/
protected static function convertEuLoginAttributesToFieldValues(array $attributes): array {
$values = [];
foreach (static::USER_EU_LOGIN_ATTRIBUTE_MAPPING as $field_name => $property_name) {
if (!empty($attributes[$property_name])) {
$values[$field_name] = $attributes[$property_name];
}
}
return $values;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

declare(strict_types = 1);

namespace Drupal\oe_whitelabel_user_profile\Plugin\ConceptSubset;

use Drupal\Core\Entity\Query\QueryInterface;
use Drupal\rdf_skos\ConceptSubsetPluginBase;

/**
* Creates a subset of the languages vocabulary.
*
* @see https://github.com/ec-europa/ewcms/blob/develop/modules/ewcms_vocabularies/src/Plugin/ConceptSubset/LanguagesWeb.php
*
* @ConceptSubset(
* id = "languages_web",
* label = @Translation("WEB Languages"),
* description = @Translation("Languages to be used for the WEB presence."),
* concept_schemes = {
* "http://publications.europa.eu/resource/authority/language"
* }
* )
*/
class LanguagesWeb extends ConceptSubsetPluginBase {

/**
* {@inheritdoc}
*/
public function alterQuery(QueryInterface $query, $match_operator, array $concept_schemes = [], string $match = NULL): void {
$languages = [
'Bulgarian' => 'http://publications.europa.eu/resource/authority/language/BUL',
'Spanish' => 'http://publications.europa.eu/resource/authority/language/SPA',
'Czech' => 'http://publications.europa.eu/resource/authority/language/CES',
'Danish' => 'http://publications.europa.eu/resource/authority/language/DAN',
'German' => 'http://publications.europa.eu/resource/authority/language/DEU',
'Estonian' => 'http://publications.europa.eu/resource/authority/language/EST',
'Greek' => 'http://publications.europa.eu/resource/authority/language/ELL',
'English' => 'http://publications.europa.eu/resource/authority/language/ENG',
'French' => 'http://publications.europa.eu/resource/authority/language/FRA',
'Irish' => 'http://publications.europa.eu/resource/authority/language/GLE',
'Croatian' => 'http://publications.europa.eu/resource/authority/language/HRV',
'Italian' => 'http://publications.europa.eu/resource/authority/language/ITA',
'Latvian' => 'http://publications.europa.eu/resource/authority/language/LAV',
'Lithuanian' => 'http://publications.europa.eu/resource/authority/language/LIT',
'Hungarian' => 'http://publications.europa.eu/resource/authority/language/HUN',
'Maltese' => 'http://publications.europa.eu/resource/authority/language/MLT',
'Dutch' => 'http://publications.europa.eu/resource/authority/language/NLD',
'Polish' => 'http://publications.europa.eu/resource/authority/language/POL',
'Portuguese' => 'http://publications.europa.eu/resource/authority/language/POR',
'Romanian' => 'http://publications.europa.eu/resource/authority/language/RON',
'Slovak' => 'http://publications.europa.eu/resource/authority/language/SLK',
'Slovenian' => 'http://publications.europa.eu/resource/authority/language/SLV',
'Finnish' => 'http://publications.europa.eu/resource/authority/language/FIN',
'Swedish' => 'http://publications.europa.eu/resource/authority/language/SWE',
'Arabic' => 'http://publications.europa.eu/resource/authority/language/ARA',
'Belorussian' => 'http://publications.europa.eu/resource/authority/language/BEL',
'Hebrew' => 'http://publications.europa.eu/resource/authority/language/HEB',
'Hindi' => 'http://publications.europa.eu/resource/authority/language/HIN',
'Armenian' => 'http://publications.europa.eu/resource/authority/language/HYE',
'Icelandic' => 'http://publications.europa.eu/resource/authority/language/ISL',
'Japanese' => 'http://publications.europa.eu/resource/authority/language/JPN',
'Macedonian' => 'http://publications.europa.eu/resource/authority/language/MKD',
'Norwegian' => 'http://publications.europa.eu/resource/authority/language/NOR',
'Russian' => 'http://publications.europa.eu/resource/authority/language/RUS',
'Albanian' => 'http://publications.europa.eu/resource/authority/language/SQI',
'Turkish' => 'http://publications.europa.eu/resource/authority/language/TUR',
'Urdu' => 'http://publications.europa.eu/resource/authority/language/URD',
'Vietnamese' => 'http://publications.europa.eu/resource/authority/language/VIE',
'Chinese' => 'http://publications.europa.eu/resource/authority/language/ZHO',
];

$query->condition('id', array_values($languages), 'IN');
}

}
4 changes: 4 additions & 0 deletions runner.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@ drupal:
# Prepare the instance.
- "./vendor/bin/drush en oe_whitelabel_helper -y"
- "./vendor/bin/drush en oe_whitelabel_search -y"
- "./vendor/bin/drush en oe_whitelabel_user_profile -y"
- "./vendor/bin/drush en field_ui -y"
- "./vendor/bin/drush en toolbar -y"
- "./vendor/bin/drush theme:enable oe_whitelabel -y"
- "./vendor/bin/drush en oe_bootstrap_theme_helper -y"
- "./vendor/bin/drush en oe_whitelabel_helper -y"
- "./vendor/bin/drush en oe_whitelabel_search -y"
- "./vendor/bin/drush theme:enable seven -y"
- "./vendor/bin/drush config-set system.theme default oe_whitelabel -y"
- "./vendor/bin/drush config-set system.theme admin seven -y"
Expand Down