summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorziomizar2016-07-27 21:50:16 -0700
committermicropat2016-07-27 21:50:16 -0700
commit176feea77a86efe3cdf102b8289191560c517636 (patch)
treed21e6a45d52b96902738cead85771bf87f7811d8
parentbefae4419db8ed17e2e690b371d262d66b79d1ae (diff)
Issue #2760383 by ziomizar: Token support
-rw-r--r--addtoany.module29
-rw-r--r--src/Form/AddToAnySettingsForm.php12
2 files changed, 38 insertions, 3 deletions
diff --git a/addtoany.module b/addtoany.module
index ec5628e..699b15b 100644
--- a/addtoany.module
+++ b/addtoany.module
@@ -78,11 +78,23 @@ function addtoany_page_attachments(&$page) {
/**
* Initial JS.
*/
+
+ $additional_js = $config->get('additional_js');
+
+ if (\Drupal::moduleHandler()->moduleExists('token')) {
+ $node = \Drupal::routeMatch()->getParameter('node');
+ $data = [];
+ if ($node) {
+ $data = ['node' => $node];
+ $additional_js = \Drupal::token()->replace($additional_js, $data);
+ }
+ }
+
$javascript_header = 'window.a2a_config=window.a2a_config||{};'
. 'a2a_config.callbacks=a2a_config.callbacks||[];'
. 'a2a_config.templates=a2a_config.templates||{};'
. (($config->get('no_3p')) ? 'a2a_config.no_3p=1;' : '')
- . $config->get('additional_js');
+ . $additional_js;
// Add AddToAny initial JS config.
$page['#attached']['html_head'][] = [
@@ -229,12 +241,23 @@ function addtoany_create_buttons($url = NULL, $title = NULL) {
$universal_button = '';
}
- return ( sprintf('<span class="a2a_kit%s addtoany_list" data-a2a-url="%s" data-a2a-title="%s">%s%s%s</span>',
+ $buttons = sprintf('<span class="a2a_kit%s addtoany_list" data-a2a-url="%s" data-a2a-title="%s">%s%s%s</span>',
($buttons_size != '16') ? ' a2a_kit_size_' . $buttons_size : '',
$link_url,
$link_name,
($universal_button_placement == 'after') ? $additional_html : '',
$universal_button,
($universal_button_placement == 'before') ? $additional_html : ''
- ));
+ );
+
+ if (\Drupal::moduleHandler()->moduleExists('token')) {
+ $node = \Drupal::routeMatch()->getParameter('node');
+ $data = [];
+ if ($node) {
+ $data = ['node' => $node];
+ $buttons = \Drupal::token()->replace($buttons, $data);
+ }
+ }
+
+ return $buttons;
}
diff --git a/src/Form/AddToAnySettingsForm.php b/src/Form/AddToAnySettingsForm.php
index 39eb30d..267d1db 100644
--- a/src/Form/AddToAnySettingsForm.php
+++ b/src/Form/AddToAnySettingsForm.php
@@ -198,6 +198,18 @@ class AddToAnySettingsForm extends ConfigFormBase {
'#description' => t('Disabling may affect analytics and limit some functionality.'),
);
+ if (\Drupal::moduleHandler()->moduleExists('token')) {
+ $form['tokens'] = array(
+ '#theme' => 'token_tree_link',
+ '#token_types' => array('node'),
+ '#global_types' => TRUE,
+ '#click_insert' => TRUE,
+ '#show_restricted' => FALSE,
+ '#recursion_limit' => 3,
+ '#text' => t('Browse available tokens'),
+ );
+ }
+
return parent::buildForm($form, $form_state);
}