From d087ab89cc6ceb2d656b91a1faccf82e81080f8b Mon Sep 17 00:00:00 2001 From: Marc Berger <107938318+codechefmarc@users.noreply.github.com> Date: Thu, 19 Dec 2024 07:58:05 -0800 Subject: [PATCH] SHS-5904: Add new "log out" block to existing sites (#1696) --- ...humsci_colorful_samlsunetidlogoutblock.yml | 21 ++++++ ...sci_traditional_samlsunetidlogoutblock.yml | 21 ++++++ .../su_humsci_profile.install | 75 +++++++++++++++++-- .../su_humsci_profile.profile | 15 +++- 4 files changed, 122 insertions(+), 10 deletions(-) create mode 100644 config/default/block.block.humsci_colorful_samlsunetidlogoutblock.yml create mode 100644 config/default/block.block.humsci_traditional_samlsunetidlogoutblock.yml diff --git a/config/default/block.block.humsci_colorful_samlsunetidlogoutblock.yml b/config/default/block.block.humsci_colorful_samlsunetidlogoutblock.yml new file mode 100644 index 000000000..efe814bfe --- /dev/null +++ b/config/default/block.block.humsci_colorful_samlsunetidlogoutblock.yml @@ -0,0 +1,21 @@ +uuid: 7e424b1f-3692-41a3-a48a-dd1a450e0203 +langcode: en +status: true +dependencies: + module: + - stanford_samlauth + theme: + - humsci_colorful +id: humsci_colorful_samlsunetidlogoutblock +theme: humsci_colorful +region: footer +weight: 0 +provider: null +plugin: stanford_samlauth_logout_block +settings: + id: stanford_samlauth_logout_block + label: 'SAML SUNetID Logout Block' + label_display: '0' + provider: stanford_samlauth + link_text: 'SUNetID Logout' +visibility: { } diff --git a/config/default/block.block.humsci_traditional_samlsunetidlogoutblock.yml b/config/default/block.block.humsci_traditional_samlsunetidlogoutblock.yml new file mode 100644 index 000000000..fdd685e5f --- /dev/null +++ b/config/default/block.block.humsci_traditional_samlsunetidlogoutblock.yml @@ -0,0 +1,21 @@ +uuid: 2f7f0d52-c463-411d-a2e2-656d185acd4d +langcode: en +status: true +dependencies: + module: + - stanford_samlauth + theme: + - humsci_traditional +id: humsci_traditional_samlsunetidlogoutblock +theme: humsci_traditional +region: footer +weight: 0 +provider: null +plugin: stanford_samlauth_logout_block +settings: + id: stanford_samlauth_logout_block + label: 'SAML SUNetID Logout Block' + label_display: '0' + provider: stanford_samlauth + link_text: 'SUNetID Logout' +visibility: { } diff --git a/docroot/profiles/humsci/su_humsci_profile/su_humsci_profile.install b/docroot/profiles/humsci/su_humsci_profile/su_humsci_profile.install index 2706d929b..68d7cc67b 100644 --- a/docroot/profiles/humsci/su_humsci_profile/su_humsci_profile.install +++ b/docroot/profiles/humsci/su_humsci_profile/su_humsci_profile.install @@ -15,7 +15,6 @@ use Drupal\hs_entities\Entity\HsEntityType; use Drupal\node\NodeInterface; use Drupal\paragraphs\Entity\ParagraphsType; use Drupal\user\RoleInterface; -use Drush\Drush; /** * Implements hook_requirements(). @@ -23,7 +22,6 @@ use Drush\Drush; function su_humsci_profile_requirements($phase) { $requirements = []; if ($phase == 'runtime') { - $site_path = DrupalKernel::findSitePath(\Drupal::request()); $site_path = explode('/', $site_path); $site_name = $site_path[1]; @@ -75,7 +73,11 @@ function su_humsci_profile_update_9606() { $entity_type_manager = \Drupal::entityTypeManager(); $config_factory = \Drupal::configFactory(); - \Drupal::service('module_installer')->install(['menu_link', 'cshs', 'token_or']); + \Drupal::service('module_installer')->install([ + 'menu_link', + 'cshs', + 'token_or', + ]); $config_factory->getEditable('menu_link_weight.settings') ->set('menu_parent_form_selector', 'cshs') ->save(); @@ -110,7 +112,8 @@ function su_humsci_profile_update_9607() { $field_config_storage = $entity_type_manager->getStorage('field_config'); $bundles = []; /** @var \Drupal\node\Entity\NodeType $node_type */ - foreach ($entity_type_manager->getStorage('node_type')->loadMultiple() as $node_type) { + foreach ($entity_type_manager->getStorage('node_type') + ->loadMultiple() as $node_type) { if ($node_type->getThirdPartySetting('menu_ui', 'available_menus')) { $bundles[] = $node_type->id(); $node_type->setThirdPartySetting('menu_ui', 'available_menus', []); @@ -479,7 +482,8 @@ function su_humsci_profile_update_9701(&$sandbox) { // Clear entity caches. $entity_type_manager->getStorage($eck_type)->resetCache([$id]); - $entity_type_manager->getStorage('hs_entity')->resetCache([$new_entity->id()]); + $entity_type_manager->getStorage('hs_entity') + ->resetCache([$new_entity->id()]); } $sandbox['#finished'] = empty($sandbox['items']) ? 1 : ($sandbox['count'] - count($sandbox['items'])) / $sandbox['count']; @@ -852,7 +856,8 @@ function _su_humsci_profile_get_uuid(string $config_name): string|null { * Uninstall legacy themes. */ function su_humsci_profile_update_9705() { - $installed_themes = \Drupal::service('extension.list.theme')->getAllInstalledInfo(); + $installed_themes = \Drupal::service('extension.list.theme') + ->getAllInstalledInfo(); $legacy_themes = [ 'archaeology', 'francestanford', @@ -1096,7 +1101,7 @@ function su_humsci_profile_update_9718() { // Remove webform existing config - needs to be done before uninstall. $config_factory = \Drupal::configFactory(); - $config_names = array_filter($config_factory->listAll(), function ($item) { + $config_names = array_filter($config_factory->listAll(), function($item) { return str_contains($item, 'webform'); }); @@ -1114,5 +1119,59 @@ function su_humsci_profile_update_9718() { */ function su_humsci_profile_update_9719() { // Uninstalls modules after removing configs to prevent updb errors. - \Drupal::service('module_installer')->uninstall(['hs_webform', 'webform_ui', 'webform']); + \Drupal::service('module_installer')->uninstall([ + 'hs_webform', + 'webform_ui', + 'webform', + ]); +} + +/** + * Add new logout block to existing sites. + */ +function su_humsci_profile_update_9720() { + $block_storage = \Drupal::entityTypeManager()->getStorage('block'); + /** @var Drupal\block\Entity\Block[] $login_blocks */ + $login_blocks = $block_storage->loadByProperties([ + 'plugin' => 'stanford_samlauth_login_block', + ]); + $log_out = 'SUNetID Logout'; + + if ($login_blocks) { + $login_block = reset($login_blocks); + $settings = $login_block->get('settings'); + + $log_in = $settings['link_text']; + $log_out = preg_replace('/in\b/', 'out', $log_in); + $log_out = preg_replace('/In\b/', 'Out', $log_out); + $log_out = str_replace(' to ', ' from ', $log_out); + $log_out = str_replace(' To ', ' From ', $log_out); + } + + $block_info = [ + 'status' => TRUE, + 'region' => 'footer', + 'plugin' => 'stanford_samlauth_logout_block', + 'weight' => 0, + 'settings' => [ + 'id' => 'stanford_samlauth_logout_block', + 'label' => 'SAML SUNetID Logout Block', + 'label_display' => 0, + 'provider' => 'stanford_samlauth', + 'link_text' => $log_out, + ], + 'visibility' => [], + ]; + $block_storage->create([ + 'uuid' => '7e424b1f-3692-41a3-a48a-dd1a450e0203', + 'id' => 'humsci_colorful_samlsunetidlogoutblock', + 'theme' => 'humsci_colorful', + ...$block_info, + ])->save(); + $block_storage->create([ + 'uuid' => '2f7f0d52-c463-411d-a2e2-656d185acd4d', + 'id' => 'humsci_traditional_samlsunetidlogoutblock', + 'theme' => 'humsci_traditional', + ...$block_info, + ])->save(); } diff --git a/docroot/profiles/humsci/su_humsci_profile/su_humsci_profile.profile b/docroot/profiles/humsci/su_humsci_profile/su_humsci_profile.profile index 6b3154205..1df4df9c3 100644 --- a/docroot/profiles/humsci/su_humsci_profile/su_humsci_profile.profile +++ b/docroot/profiles/humsci/su_humsci_profile/su_humsci_profile.profile @@ -875,11 +875,22 @@ function su_humsci_profile_form_user_register_form_alter(&$form, FormStateInterf /** * Implements hook_preprocess_HOOK(). */ -function su_humsci_profile_preprocess_block__stanford_samlauth(&$variables) { - $variables['content']['login']['#attributes']['class'] = [ +function su_humsci_profile_preprocess_block(&$variables) { + $classes = [ 'text-align-right', 'hs-secondary-button', ]; + + $base_plugin_id = $variables['base_plugin_id']; + + switch ($base_plugin_id) { + case 'stanford_samlauth_login_block': + $variables['content']['login']['#attributes']['class'] = $classes; + break; + + case 'stanford_samlauth_logout_block': + $variables['content']['logout']['#attributes']['class'] = $classes; + } } /**