Skip to content

Commit

Permalink
Merge pull request #681 from City-of-Helsinki/UHF-9551-telia-ace-fixes
Browse files Browse the repository at this point in the history
UHF-9551: Telia ACE fixes.
  • Loading branch information
juho-lehmonen authored Apr 25, 2024
2 parents 18406aa + 6c1311c commit 9522e90
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
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

0 comments on commit 9522e90

Please sign in to comment.