diff --git a/helfi_platform_config.libraries.yml b/helfi_platform_config.libraries.yml index 9f7ff4420..99333fd05 100644 --- a/helfi_platform_config.libraries.yml +++ b/helfi_platform_config.libraries.yml @@ -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 diff --git a/src/Plugin/Block/TeliaAceWidget.php b/src/Plugin/Block/TeliaAceWidget.php index fe3567ca1..2b018d606 100644 --- a/src/Plugin/Block/TeliaAceWidget.php +++ b/src/Plugin/Block/TeliaAceWidget.php @@ -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'] ?? '', ]; @@ -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'); } @@ -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;