-
Notifications
You must be signed in to change notification settings - Fork 3
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
SHS-5904: Add new "log out" block to existing sites #1696
Changes from 4 commits
e824148
afbdf9a
5ae139b
7167595
3347d63
0c6f20c
a9dfee8
6765439
fb00382
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: { } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: { } |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -5,10 +5,12 @@ | |||||||
* su_humsci_profile.install | ||||||||
*/ | ||||||||
|
||||||||
use Drupal\Core\Config\FileStorage; | ||||||||
use Drupal\Core\DrupalKernel; | ||||||||
use Drupal\Core\Entity\Entity\EntityFormDisplay; | ||||||||
use Drupal\Core\Entity\Entity\EntityViewDisplay; | ||||||||
use Drupal\Core\Menu\MenuTreeParameters; | ||||||||
use Drupal\Core\Site\Settings; | ||||||||
use Drupal\field\Entity\FieldConfig; | ||||||||
use Drupal\field\Entity\FieldStorageConfig; | ||||||||
use Drupal\hs_entities\Entity\HsEntityType; | ||||||||
|
@@ -1096,3 +1098,55 @@ function su_humsci_profile_update_9718() { | |||||||
// Uninstalls modules after removing configs to prevent updb errors. | ||||||||
\Drupal::service('module_installer')->uninstall(['hs_webform', 'webform_ui', 'webform']); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
* Add new logout block to existing sites. | ||||||||
*/ | ||||||||
function su_humsci_profile_update_9719() { | ||||||||
$config_storage = new FileStorage(Settings::get('config_sync_directory')); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please use
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For this one, I did try that initially, but it fails:
My theory is that this is dealing with theme config? But not sure if that is correct. If we're set on using the service, I'll have to poke at that again next week. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's weird. We have both versions in the site, but in the past we've had kickbacks because SWS prefers to use the service. Let's keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
$entity_type_manager = \Drupal::service('entity_type.manager'); | ||||||||
|
||||||||
$config_names = [ | ||||||||
'block.block.humsci_colorful_samlsunetidlogoutblock', | ||||||||
'block.block.humsci_traditional_samlsunetidlogoutblock', | ||||||||
]; | ||||||||
|
||||||||
foreach ($config_names as $config_name) { | ||||||||
|
||||||||
// Load the configuration data from the sync directory. | ||||||||
$config_data = $config_storage->read($config_name); | ||||||||
|
||||||||
if (!$config_data) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use |
||||||||
throw new \Exception(t('The configuration %config_name was not found in the sync directory.', ['%config_name' => $config_name])); | ||||||||
} | ||||||||
|
||||||||
// Get the block storage and possible existing config. | ||||||||
$block_storage = $entity_type_manager->getStorage('block'); | ||||||||
$existing_config = $block_storage->load($config_data['id']); | ||||||||
|
||||||||
if (!$existing_config) { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. isn't it guaranteed there will not be existing config? These are new configs and blocks are prefixed if they are custom on sites. |
||||||||
// Change the logout link text to match what the existing login text is. | ||||||||
$login_blocks = $entity_type_manager->getStorage('block')->loadByProperties([ | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is looping through blocks multiple times and doing the same thing to produce a "log out" text. Why not do that prior to creating the config because we don't need to do it multiple times. Just once for one block. |
||||||||
'plugin' => 'stanford_samlauth_login_block', | ||||||||
]); | ||||||||
|
||||||||
if ($login_blocks) { | ||||||||
foreach ($login_blocks as $login_block) { | ||||||||
/** @var Drupal\block\Entity\BlockDrupal\block\Entity\Block $login_block */ | ||||||||
$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); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
$config_data['settings']['link_text'] = $log_out; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||||||||
$block_storage->create($config_data)->save(); | ||||||||
|
||||||||
\Drupal::logger('su_humsci_profile')->info('Block configuration %config_name has been imported.', ['%config_name' => $config_name]); | ||||||||
} | ||||||||
} | ||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about this a bit more, this update hook is not needed. We force import configs prefixed with
block.block.humsci_colorful_
andblock.block.humsci_traditional_
. So any changes to those configs would be reverted during config import anyways.ref: https://github.com/SU-HSDO/suhumsci/blob/develop/config/default/config_ignore.settings.yml#L10