Last active
July 13, 2021 15:36
-
-
Save imcbride/7c8503c38293b1cf764ee0fb98bc80ce to your computer and use it in GitHub Desktop.
This file contains hidden or 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
diff --git a/olark.module b/olark.module | |
index d56db12..290e848 100644 | |
--- a/olark.module | |
+++ b/olark.module | |
@@ -25,6 +25,22 @@ function olark_page_bottom(array &$page_bottom) { | |
return; | |
} | |
+ $page_bottom['olark'] = olark_render_array(); | |
+ | |
+ // Add cachability metadata. | |
+ /** @var Drupal\Core\Render\Renderer $renderer */ | |
+ $renderer = \Drupal::service('renderer'); | |
+ $renderer->addCacheableDependency($page_bottom['olark'], $settings); | |
+} | |
+ | |
+/** | |
+ * Create the render array for the chat widget. | |
+ * | |
+ * @return array | |
+ * A render array for the chat widget. | |
+ */ | |
+function olark_render_array() { | |
+ $settings = \Drupal::config('olark.settings'); | |
$user = \Drupal::currentUser(); | |
$js_settings = [ | |
'olark' => [ | |
@@ -47,7 +63,7 @@ function olark_page_bottom(array &$page_bottom) { | |
':url' => $user_page_url, | |
]); | |
} | |
- $page_bottom['olark'] = [ | |
+ $render = [ | |
'#markup' => Markup::create($settings->get('olark_code')), | |
'#attached' => [ | |
'library' => ['olark/integration'], | |
@@ -58,8 +74,6 @@ function olark_page_bottom(array &$page_bottom) { | |
'tags' => ['user:' . $user->id()], | |
], | |
]; | |
- // Add cachability metadata. | |
- /** @var Drupal\Core\Render\Renderer $renderer */ | |
- $renderer = \Drupal::service('renderer'); | |
- $renderer->addCacheableDependency($page_bottom['olark'], $settings); | |
+ | |
+ return $render; | |
} | |
diff --git a/src/Form/OlarkSettings.php b/src/Form/OlarkSettings.php | |
index af12e43..cc93b0a 100644 | |
--- a/src/Form/OlarkSettings.php | |
+++ b/src/Form/OlarkSettings.php | |
@@ -50,12 +50,6 @@ class OlarkSettings extends ConfigFormBase { | |
*/ | |
public function buildForm(array $form, FormStateInterface $form_state) { | |
$settings = \Drupal::config('olark.settings'); | |
- $form['olark_enable'] = [ | |
- '#type' => 'checkbox', | |
- '#title' => $this->t('Enable Olark'), | |
- '#default_value' => $settings->get('olark_enable', TRUE), | |
- '#description' => $this->t('Enable / disable Olark integration for this site.'), | |
- ]; | |
$form['olark_code'] = [ | |
'#type' => 'textarea', | |
@@ -70,6 +64,12 @@ class OlarkSettings extends ConfigFormBase { | |
'#description' => $this->t('Hides it on iPhone, iPad and iPod since it has issues in this platforms.'), | |
'#default_value' => $settings->get('olark_ios'), | |
]; | |
+ $form['olark_enable'] = [ | |
+ '#type' => 'checkbox', | |
+ '#title' => $this->t('Enable Olark'), | |
+ '#default_value' => $settings->get('olark_enable', TRUE), | |
+ '#description' => $this->t('Enable / disable Olark integration for this site.'), | |
+ ]; | |
$form['olark_enable_admin'] = [ | |
'#type' => 'checkbox', | |
'#title' => $this->t('Enable on admin pages.'), | |
diff --git a/src/Plugin/Block/OlarkBlock.php b/src/Plugin/Block/OlarkBlock.php | |
new file mode 100755 | |
index 0000000..90ebe9f | |
--- /dev/null | |
+++ b/src/Plugin/Block/OlarkBlock.php | |
@@ -0,0 +1,25 @@ | |
+<?php | |
+ | |
+namespace Drupal\olark\Plugin\Block; | |
+ | |
+use Drupal\Core\Block\BlockBase; | |
+ | |
+/** | |
+ * Show the chat widget as a block. | |
+ * | |
+ * @Block( | |
+ * id = "olark_block", | |
+ * admin_label = @Translation("Olark"), | |
+ * category = @Translation("Olark"), | |
+ * ) | |
+ */ | |
+class OlarkBlock extends BlockBase { | |
+ | |
+ /** | |
+ * {@inheritdoc} | |
+ */ | |
+ public function build() { | |
+ return olark_render_array(); | |
+ } | |
+ | |
+} | |
+ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment