Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update token.tokens.inc #67

Open
wants to merge 1 commit into
base: 8.x-1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions token.tokens.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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',
);
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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();
Expand All @@ -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':
Expand All @@ -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;
}
Expand Down Expand Up @@ -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('<current>', [], $url_options)->toString();
Expand All @@ -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];
}
}
}
Expand All @@ -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;
}
}
}
Expand All @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand All @@ -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':
Expand Down Expand Up @@ -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',
);
Expand Down