-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #652 from City-of-Helsinki/UHF-9274-telia-ace
UHF-9274: Basic implementation of Telia ACE widget.
- Loading branch information
Showing
5 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.region--attachments .humany-rendered { | ||
visibility: visible; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
<?php | ||
|
||
namespace Drupal\helfi_platform_config\Plugin\Block; | ||
|
||
use Drupal\Core\Block\BlockBase; | ||
use Drupal\Core\Form\FormStateInterface; | ||
|
||
/** | ||
* Provides a Telia ACE chat widget block. | ||
* | ||
* @Block( | ||
* id = "telia_ace_widget", | ||
* admin_label = @Translation("Telia ACE Widget"), | ||
* ) | ||
*/ | ||
class TeliaAceWidget extends BlockBase { | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
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: //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' => '<a class="hidden" href="' . $chat_id . '"></a>', | ||
'#attached' => [ | ||
'library' => $library, | ||
'html_head' => [ | ||
[ | ||
[ | ||
'#tag' => 'script', | ||
'#attributes' => [ | ||
'async' => TRUE, | ||
'type' => 'text/javascript', | ||
'src' => $script_url, | ||
], | ||
], 'telia_ace_script', | ||
], | ||
], | ||
], | ||
]; | ||
|
||
return $build; | ||
} | ||
|
||
} |