From d6059eca652fa118858774f8a2794c73df8fdf93 Mon Sep 17 00:00:00 2001 From: Gilmar Lima Date: Wed, 10 Nov 2021 12:22:25 +0000 Subject: [PATCH 01/14] OEL-476: Create the User Profile submodule. --- modules/oe_whitelabel_user_profile/README.md | 3 +++ .../oe_whitelabel_user_profile.info.yml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 modules/oe_whitelabel_user_profile/README.md create mode 100644 modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml diff --git a/modules/oe_whitelabel_user_profile/README.md b/modules/oe_whitelabel_user_profile/README.md new file mode 100644 index 000000000..c01c78a98 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/README.md @@ -0,0 +1,3 @@ +# OpenEuropa Whitelabel User Profile + +The scope of this module is to provide templates for theming the User Profile. diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml new file mode 100644 index 000000000..8a9bbfb42 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml @@ -0,0 +1,5 @@ +name: OpenEuropa Whitelabel User Profile +type: module +description: OpenEuropa Whitelabel Theme User Profile. +package: OpenEuropa Whitelabel Theme +core_version_requirement: ^8.9 || ^9.1 From e2eeb7b5f41aea9e06e17ca515c115039eb4104c Mon Sep 17 00:00:00 2001 From: drishu Date: Thu, 18 Nov 2021 13:31:02 +0200 Subject: [PATCH 02/14] OEL-476: Improve texts, add to runner. --- modules/oe_whitelabel_user_profile/README.md | 2 +- .../oe_whitelabel_user_profile.info.yml | 2 +- runner.yml.dist | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/oe_whitelabel_user_profile/README.md b/modules/oe_whitelabel_user_profile/README.md index c01c78a98..8c4b79504 100644 --- a/modules/oe_whitelabel_user_profile/README.md +++ b/modules/oe_whitelabel_user_profile/README.md @@ -1,3 +1,3 @@ # OpenEuropa Whitelabel User Profile -The scope of this module is to provide templates for theming the User Profile. +The scope of this module is to provide alterations and additional functionality for the theming of the OpenEuropa Library User Profile feature. diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml index 8a9bbfb42..1ac38d3a3 100644 --- a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml @@ -1,5 +1,5 @@ name: OpenEuropa Whitelabel User Profile type: module -description: OpenEuropa Whitelabel Theme User Profile. +description: Adds additional functionality to the User Profile feature. package: OpenEuropa Whitelabel Theme core_version_requirement: ^8.9 || ^9.1 diff --git a/runner.yml.dist b/runner.yml.dist index deb56344f..dd392a693 100644 --- a/runner.yml.dist +++ b/runner.yml.dist @@ -22,6 +22,7 @@ drupal: - "./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 en oe_whitelabel_user_profile -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" From 1553fb7c42ab0534e997e42503b036392ab20cd5 Mon Sep 17 00:00:00 2001 From: drishu Date: Wed, 12 Jan 2022 09:15:02 +0200 Subject: [PATCH 03/14] OEL-484: Add language concept subset. --- .../src/Plugin/ConceptSubset/LanguagesWeb.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php diff --git a/modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php b/modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php new file mode 100644 index 000000000..daba08aed --- /dev/null +++ b/modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php @@ -0,0 +1,75 @@ + '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'); + } + +} From 95f096b6ddbe66bc5f583237bafc37a5642c9085 Mon Sep 17 00:00:00 2001 From: drishu Date: Tue, 25 Jan 2022 09:42:05 +0200 Subject: [PATCH 04/14] OEL-484: Add ecas field mapping. --- .../oe_whitelabel_user_profile.info.yml | 2 + .../oe_whitelabel_user_profile.services.yml | 5 ++ ...uLoginAttributesToUserFieldsSubscriber.php | 82 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml create mode 100644 modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml index 1ac38d3a3..f7dc68a08 100644 --- a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml @@ -3,3 +3,5 @@ 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 diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml new file mode 100644 index 000000000..e76fbb582 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml @@ -0,0 +1,5 @@ +services: + oe_whitelabel_user_profile.event_subscriber: + class: Drupal\oe_whitelabel_user_profile\EventSubscriber\EuLoginAttributesToUserFieldsSubscriber + tags: + - { name: event_subscriber } diff --git a/modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php b/modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php new file mode 100644 index 000000000..caad07b59 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php @@ -0,0 +1,82 @@ + '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; + } + +} From 21d0af1ab7ed33a9bc18502f9297098bd5a8c45c Mon Sep 17 00:00:00 2001 From: Gilmar Lima Date: Wed, 10 Nov 2021 12:22:25 +0000 Subject: [PATCH 05/14] OEL-476: Create the User Profile submodule. --- modules/oe_whitelabel_user_profile/README.md | 3 +++ .../oe_whitelabel_user_profile.info.yml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 modules/oe_whitelabel_user_profile/README.md create mode 100644 modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml diff --git a/modules/oe_whitelabel_user_profile/README.md b/modules/oe_whitelabel_user_profile/README.md new file mode 100644 index 000000000..c01c78a98 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/README.md @@ -0,0 +1,3 @@ +# OpenEuropa Whitelabel User Profile + +The scope of this module is to provide templates for theming the User Profile. diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml new file mode 100644 index 000000000..8a9bbfb42 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml @@ -0,0 +1,5 @@ +name: OpenEuropa Whitelabel User Profile +type: module +description: OpenEuropa Whitelabel Theme User Profile. +package: OpenEuropa Whitelabel Theme +core_version_requirement: ^8.9 || ^9.1 From 7f15acd0d63f99198eea339c2755ecfef54853db Mon Sep 17 00:00:00 2001 From: drishu Date: Thu, 18 Nov 2021 13:31:02 +0200 Subject: [PATCH 06/14] OEL-476: Improve texts, add to runner. --- modules/oe_whitelabel_user_profile/README.md | 2 +- .../oe_whitelabel_user_profile.info.yml | 2 +- runner.yml.dist | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/oe_whitelabel_user_profile/README.md b/modules/oe_whitelabel_user_profile/README.md index c01c78a98..8c4b79504 100644 --- a/modules/oe_whitelabel_user_profile/README.md +++ b/modules/oe_whitelabel_user_profile/README.md @@ -1,3 +1,3 @@ # OpenEuropa Whitelabel User Profile -The scope of this module is to provide templates for theming the User Profile. +The scope of this module is to provide alterations and additional functionality for the theming of the OpenEuropa Library User Profile feature. diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml index 8a9bbfb42..1ac38d3a3 100644 --- a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml @@ -1,5 +1,5 @@ name: OpenEuropa Whitelabel User Profile type: module -description: OpenEuropa Whitelabel Theme User Profile. +description: Adds additional functionality to the User Profile feature. package: OpenEuropa Whitelabel Theme core_version_requirement: ^8.9 || ^9.1 diff --git a/runner.yml.dist b/runner.yml.dist index 407e5c739..628b9cfaf 100644 --- a/runner.yml.dist +++ b/runner.yml.dist @@ -17,6 +17,7 @@ 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" From e6898028c403830874e7346590016fb8e019b395 Mon Sep 17 00:00:00 2001 From: drishu Date: Wed, 12 Jan 2022 09:15:02 +0200 Subject: [PATCH 07/14] OEL-484: Add language concept subset. --- .../src/Plugin/ConceptSubset/LanguagesWeb.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php diff --git a/modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php b/modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php new file mode 100644 index 000000000..daba08aed --- /dev/null +++ b/modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php @@ -0,0 +1,75 @@ + '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'); + } + +} From 936a69c66fee4cc04c28667b64d6afc4d343c5e7 Mon Sep 17 00:00:00 2001 From: drishu Date: Tue, 25 Jan 2022 09:42:05 +0200 Subject: [PATCH 08/14] OEL-484: Add ecas field mapping. --- .../oe_whitelabel_user_profile.info.yml | 2 + .../oe_whitelabel_user_profile.services.yml | 5 ++ ...uLoginAttributesToUserFieldsSubscriber.php | 82 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml create mode 100644 modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml index 1ac38d3a3..f7dc68a08 100644 --- a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml @@ -3,3 +3,5 @@ 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 diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml new file mode 100644 index 000000000..e76fbb582 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml @@ -0,0 +1,5 @@ +services: + oe_whitelabel_user_profile.event_subscriber: + class: Drupal\oe_whitelabel_user_profile\EventSubscriber\EuLoginAttributesToUserFieldsSubscriber + tags: + - { name: event_subscriber } diff --git a/modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php b/modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php new file mode 100644 index 000000000..caad07b59 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php @@ -0,0 +1,82 @@ + '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; + } + +} From f72421c6105b9e6872ffe1cddf20fdabef9f6abf Mon Sep 17 00:00:00 2001 From: Gilmar Lima Date: Wed, 10 Nov 2021 12:22:25 +0000 Subject: [PATCH 09/14] OEL-476: Create the User Profile submodule. --- modules/oe_whitelabel_user_profile/README.md | 3 +++ .../oe_whitelabel_user_profile.info.yml | 5 +++++ 2 files changed, 8 insertions(+) create mode 100644 modules/oe_whitelabel_user_profile/README.md create mode 100644 modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml diff --git a/modules/oe_whitelabel_user_profile/README.md b/modules/oe_whitelabel_user_profile/README.md new file mode 100644 index 000000000..c01c78a98 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/README.md @@ -0,0 +1,3 @@ +# OpenEuropa Whitelabel User Profile + +The scope of this module is to provide templates for theming the User Profile. diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml new file mode 100644 index 000000000..8a9bbfb42 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml @@ -0,0 +1,5 @@ +name: OpenEuropa Whitelabel User Profile +type: module +description: OpenEuropa Whitelabel Theme User Profile. +package: OpenEuropa Whitelabel Theme +core_version_requirement: ^8.9 || ^9.1 From 74cb27f90b2ff675712c181a51f90020e4f18462 Mon Sep 17 00:00:00 2001 From: drishu Date: Thu, 18 Nov 2021 13:31:02 +0200 Subject: [PATCH 10/14] OEL-476: Improve texts, add to runner. --- modules/oe_whitelabel_user_profile/README.md | 2 +- .../oe_whitelabel_user_profile.info.yml | 2 +- runner.yml.dist | 1 + 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/oe_whitelabel_user_profile/README.md b/modules/oe_whitelabel_user_profile/README.md index c01c78a98..8c4b79504 100644 --- a/modules/oe_whitelabel_user_profile/README.md +++ b/modules/oe_whitelabel_user_profile/README.md @@ -1,3 +1,3 @@ # OpenEuropa Whitelabel User Profile -The scope of this module is to provide templates for theming the User Profile. +The scope of this module is to provide alterations and additional functionality for the theming of the OpenEuropa Library User Profile feature. diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml index 8a9bbfb42..1ac38d3a3 100644 --- a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml @@ -1,5 +1,5 @@ name: OpenEuropa Whitelabel User Profile type: module -description: OpenEuropa Whitelabel Theme User Profile. +description: Adds additional functionality to the User Profile feature. package: OpenEuropa Whitelabel Theme core_version_requirement: ^8.9 || ^9.1 diff --git a/runner.yml.dist b/runner.yml.dist index 407e5c739..628b9cfaf 100644 --- a/runner.yml.dist +++ b/runner.yml.dist @@ -17,6 +17,7 @@ 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" From b04f44e81cfadfc8ba95959ad2b22d8efe2ab4ed Mon Sep 17 00:00:00 2001 From: drishu Date: Wed, 12 Jan 2022 09:15:02 +0200 Subject: [PATCH 11/14] OEL-484: Add language concept subset. --- .../src/Plugin/ConceptSubset/LanguagesWeb.php | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php diff --git a/modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php b/modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php new file mode 100644 index 000000000..daba08aed --- /dev/null +++ b/modules/oe_whitelabel_user_profile/src/Plugin/ConceptSubset/LanguagesWeb.php @@ -0,0 +1,75 @@ + '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'); + } + +} From 2797db0ead7a7d71718b694992a53bee1b55036c Mon Sep 17 00:00:00 2001 From: drishu Date: Tue, 25 Jan 2022 09:42:05 +0200 Subject: [PATCH 12/14] OEL-484: Add ecas field mapping. --- .../oe_whitelabel_user_profile.info.yml | 2 + .../oe_whitelabel_user_profile.services.yml | 5 ++ ...uLoginAttributesToUserFieldsSubscriber.php | 82 +++++++++++++++++++ 3 files changed, 89 insertions(+) create mode 100644 modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml create mode 100644 modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml index 1ac38d3a3..f7dc68a08 100644 --- a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.info.yml @@ -3,3 +3,5 @@ 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 diff --git a/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml new file mode 100644 index 000000000..e76fbb582 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/oe_whitelabel_user_profile.services.yml @@ -0,0 +1,5 @@ +services: + oe_whitelabel_user_profile.event_subscriber: + class: Drupal\oe_whitelabel_user_profile\EventSubscriber\EuLoginAttributesToUserFieldsSubscriber + tags: + - { name: event_subscriber } diff --git a/modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php b/modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php new file mode 100644 index 000000000..caad07b59 --- /dev/null +++ b/modules/oe_whitelabel_user_profile/src/EventSubscriber/EuLoginAttributesToUserFieldsSubscriber.php @@ -0,0 +1,82 @@ + '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; + } + +} From 307052e3b79af9ce22cc86a3ee21e879da68f545 Mon Sep 17 00:00:00 2001 From: Gilmar Lima Date: Wed, 10 Nov 2021 12:22:25 +0000 Subject: [PATCH 13/14] OEL-476: Create the User Profile submodule. --- modules/oe_whitelabel_user_profile/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/oe_whitelabel_user_profile/README.md b/modules/oe_whitelabel_user_profile/README.md index 8c4b79504..c01c78a98 100644 --- a/modules/oe_whitelabel_user_profile/README.md +++ b/modules/oe_whitelabel_user_profile/README.md @@ -1,3 +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. +The scope of this module is to provide templates for theming the User Profile. From 37dc87d499ff9978fb6ec36a7e77024e9c5c8b18 Mon Sep 17 00:00:00 2001 From: drishu Date: Thu, 18 Nov 2021 13:31:02 +0200 Subject: [PATCH 14/14] OEL-476: Improve texts, add to runner. --- modules/oe_whitelabel_user_profile/README.md | 2 +- runner.yml.dist | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/modules/oe_whitelabel_user_profile/README.md b/modules/oe_whitelabel_user_profile/README.md index c01c78a98..8c4b79504 100644 --- a/modules/oe_whitelabel_user_profile/README.md +++ b/modules/oe_whitelabel_user_profile/README.md @@ -1,3 +1,3 @@ # OpenEuropa Whitelabel User Profile -The scope of this module is to provide templates for theming the User Profile. +The scope of this module is to provide alterations and additional functionality for the theming of the OpenEuropa Library User Profile feature. diff --git a/runner.yml.dist b/runner.yml.dist index 628b9cfaf..b782da46b 100644 --- a/runner.yml.dist +++ b/runner.yml.dist @@ -21,6 +21,9 @@ drupal: - "./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"