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

UHF-9551: Telia ACE fixes. #681

Merged
merged 4 commits into from
Apr 25, 2024
Merged
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
13 changes: 10 additions & 3 deletions helfi_platform_config.libraries.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,18 @@ user_consent_functions:
dependencies:
- core/drupal

telia_ace_widget:
version: 1.0.x
header: true
telia_ace_widget_loadjs:
version: 1.0.1
css:
theme:
assets/css/telia_ace.css: {}
js:
'https://wds.ace.teliacompany.com/wds/instances/J5XKjqJt/load_ace.js': {
type: external,
minified: false,
attributes: {
defer: true
}
}
dependencies:
- helfi_platform_config/user_consent_functions
38 changes: 8 additions & 30 deletions src/Plugin/Block/TeliaAceWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,11 @@ public function blockForm($form, FormStateInterface $form_state) {
$form = parent::blockForm($form, $form_state);
$config = $this->getConfiguration();

$form['script_url'] = [
'#type' => 'textfield',
'#required' => TRUE,
'#title' => $this->t('Script URL'),
'#description' => $this->t('URL to the chat JS library without the domain, for example: /wds/instances/J5XKjqJt/ACEWebSDK.min.js'),
'#default_value' => $config['script_url'] ?? '/wds/instances/J5XKjqJt/ACEWebSDK.min.js',
];

$form['chat_id'] = [
'#type' => 'textfield',
'#required' => TRUE,
'#title' => $this->t('Chat Widget ID'),
'#description' => $this->t('ID for the chat instance. Example format: example-chat-fin'),
'#description' => $this->t('ID for the chat instance, without the humany_ prefix. This value can be translated. Example format: example-chat-fin'),
'#default_value' => $config['chat_id'] ?? '',
];

Expand All @@ -45,7 +37,6 @@ public function blockForm($form, FormStateInterface $form_state) {
* {@inheritdoc}
*/
public function blockSubmit($form, FormStateInterface $formState) {
$this->configuration['script_url'] = $formState->getValue('script_url');
$this->configuration['chat_id'] = $formState->getValue('chat_id');
}

Expand All @@ -54,41 +45,28 @@ public function blockSubmit($form, FormStateInterface $formState) {
*/
public function build() {

$library = ['helfi_platform_config/telia_ace_widget'];

$build = [];

$config = $this->getConfiguration();
$base_url = 'https://wds.ace.teliacompany.com';
$script_url = $base_url . $config['script_url'];
$chat_id = 'humany_' . $config['chat_id'];
$attached = [
'library' => ['helfi_platform_config/telia_ace_widget_loadjs'],
];

$build['ibm_chat_app'] = [
$build['telia_chat_widget'] = [
'button' => [
'#type' => 'html_tag',
'#tag' => 'div',
'#attributes' => [
'role' => 'region',
'aria-label' => 'chat',
'id' => $chat_id,
'class' => [
'hidden',
],
],
],
'#attached' => [
'library' => $library,
'html_head' => [
[
[
'#tag' => 'script',
'#attributes' => [
'async' => TRUE,
'type' => 'text/javascript',
'src' => $script_url,
],
], 'telia_ace_script',
],
],
],
'#attached' => $attached,
];

return $build;
Expand Down