Issue #2361797 by rpayanm, Palashvijay4O, er.pushpinderrana: Remove usage of drupal_strlen().

8.0.x
Alex Pott 2014-11-05 09:24:11 +00:00
parent 55286952b6
commit 12ba160d0a
19 changed files with 31 additions and 23 deletions

View File

@ -9,6 +9,7 @@ namespace Drupal\Core\Mail;
use Drupal\Component\Utility\Html;
use Drupal\Component\Utility\String;
use Drupal\Component\Utility\Unicode;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Site\Settings;
@ -264,7 +265,7 @@ class MailFormatHelper {
// Convert inline HTML text to plain text; not removing line-breaks or
// white-space, since that breaks newlines when sanitizing plain-text.
$value = trim(String::decodeEntities($value));
if (drupal_strlen($value)) {
if (Unicode::strlen($value)) {
$chunk = $value;
}
}

View File

@ -99,7 +99,7 @@ class ItemList extends TypedData implements \IteratorAggregate, ListInterface {
$strings[] = $item->getString();
}
// Remove any empty strings resulting from empty items.
return implode(', ', array_filter($strings, 'drupal_strlen'));
return implode(', ', array_filter($strings, '\Drupal\Component\Utility\Unicode::strlen'));
}
}

View File

@ -115,7 +115,7 @@ class Map extends TypedData implements \IteratorAggregate, ComplexDataInterface
$strings[] = $property->getString();
}
// Remove any empty strings resulting from empty items.
return implode(', ', array_filter($strings, 'drupal_strlen'));
return implode(', ', array_filter($strings, '\Drupal\Component\Utility\Unicode::strlen'));
}
/**

View File

@ -784,7 +784,7 @@ function _filter_html_escape($text) {
function _filter_html_image_secure_process($text) {
// Find the path (e.g. '/') to Drupal root.
$base_path = base_path();
$base_path_length = drupal_strlen($base_path);
$base_path_length = Unicode::strlen($base_path);
// Find the directory on the server where index.php resides.
$local_dir = DRUPAL_ROOT . '/';

View File

@ -6,6 +6,7 @@
*/
use Drupal\Component\Utility\NestedArray;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Render\Element;
/**
@ -64,7 +65,7 @@ function template_preprocess_image_formatter(&$variables) {
$item = $variables['item'];
// Do not output an empty 'title' attribute.
if (drupal_strlen($item->title) != 0) {
if (Unicode::strlen($item->title) != 0) {
$variables['image']['#title'] = $item->title;
}

View File

@ -8,6 +8,7 @@
namespace Drupal\menu_ui\Tests;
use Drupal\Component\Serialization\Json;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Menu\MenuLinkInterface;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\system\Entity\Menu;
@ -175,7 +176,7 @@ class MenuTest extends MenuWebTestBase {
$this->assertRaw(t('!name cannot be longer than %max characters but is currently %length characters long.', array(
'!name' => t('Menu name'),
'%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
'%length' => drupal_strlen($menu_name),
'%length' => Unicode::strlen($menu_name),
)));
// Change the menu_name so it no longer exceeds the maximum length.
@ -187,7 +188,7 @@ class MenuTest extends MenuWebTestBase {
$this->assertNoRaw(t('!name cannot be longer than %max characters but is currently %length characters long.', array(
'!name' => t('Menu name'),
'%max' => MENU_MAX_MENU_NAME_LENGTH_UI,
'%length' => drupal_strlen($menu_name),
'%length' => Unicode::strlen($menu_name),
)));
// Verify that the confirmation message is displayed.
$this->assertRaw(t('Menu %label has been added.', array('%label' => $label)));

View File

@ -7,6 +7,7 @@
namespace Drupal\options\Plugin\Field\FieldType;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
use Drupal\Core\TypedData\DataDefinition;
@ -68,7 +69,7 @@ class ListStringItem extends ListItemBase {
* {@inheritdoc}
*/
protected static function validateAllowedValue($option) {
if (drupal_strlen($option) > 255) {
if (Unicode::strlen($option) > 255) {
return t('Allowed values list: each key must be a string at most 255 characters long.');
}
}

View File

@ -6,6 +6,7 @@
*/
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Routing\RouteMatchInterface;
use \Drupal\Core\Template\Attribute;
use Drupal\Core\Url;
@ -144,7 +145,7 @@ function theme_responsive_image_formatter($variables) {
$responsive_image['#entity'] = $entity;
}
$responsive_image['#alt'] = $item->alt;
if (drupal_strlen($item->title) != 0) {
if (Unicode::strlen($item->title) != 0) {
$responsive_image['#title'] = $item->title;
}
// @todo Add support for route names.

View File

@ -306,7 +306,7 @@ function search_simplify($text, $langcode = NULL) {
function search_expand_cjk($matches) {
$min = \Drupal::config('search.settings')->get('index.minimum_word_size');
$str = $matches[0];
$length = drupal_strlen($str);
$length = Unicode::strlen($str);
// If the text is shorter than the minimum word size, don't tokenize it.
if ($length <= $min) {
return ' ' . $str . ' ';
@ -453,7 +453,7 @@ function search_index($sid, $type, $text, $langcode) {
// Add word to accumulator
$accum .= $word . ' ';
// Check wordlength
if (is_numeric($word) || drupal_strlen($word) >= $minimum_word_size) {
if (is_numeric($word) || Unicode::strlen($word) >= $minimum_word_size) {
if (!isset($scored_words[$word])) {
$scored_words[$word] = 0;
}

View File

@ -9,6 +9,7 @@
namespace Drupal\search;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Database\Query\SelectExtender;
use Drupal\Core\Database\StatementEmpty;
@ -367,7 +368,7 @@ class SearchQuery extends SelectExtender {
$split = explode(' ', $word);
foreach ($split as $s) {
$num = is_numeric($s);
if ($num || drupal_strlen($s) >= \Drupal::config('search.settings')->get('index.minimum_word_size')) {
if ($num || Unicode::strlen($s) >= \Drupal::config('search.settings')->get('index.minimum_word_size')) {
if (!isset($this->words[$s])) {
$this->words[$s] = $s;
$num_new_scores++;

View File

@ -39,7 +39,7 @@ class SearchSimplifyTest extends SearchTestBase {
// Split this into 30-character chunks, so we don't run into limits
// of truncation in search_simplify().
$start = 0;
while ($start < drupal_strlen($string)) {
while ($start < Unicode::strlen($string)) {
$newstr = Unicode::substr($string, $start, 30);
// Special case: leading zeros are removed from numeric strings,
// and there's one string in this file that is numbers starting with
@ -54,7 +54,7 @@ class SearchSimplifyTest extends SearchTestBase {
}
foreach ($strings as $key => $string) {
$simplified = search_simplify($string);
$this->assertTrue(drupal_strlen($simplified) >= drupal_strlen($string), "Nothing is removed from string $key.");
$this->assertTrue(Unicode::strlen($simplified) >= Unicode::strlen($string), "Nothing is removed from string $key.");
}
// Test the low-numbered ASCII control characters separately. They are not

View File

@ -352,7 +352,7 @@ class HtmlToTextTest extends WebTestBase {
$maximum_line_length = 0;
foreach (explode($eol, $output) as $line) {
// We must use strlen() rather than drupal_strlen() in order to count
// We must use strlen() rather than Unicode::strlen() in order to count
// octets rather than characters.
$maximum_line_length = max($maximum_line_length, strlen($line . $eol));
}

View File

@ -91,7 +91,7 @@ function text_summary($text, $format = NULL, $size = NULL) {
}
// If we have a short body, the entire body is the summary.
if (drupal_strlen($text) <= $size) {
if (Unicode::strlen($text) <= $size) {
return $text;
}

View File

@ -7,6 +7,7 @@
namespace Drupal\user;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Entity\ContentEntityForm;
use Drupal\Core\Entity\EntityManagerInterface;
use Drupal\Core\Entity\Query\QueryFactory;
@ -379,7 +380,7 @@ abstract class AccountForm extends ContentEntityForm {
// automatic typed data validation in https://drupal.org/node/2227381.
$field_definitions = $this->entityManager->getFieldDefinitions('user', $this->getEntity()->bundle());
$max_length = $field_definitions['signature']->getSetting('max_length');
if (drupal_strlen($form_state->getValue('signature')) > $max_length) {
if (Unicode::strlen($form_state->getValue('signature')) > $max_length) {
$form_state->setErrorByName('signature', $this->t('The signature is too long: it must be %max characters or less.', array('%max' => $max_length)));
}
}

View File

@ -7,6 +7,7 @@
namespace Drupal\user\Plugin\Validation\Constraint;
use Drupal\Component\Utility\Unicode;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
@ -48,7 +49,7 @@ class UserNameConstraintValidator extends ConstraintValidator {
) {
$this->context->addViolation($constraint->illegalMessage);
}
if (drupal_strlen($name) > USERNAME_MAX_LENGTH) {
if (Unicode::strlen($name) > USERNAME_MAX_LENGTH) {
$this->context->addViolation($constraint->tooLongMessage, array('%name' => $name, '%max' => USERNAME_MAX_LENGTH));
}
}

View File

@ -556,7 +556,7 @@ function template_preprocess_username(&$variables) {
// their own shortening logic or add markup. If they do so, they must ensure
// that $variables['name'] is safe for printing.
$name = $variables['name_raw'] = $account->getUsername();
if (drupal_strlen($name) > 20) {
if (Unicode::strlen($name) > 20) {
$name = Unicode::truncate($name, 15, FALSE, TRUE);
$variables['truncated'] = TRUE;
}

View File

@ -1289,7 +1289,7 @@ abstract class FieldPluginBase extends HandlerBase {
$base_path = base_path();
// Checks whether the path starts with the base_path.
if (strpos($more_link_path, $base_path) === 0) {
$more_link_path = Unicode::substr($more_link_path, drupal_strlen($base_path));
$more_link_path = Unicode::substr($more_link_path, Unicode::strlen($base_path));
}
$more_link = _l($more_link_text, $more_link_path, array('attributes' => array('class' => array('views-more-link'))));
@ -1705,7 +1705,7 @@ abstract class FieldPluginBase extends HandlerBase {
* The trimmed string.
*/
public static function trimText($alter, $value) {
if (drupal_strlen($value) > $alter['max_length']) {
if (Unicode::strlen($value) > $alter['max_length']) {
$value = Unicode::substr($value, 0, $alter['max_length']);
if (!empty($alter['word_boundary'])) {
$regex = "(.*)\b.+";

View File

@ -367,7 +367,7 @@ class InOperator extends FilterPluginBase {
if ($values !== '') {
$values .= ', ';
}
if (drupal_strlen($values) > 8) {
if (Unicode::strlen($values) > 8) {
$values = Unicode::truncate($values, 8, FALSE, TRUE);
break;
}

View File

@ -327,7 +327,7 @@ function views_ui_views_analyze(ViewExecutable $view) {
* This is often used in the UI to ensure long strings fit.
*/
function views_ui_truncate($string, $length) {
if (drupal_strlen($string) > $length) {
if (Unicode::strlen($string) > $length) {
$string = Unicode::substr($string, 0, $length);
$string .= '...';
}