Commit c06ebaa0 authored by catch's avatar catch

Issue #2196907 by divesh.kumar: Convert all calls & docs references to...

Issue #2196907 by divesh.kumar: Convert all calls & docs references to check_plain() in core to Drupal\Component\Utility\String::checkPlain() in link module.
parent 5bf67c98
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\link\Plugin\Field\FieldFormatter; namespace Drupal\link\Plugin\Field\FieldFormatter;
use Drupal\Component\Utility\Url; use Drupal\Component\Utility\Url;
use Drupal\Component\Utility\String;
use Drupal\Core\Field\FieldItemListInterface; use Drupal\Core\Field\FieldItemListInterface;
use Drupal\Core\Field\FieldItemInterface; use Drupal\Core\Field\FieldItemInterface;
use Drupal\Core\Field\FormatterBase; use Drupal\Core\Field\FormatterBase;
...@@ -137,7 +138,7 @@ public function viewElements(FieldItemListInterface $items) { ...@@ -137,7 +138,7 @@ public function viewElements(FieldItemListInterface $items) {
if (!empty($settings['url_only']) && !empty($settings['url_plain'])) { if (!empty($settings['url_only']) && !empty($settings['url_plain'])) {
$element[$delta] = array( $element[$delta] = array(
'#markup' => check_plain($link_title), '#markup' => String::checkPlain($link_title),
); );
} }
else { else {
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
namespace Drupal\link\Tests; namespace Drupal\link\Tests;
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
use Drupal\Component\Utility\String;
/** /**
* Tests link field widgets and formatters. * Tests link field widgets and formatters.
...@@ -347,41 +348,41 @@ function testLinkFormatter() { ...@@ -347,41 +348,41 @@ function testLinkFormatter() {
case 'trim_length': case 'trim_length':
$url = $url1; $url = $url1;
$title = isset($new_value) ? truncate_utf8($title1, $new_value, FALSE, TRUE) : $title1; $title = isset($new_value) ? truncate_utf8($title1, $new_value, FALSE, TRUE) : $title1;
$this->assertRaw('<a href="' . check_plain($url) . '">' . check_plain($title) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url) . '">' . String::checkPlain($title) . '</a>');
$url = $url2; $url = $url2;
$title = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2; $title = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2;
$this->assertRaw('<a href="' . check_plain($url) . '">' . check_plain($title) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url) . '">' . String::checkPlain($title) . '</a>');
break; break;
case 'rel': case 'rel':
$rel = isset($new_value) ? ' rel="' . $new_value . '"' : ''; $rel = isset($new_value) ? ' rel="' . $new_value . '"' : '';
$this->assertRaw('<a href="' . check_plain($url1) . '"' . $rel . '>' . check_plain($title1) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url1) . '"' . $rel . '>' . String::checkPlain($title1) . '</a>');
$this->assertRaw('<a href="' . check_plain($url2) . '"' . $rel . '>' . check_plain($title2) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url2) . '"' . $rel . '>' . String::checkPlain($title2) . '</a>');
break; break;
case 'target': case 'target':
$target = isset($new_value) ? ' target="' . $new_value . '"' : ''; $target = isset($new_value) ? ' target="' . $new_value . '"' : '';
$this->assertRaw('<a href="' . check_plain($url1) . '"' . $target . '>' . check_plain($title1) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url1) . '"' . $target . '>' . String::checkPlain($title1) . '</a>');
$this->assertRaw('<a href="' . check_plain($url2) . '"' . $target . '>' . check_plain($title2) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url2) . '"' . $target . '>' . String::checkPlain($title2) . '</a>');
break; break;
case 'url_only': case 'url_only':
// In this case, $new_value is an array. // In this case, $new_value is an array.
if (!$new_value['url_only']) { if (!$new_value['url_only']) {
$this->assertRaw('<a href="' . check_plain($url1) . '">' . check_plain($title1) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url1) . '">' . String::checkPlain($title1) . '</a>');
$this->assertRaw('<a href="' . check_plain($url2) . '">' . check_plain($title2) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url2) . '">' . String::checkPlain($title2) . '</a>');
} }
else { else {
if (empty($new_value['url_plain'])) { if (empty($new_value['url_plain'])) {
$this->assertRaw('<a href="' . check_plain($url1) . '">' . check_plain($url1) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url1) . '">' . String::checkPlain($url1) . '</a>');
$this->assertRaw('<a href="' . check_plain($url2) . '">' . check_plain($url2) . '</a>'); $this->assertRaw('<a href="' . String::checkPlain($url2) . '">' . String::checkPlain($url2) . '</a>');
} }
else { else {
$this->assertNoRaw('<a href="' . check_plain($url1) . '">' . check_plain($url1) . '</a>'); $this->assertNoRaw('<a href="' . String::checkPlain($url1) . '">' . String::checkPlain($url1) . '</a>');
$this->assertNoRaw('<a href="' . check_plain($url2) . '">' . check_plain($url2) . '</a>'); $this->assertNoRaw('<a href="' . String::checkPlain($url2) . '">' . String::checkPlain($url2) . '</a>');
$this->assertRaw(check_plain($url1)); $this->assertRaw(String::checkPlain($url1));
$this->assertRaw(check_plain($url2)); $this->assertRaw(String::checkPlain($url2));
} }
} }
break; break;
...@@ -469,7 +470,7 @@ function testLinkSeparateFormatter() { ...@@ -469,7 +470,7 @@ function testLinkSeparateFormatter() {
$url = $url1; $url = $url1;
$url_title = isset($new_value) ? truncate_utf8($url, $new_value, FALSE, TRUE) : $url; $url_title = isset($new_value) ? truncate_utf8($url, $new_value, FALSE, TRUE) : $url;
$expected = '<div class="link-item">'; $expected = '<div class="link-item">';
$expected .= '<div class="link-url"><a href="' . check_plain($url) . '">' . check_plain($url_title) . '</a></div>'; $expected .= '<div class="link-url"><a href="' . String::checkPlain($url) . '">' . String::checkPlain($url_title) . '</a></div>';
$expected .= '</div>'; $expected .= '</div>';
$this->assertRaw($expected); $this->assertRaw($expected);
...@@ -477,22 +478,22 @@ function testLinkSeparateFormatter() { ...@@ -477,22 +478,22 @@ function testLinkSeparateFormatter() {
$url_title = isset($new_value) ? truncate_utf8($url, $new_value, FALSE, TRUE) : $url; $url_title = isset($new_value) ? truncate_utf8($url, $new_value, FALSE, TRUE) : $url;
$title = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2; $title = isset($new_value) ? truncate_utf8($title2, $new_value, FALSE, TRUE) : $title2;
$expected = '<div class="link-item">'; $expected = '<div class="link-item">';
$expected .= '<div class="link-title">' . check_plain($title) . '</div>'; $expected .= '<div class="link-title">' . String::checkPlain($title) . '</div>';
$expected .= '<div class="link-url"><a href="' . check_plain($url) . '">' . check_plain($url_title) . '</a></div>'; $expected .= '<div class="link-url"><a href="' . String::checkPlain($url) . '">' . String::checkPlain($url_title) . '</a></div>';
$expected .= '</div>'; $expected .= '</div>';
$this->assertRaw($expected); $this->assertRaw($expected);
break; break;
case 'rel': case 'rel':
$rel = isset($new_value) ? ' rel="' . $new_value . '"' : ''; $rel = isset($new_value) ? ' rel="' . $new_value . '"' : '';
$this->assertRaw('<div class="link-url"><a href="' . check_plain($url1) . '"' . $rel . '>' . check_plain($url1) . '</a></div>'); $this->assertRaw('<div class="link-url"><a href="' . String::checkPlain($url1) . '"' . $rel . '>' . String::checkPlain($url1) . '</a></div>');
$this->assertRaw('<div class="link-url"><a href="' . check_plain($url2) . '"' . $rel . '>' . check_plain($url2) . '</a></div>'); $this->assertRaw('<div class="link-url"><a href="' . String::checkPlain($url2) . '"' . $rel . '>' . String::checkPlain($url2) . '</a></div>');
break; break;
case 'target': case 'target':
$target = isset($new_value) ? ' target="' . $new_value . '"' : ''; $target = isset($new_value) ? ' target="' . $new_value . '"' : '';
$this->assertRaw('<div class="link-url"><a href="' . check_plain($url1) . '"' . $target . '>' . check_plain($url1) . '</a></div>'); $this->assertRaw('<div class="link-url"><a href="' . String::checkPlain($url1) . '"' . $target . '>' . String::checkPlain($url1) . '</a></div>');
$this->assertRaw('<div class="link-url"><a href="' . check_plain($url2) . '"' . $target . '>' . check_plain($url2) . '</a></div>'); $this->assertRaw('<div class="link-url"><a href="' . String::checkPlain($url2) . '"' . $target . '>' . String::checkPlain($url2) . '</a></div>');
break; break;
} }
} }
......
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
* Defines simple link field types. * Defines simple link field types.
*/ */
use Drupal\Component\Utility\String;
/** /**
* Implements hook_help(). * Implements hook_help().
*/ */
...@@ -60,7 +62,7 @@ function link_theme() { ...@@ -60,7 +62,7 @@ function link_theme() {
*/ */
function template_preprocess_link_formatter_link_separate(&$variables) { function template_preprocess_link_formatter_link_separate(&$variables) {
if (!empty($variables['title'])) { if (!empty($variables['title'])) {
$variables['title'] = check_plain($variables['title']); $variables['title'] = String::checkPlain($variables['title']);
} }
$variables['link'] = l($variables['url_title'], $variables['href'], $variables['options']); $variables['link'] = l($variables['url_title'], $variables['href'], $variables['options']);
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment