Same name and namespace in other branches
  1. 4.6.x includes/common.inc \format_size()
  2. 4.7.x includes/common.inc \format_size()
  3. 5.x includes/common.inc \format_size()
  4. 6.x includes/common.inc \format_size()
  5. 7.x includes/common.inc \format_size()
  6. 8.9.x core/includes/common.inc \format_size()
  7. 9 core/includes/common.inc \format_size()

Generates a string representation for the given byte count.

Parameters

$size: A size in bytes.

$langcode: Optional language code to translate to a language other than what is used to display the page.

Return value

\Drupal\Core\StringTranslation\TranslatableMarkup A translated string representation of the size.

Deprecated

in drupal:10.2.0 and is removed from drupal:11.0.0. Use \Drupal\Core\StringTranslation\ByteSizeMarkup::create($size, $langcode) instead.

See also

https://www.drupal.org/node/2999981

Related topics

3 calls to format_size()
FormAjaxSubscriber::formatSize in core/lib/Drupal/Core/Form/EventSubscriber/FormAjaxSubscriber.php
Wraps format_size()
LegacyCommonTest::testFormatSizeDeprecation in core/tests/Drupal/KernelTests/Core/Common/LegacyCommonTest.php
Tests deprecation of the format_size() function.
MigrateExecutable::formatSize in core/modules/migrate/src/MigrateExecutable.php
Generates a string representation for the given byte count.

File

core/includes/common.inc, line 141
Common functions that many Drupal modules will need to reference.

Code

function format_size($size, $langcode = NULL) {
  @trigger_error('format_size() is deprecated in drupal:10.2.0 and is removed from drupal:11.0.0. Use \\Drupal\\Core\\StringTranslation\\ByteSizeMarkup::create($size, $langcode) instead. See https://www.drupal.org/node/2999981', E_USER_DEPRECATED);
  return ByteSizeMarkup::create($size ?? 0, $langcode);
}