src/Drupal/functions legacy-removed.php

Functions

watchdog_exception()

watchdog_exception(string  $type, \Exception  $exception, string|null  $message = null, array  $variables = [], int  $severity = \Drupal\Core\Logger\RfcLogLevel::ERROR, string|null  $link = null) : mixed

Logs an exception through the logger service, as Drupal 7's watchdog_exception() did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). Severity defaults to RfcLogLevel::ERROR where Drupal 7 used WATCHDOG_ERROR.

Parameters

string $type

The logger channel.

\Exception $exception

The exception to log.

string|null $message

The message, or null for the default exception message.

array $variables

Placeholder replacements. Exception details are merged in.

int $severity

The RFC 5424 log level.

string|null $link

An optional link to attach to the entry.

Returns

mixed —

module_load_include()

module_load_include(string  $type, string  $module, string|null  $name = null) : string|false

Includes a file from a module's directory, as Drupal 7's module_load_include() did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). Drupal 7 cached each result. This version looks the module path up in the extension.list.module service.

Parameters

string $type

The file extension without the dot, such as "inc".

string $module

The module machine name.

string|null $name

The file base name, or null to use the module name.

Returns

string|false —

The included file path, or false when the file does not exist.

module_load_install()

module_load_install(mixed  $module) : string|false

Loads a module's install file, as Drupal 7's module_load_install() did.

Parameters

mixed $module

Returns

string|false —

The included file path, or false when the module has none.

user_role_names()

user_role_names(bool  $members_only = false, string|null  $permission = null) : array

Returns role labels keyed by role ID, as Drupal 10's user_role_names() did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). Drupal 7 had no function of this name; its user_roles() covered the same job.

Parameters

bool $members_only

Whether to leave out the anonymous role.

string|null $permission

When set, only roles holding this permission are returned.

Returns

array —

Role labels keyed by role ID.

file_icon_class()

file_icon_class(string  $mime_type) : string

Returns the icon class for a MIME type, as Drupal 10's file_icon_class() did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). Drupal 7 had no function of this name.

Parameters

string $mime_type

The MIME type.

Returns

string —

The icon class.

user_password()

user_password(int  $length = 10) : string

Generates a random password, as Drupal 7's user_password() did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). The password comes from the password_generator service.

Parameters

int $length

The password length.

Returns

string —

The generated password.

debug()

debug(mixed  $data, string|null  $label = null, bool  $print_r = true) : mixed

Prints a value as an escaped, preformatted notice, as Drupal 7's debug() did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). $print_r defaults to true here, where Drupal 7 defaulted to false.

Parameters

mixed $data

The value to print.

string|null $label

An optional label.

bool $print_r

True for print_r() output, false for var_export().

Returns

mixed —

file_save_data()

file_save_data(string  $data, string|null  $destination = null, int|\Drupal\Core\File\FileExists  $replace = \Drupal\Core\File\FileSystemInterface::EXISTS_RENAME) : \Drupal\file\FileInterface|false

Saves a string to a new file entity, as Drupal 7's file_save_data() did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). It calls the file.repository service and maps the old integer replace flags to FileExists. It returns false on a file or stream wrapper error.

Parameters

string $data

The contents to write.

string|null $destination

The destination URI, or null for the default scheme root.

int|\Drupal\Core\File\FileExists $replace

The behavior when the file exists: 0 renames, 2 errors, anything else replaces.

Returns

\Drupal\file\FileInterface|false —

The file entity, or false on failure.

file_munge_filename()

file_munge_filename(string  $filename, string  $extensions, bool  $alerts = true) : string

Renames a file so a double extension cannot run as code, as Drupal 7's did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). The allow_insecure_uploads setting comes from system.file config, where Drupal 7 used a variable.

Parameters

string $filename

The file name.

string $extensions

The space-separated list of allowed extensions.

bool $alerts

Whether to show a status message when the name changes.

Returns

string —

The munged file name.

drupal_get_module_schema()

drupal_get_module_schema(string  $module, string|null  $table = null) : array

Returns a module's hook_schema() definition, as Drupal 9's did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). Drupal 7 had no function of this name.

Parameters

string $module

The module machine name.

string|null $table

A table name, or null for the whole schema.

Returns

array —

The table definition or the full schema, empty when none exists.

drupal_get_installed_schema_version()

drupal_get_installed_schema_version(string  $module, bool  $reset = false, bool  $array = false) : int|array

Returns the installed schema version of a module, as Drupal 7's did.

Replaces a function absent from Drupal 11.4.11 core (original cited above). It reads the update.update_hook_registry service, so the Drupal 7 $reset flag has no effect.

Parameters

string $module

The module machine name.

bool $reset

Ignored.

bool $array

True to return the versions of all modules keyed by name.

Returns

int|array —

The schema version, or all versions when $array is set.