summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormicropat2016-06-11 23:16:14 -0700
committermicropat2016-06-11 23:16:14 -0700
commit815acaf457f03d3a6af6dc3d455efec53a01c102 (patch)
tree7a0d9ee778caadc6eda1d6a0d0bdf54bce1bc3f4
parent8b84be840f1b4266b27157f058605c30a094009a (diff)
Handle all types returned from getTitle
since title_resolver's getTitle can return a render array, string, or null. Fixes #2734251
-rw-r--r--addtoany.module15
1 files changed, 12 insertions, 3 deletions
diff --git a/addtoany.module b/addtoany.module
index fe0adc5..ec5628e 100644
--- a/addtoany.module
+++ b/addtoany.module
@@ -175,21 +175,30 @@ function addtoany_create_buttons($url = NULL, $title = NULL) {
$url = UrlHelper::stripDangerousProtocols($url);
}
- // Default to the current title, using the site name for the home page.
+ // Default to the current title if available, otherwise use the site name.
if (!isset($title)) {
+ $site_name = \Drupal::config('system.site')->get('name');
+
if ($is_front) {
- $title = \Drupal::config('system.site')->get('name');
+ $title = $site_name;
}
else {
$request = \Drupal::request();
$route_match = \Drupal::routeMatch();
$title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
+ // Expecting array|string|null from getTitle
+ if (is_array($title)) {
+ $title['#allowed_tags'] = array();
+ $title = \Drupal::service('renderer')->renderPlain($title);
+ }
}
+
+ $title = (empty($title)) ? $site_name : $title;
}
// Set the link name.
$link_name = Html::escape($title);
- // Set the link URL
+ // Set the link URL.
$link_url = Html::escape($url);
//$javascript = _addtoany_create_script($_addtoany_num, $link_name, $link_url);