From fd0dea9a2b4b5e7ccfade1a6b677496e6ee62995 Mon Sep 17 00:00:00 2001 From: Kurtis Dunn Date: Sun, 29 Nov 2015 22:49:33 +1100 Subject: [PATCH] Update token.tokens.inc Replace calls to \Drupal\Component\Utility\String with \Drupal\Component\Utility\SafeMarkup --- token.tokens.inc | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/token.tokens.inc b/token.tokens.inc index 2bd8166..8fc4e07 100644 --- a/token.tokens.inc +++ b/token.tokens.inc @@ -5,7 +5,7 @@ * Token callbacks for the token module. */ use Drupal\Component\Utility\Crypt; -use Drupal\Component\Utility\String; +use Drupal\Component\Utility\SafeMarkup; use Drupal\Component\Utility\Unicode; use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Render\Element; @@ -100,7 +100,7 @@ function token_token_info_alter(&$info) { /* @var \Drupal\system\Entity\DateFormat $date_format_type_info */ if (!isset($info['tokens']['date'][$date_format_type])) { $info['tokens']['date'][$date_format_type] = array( - 'name' => String::checkPlain($date_format_type_info->label()), + 'name' => SafeMarkup::checkPlain($date_format_type_info->label()), 'description' => t("A date in '@type' format. (%date)", array('@type' => $date_format_type, '%date' => format_date(REQUEST_TIME, $date_format_type))), 'module' => 'token', ); @@ -434,7 +434,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option break; case 'content-type': $type_name = \Drupal::entityManager()->getStorage('node_type')->load($node->getType())->label(); - $replacements[$original] = $sanitize ? String::checkPlain($type_name) : $type_name; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($type_name) : $type_name; break; } } @@ -459,7 +459,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option foreach ($tokens as $name => $original) { switch ($name) { case 'name': - $replacements[$original] = $sanitize ? String::checkPlain($node_type->label()) : $node_type->label(); + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($node_type->label()) : $node_type->label(); break; case 'machine-name': // This is a machine name so does not ever need to be sanitized. @@ -506,7 +506,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option $parents = $term_storage->loadAllParents($term->id()); $root_term = end($parents); if ($root_term->id() != $term->id()) { - $replacements[$original] = $sanitize ? String::checkPlain($root_term->label()) : $root_term->label(); + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($root_term->label()) : $root_term->label(); } break; } @@ -556,11 +556,11 @@ function token_tokens($type, array $tokens, array $data = array(), array $option switch ($name) { case 'basename': $basename = pathinfo($file->uri->value, PATHINFO_BASENAME); - $replacements[$original] = $sanitize ? String::checkPlain($basename) : $basename; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($basename) : $basename; break; case 'extension': $extension = pathinfo($file->uri->value, PATHINFO_EXTENSION); - $replacements[$original] = $sanitize ? String::checkPlain($extension) : $extension; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($extension) : $extension; break; case 'size-raw': $replacements[$original] = (int) $file->filesize->value; @@ -616,7 +616,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option switch ($name) { case 'ip-address': $ip = \Drupal::request()->getClientIp(); - $replacements[$original] = $sanitize ? String::checkPlain($ip) : $ip; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($ip) : $ip; break; } } @@ -639,7 +639,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option $replacements[$original] = $link->getPluginId(); break; case 'title': - $replacements[$original] = $sanitize ? String::checkPlain($link->getTitle()) : $link->getTitle(); + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($link->getTitle()) : $link->getTitle(); break; case 'url': $replacements[$original] = $link->getUrlObject()->setAbsolute()->toString(); @@ -648,7 +648,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option /** @var \Drupal\Core\Menu\MenuLinkInterface $parent */ if ($link->getParent() && $parent = $menu_link_manager->createInstance($link->getParent())) { - $replacements[$original] = $sanitize ? String::checkPlain($parent->getTitle()) : $parent->getTitle(); + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($parent->getTitle()) : $parent->getTitle(); } break; case 'parents': @@ -659,7 +659,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option case 'root'; if ($link->getParent() && $parent_ids = array_keys(token_menu_link_load_all_parents($link->getPluginId()))) { $root = $menu_link_manager->createInstance(array_shift($parent_ids)); - $replacements[$original] = $sanitize ? String::checkPlain($root->getTitle()) : $root->label(); + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($root->getTitle()) : $root->label(); } break; } @@ -694,7 +694,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option $request = \Drupal::request(); $route = $request->attributes->get(RouteObjectInterface::ROUTE_OBJECT); $title = \Drupal::service('title_resolver')->getTitle($request, $route); - $replacements[$original] = $sanitize ? $title : String::decodeEntities($title); + $replacements[$original] = $sanitize ? $title : SafeMarkup::decodeEntities($title); break; case 'url': $replacements[$original] = Url::fromRoute('', [], $url_options)->toString(); @@ -719,7 +719,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option foreach ($arg_tokens as $name => $original) { $parts = explode('/', $path); if (is_numeric($name) && isset($parts[$name])) { - $replacements[$original] = $sanitize ? String::checkPlain($parts[$name]) : $parts[$name]; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($parts[$name]) : $parts[$name]; } } } @@ -730,7 +730,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option // @todo Should this use filter_input()? if (\Drupal::request()->query->has($name)) { $value = \Drupal::request()->query->get($name); - $replacements[$original] = $sanitize ? String::checkPlain($value) : $value; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($value) : $value; } } } @@ -754,12 +754,12 @@ function token_tokens($type, array $tokens, array $data = array(), array $option switch ($name) { case 'path': $value = !($url->getOption('alias')) ? \Drupal::service('path.alias_manager')->getAliasByPath($path, $langcode) : $path; - $replacements[$original] = $sanitize ? String::checkPlain($value) : $value; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($value) : $value; break; case 'alias': // @deprecated $alias = \Drupal::service('path.alias_manager')->getAliasByPath($path, $langcode); - $replacements[$original] = $sanitize ? String::checkPlain($alias) : $alias; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($alias) : $alias; break; case 'absolute': $replacements[$original] = $url->setAbsolute()->toString(); @@ -811,7 +811,7 @@ function token_tokens($type, array $tokens, array $data = array(), array $option case 'original': if (_token_module($type, 'original') == 'token' && !empty($entity->original)) { $label = $entity->original->label(); - $replacements[$original] = $sanitize ? String::checkPlain($label) : $label; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($label) : $label; } break; } @@ -849,12 +849,12 @@ function token_tokens($type, array $tokens, array $data = array(), array $option case 'first': $value = $array[$keys[0]]; $value = is_array($value) ? render($value) : (string) $value; - $replacements[$original] = $sanitize ? String::checkPlain($value) : $value; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($value) : $value; break; case 'last': $value = $array[$keys[count($keys) - 1]]; $value = is_array($value) ? render($value) : (string) $value; - $replacements[$original] = $sanitize ? String::checkPlain($value) : $value; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($value) : $value; break; case 'count': $replacements[$original] = count($keys); @@ -972,7 +972,7 @@ function book_tokens($type, $tokens, array $data = array(), array $options = arr foreach ($tokens as $name => $original) { switch ($name) { case 'book': - $replacements[$original] = $sanitize ? String::checkPlain($link['title']) : $link['title']; + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($link['title']) : $link['title']; break; } } @@ -1067,7 +1067,7 @@ function menu_ui_tokens($type, $tokens, array $data = array(), array $options = $url = $node->urlInfo(); if ($links = $menu_link_manager->loadLinksByRoute($url->getRouteName(), $url->getRouteParameters())) { $link = reset($links); - $replacements[$original] = $sanitize ? String::checkPlain($link->getTitle()) : $link->getTitle(); + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($link->getTitle()) : $link->getTitle(); } break; } @@ -1096,7 +1096,7 @@ function menu_ui_tokens($type, $tokens, array $data = array(), array $options = switch ($name) { case 'menu': if ($menu = Menu::load($link->getMenuName())) { - $replacements[$original] = $sanitize ? String::checkPlain($menu->label()) : $menu->label(); + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($menu->label()) : $menu->label(); } break; @@ -1120,7 +1120,7 @@ function menu_ui_tokens($type, $tokens, array $data = array(), array $options = foreach ($tokens as $name => $original) { switch ($name) { case 'name': - $replacements[$original] = $sanitize ? String::checkPlain($menu->label()) : $menu->label(); + $replacements[$original] = $sanitize ? SafeMarkup::checkPlain($menu->label()) : $menu->label(); break; case 'machine-name': @@ -1197,7 +1197,7 @@ function field_token_info_alter(&$info) { } $info['tokens'][$token_type][$field_name] = array( - 'name' => String::checkPlain($label), + 'name' => SafeMarkup::checkPlain($label), 'description' => $description, 'module' => 'token', );