diff --git a/assets/css/telia_ace.css b/assets/css/telia_ace.css new file mode 100644 index 000000000..a76aec348 --- /dev/null +++ b/assets/css/telia_ace.css @@ -0,0 +1,3 @@ +.region--attachments .humany-rendered { + visibility: visible; +} diff --git a/config/schema/helfi_platform_config.schema.yml b/config/schema/helfi_platform_config.schema.yml index 5f5d3ffd9..2f1753bdf 100644 --- a/config/schema/helfi_platform_config.schema.yml +++ b/config/schema/helfi_platform_config.schema.yml @@ -5,3 +5,11 @@ block.settings.chat_leijuke: chat_title: type: text label: 'Chat title' + +block.settings.telia_ace_widget: + type: block_settings + label: 'Block config translation for Telia ACE widget' + mapping: + chat_id: + type: text + label: 'Chat widget ID' diff --git a/helfi_platform_config.libraries.yml b/helfi_platform_config.libraries.yml index 604f59537..b3b692435 100644 --- a/helfi_platform_config.libraries.yml +++ b/helfi_platform_config.libraries.yml @@ -107,3 +107,12 @@ user_consent_functions: assets/js/user_consent_functions.js: {} dependencies: - core/drupal + +telia_ace_widget: + version: 1.0.x + header: true + css: + theme: + assets/css/telia_ace.css: {} + dependencies: + - helfi_platform_config/user_consent_functions diff --git a/helfi_platform_config.module b/helfi_platform_config.module index 829047edb..11131fe63 100644 --- a/helfi_platform_config.module +++ b/helfi_platform_config.module @@ -485,6 +485,8 @@ function helfi_platform_config_config_ignore_settings_alter(array &$settings) { 'block.block.genesyschat', 'block.block.genesyschat_*', 'block.block.smarttichatbot', + 'block.block.teliaacewidget*', + 'block.block.hdbt_subtheme_teliaacewidget*', ]; foreach ($add_ignore as $config) { diff --git a/src/Plugin/Block/TeliaAceWidget.php b/src/Plugin/Block/TeliaAceWidget.php new file mode 100644 index 000000000..ad7cff819 --- /dev/null +++ b/src/Plugin/Block/TeliaAceWidget.php @@ -0,0 +1,89 @@ +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: //acewebsdk/example-chat-fin'), + '#default_value' => $config['chat_id'] ?? '//acewebsdk/', + ]; + + return $form; + } + + /** + * {@inheritdoc} + */ + public function blockSubmit($form, FormStateInterface $formState) { + $this->configuration['script_url'] = $formState->getValue('script_url'); + $this->configuration['chat_id'] = $formState->getValue('chat_id'); + } + + /** + * {@inheritdoc} + */ + 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 = $config['chat_id']; + + $build['ibm_chat_app'] = [ + '#title' => $this->t('Telia ACE Widget'), + '#markup' => '', + '#attached' => [ + 'library' => $library, + 'html_head' => [ + [ + [ + '#tag' => 'script', + '#attributes' => [ + 'async' => TRUE, + 'type' => 'text/javascript', + 'src' => $script_url, + ], + ], 'telia_ace_script', + ], + ], + ], + ]; + + return $build; + } + +}