use Drupal\Component\Utility\Crypt;
use Drupal\Component\Utility\Html;
-use Drupal\Component\Utility\SafeMarkup;
+use Drupal\Component\Render\FormattableMarkup;
use Drupal\Component\Utility\Unicode;
use Drupal\Core\Config\BootstrapConfigStorageFactory;
+use Drupal\Core\Extension\Exception\UnknownExtensionException;
use Drupal\Core\Logger\RfcLogLevel;
-use Drupal\Core\Render\Markup;
-use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\Test\TestDatabase;
use Drupal\Core\Session\AccountInterface;
-use Drupal\Core\Site\Settings;
use Drupal\Core\Utility\Error;
use Drupal\Core\StringTranslation\TranslatableMarkup;
/**
* Minimum supported version of PHP.
+ *
+ * Drupal cannot be installed on versions of PHP older than this version.
+ *
+ * @todo Move this to an appropriate autoloadable class. See
+ * https://www.drupal.org/project/drupal/issues/2908079
*/
const DRUPAL_MINIMUM_PHP = '5.5.9';
+/**
+ * Minimum recommended version of PHP.
+ *
+ * Sites installing Drupal on PHP versions lower than this will see a warning
+ * message, but Drupal can still be installed. Used for (e.g.) PHP versions
+ * that have reached their EOL or will in the near future.
+ *
+ * @todo Move this to an appropriate autoloadable class. See
+ * https://www.drupal.org/project/drupal/issues/2908079
+ */
+const DRUPAL_RECOMMENDED_PHP = '7.1';
+
/**
* Minimum recommended value of PHP memory_limit.
*
* 64M was chosen as a minimum requirement in order to allow for additional
* contributed modules to be installed prior to hitting the limit. However,
* 40M is the target for the Standard installation profile.
+ *
+ * @todo Move this to an appropriate autoloadable class. See
+ * https://www.drupal.org/project/drupal/issues/2908079
*/
const DRUPAL_MINIMUM_PHP_MEMORY_LIMIT = '64M';
* The filename of the item if it is to be set explicitly rather
* than by consulting the database.
*
- * @return
+ * @return string
* The filename of the requested item or NULL if the item is not found.
*/
function drupal_get_filename($type, $name, $filename = NULL) {
return 'core/core.info.yml';
}
- // Profiles are converted into modules in system_rebuild_module_data().
- // @todo Remove false-exposure of profiles as modules.
- if ($type == 'profile') {
- $type = 'module';
- }
- if (!isset($files[$type])) {
- $files[$type] = [];
+ if ($type === 'module' || $type === 'profile') {
+ $service_id = 'extension.list.' . $type;
+ /** @var \Drupal\Core\Extension\ExtensionList $extension_list */
+ $extension_list = \Drupal::service($service_id);
+ if (isset($filename)) {
+ // Manually add the info file path of an extension.
+ $extension_list->setPathname($name, $filename);
+ }
+ try {
+ return $extension_list->getPathname($name);
+ }
+ catch (UnknownExtensionException $e) {
+ // Catch the exception. This will result in triggering an error.
+ }
}
+ else {
- if (isset($filename)) {
- $files[$type][$name] = $filename;
- }
- elseif (!isset($files[$type][$name])) {
- // If the pathname of the requested extension is not known, try to retrieve
- // the list of extension pathnames from various providers, checking faster
- // providers first.
- // Retrieve the current module list (derived from the service container).
- if ($type == 'module' && \Drupal::hasService('module_handler')) {
- foreach (\Drupal::moduleHandler()->getModuleList() as $module_name => $module) {
- $files[$type][$module_name] = $module->getPathname();
- }
+ if (!isset($files[$type])) {
+ $files[$type] = [];
}
- // If still unknown, retrieve the file list prepared in state by
- // system_rebuild_module_data() and
- // \Drupal\Core\Extension\ThemeHandlerInterface::rebuildThemeData().
- if (!isset($files[$type][$name]) && \Drupal::hasService('state')) {
- $files[$type] += \Drupal::state()->get('system.' . $type . '.files', []);
+
+ if (isset($filename)) {
+ $files[$type][$name] = $filename;
}
- // If still unknown, create a user-level error message.
- if (!isset($files[$type][$name])) {
- trigger_error(SafeMarkup::format('The following @type is missing from the file system: @name', ['@type' => $type, '@name' => $name]), E_USER_WARNING);
+ elseif (!isset($files[$type][$name])) {
+ // If still unknown, retrieve the file list prepared in state by
+ // \Drupal\Core\Extension\ExtensionList() and
+ // \Drupal\Core\Extension\ThemeHandlerInterface::rebuildThemeData().
+ if (!isset($files[$type][$name]) && \Drupal::hasService('state')) {
+ $files[$type] += \Drupal::state()->get('system.' . $type . '.files', []);
+ }
}
- }
- if (isset($files[$type][$name])) {
- return $files[$type][$name];
+ if (isset($files[$type][$name])) {
+ return $files[$type][$name];
+ }
}
+ // If the filename is still unknown, create a user-level error message.
+ trigger_error(new FormattableMarkup('The following @type is missing from the file system: @name', ['@type' => $type, '@name' => $name]), E_USER_WARNING);
}
/**
* The name of the item for which the path is requested. Ignored for
* $type 'core'.
*
- * @return
+ * @return string
* The path to the requested item or an empty string if the item is not found.
*/
function drupal_get_path($type, $name) {
* @see https://www.drupal.org/node/2302363
*/
function format_string($string, array $args) {
- return SafeMarkup::format($string, $args);
+ return new FormattableMarkup($string, $args);
}
/**
*
* @see drupal_get_messages()
* @see status-messages.html.twig
+ * @see https://www.drupal.org/node/2774931
+ *
+ * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
+ * Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.
*/
function drupal_set_message($message = NULL, $type = 'status', $repeat = FALSE) {
+ @trigger_error('drupal_set_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
+ $messenger = \Drupal::messenger();
if (isset($message)) {
- if (!isset($_SESSION['messages'][$type])) {
- $_SESSION['messages'][$type] = [];
- }
-
- // Convert strings which are safe to the simplest Markup objects.
- if (!($message instanceof Markup) && $message instanceof MarkupInterface) {
- $message = Markup::create((string) $message);
- }
-
- // Do not use strict type checking so that equivalent string and
- // MarkupInterface objects are detected.
- if ($repeat || !in_array($message, $_SESSION['messages'][$type])) {
- $_SESSION['messages'][$type][] = $message;
- }
-
- // Mark this page as being uncacheable.
- \Drupal::service('page_cache_kill_switch')->trigger();
+ $messenger->addMessage($message, $type, $repeat);
}
-
- // Messages not set when DB connection fails.
- return isset($_SESSION['messages']) ? $_SESSION['messages'] : NULL;
+ return $messenger->all();
}
/**
*
* @see drupal_set_message()
* @see status-messages.html.twig
+ * @see https://www.drupal.org/node/2774931
+ *
+ * @deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
+ * Use \Drupal\Core\Messenger\MessengerInterface::all() or
+ * \Drupal\Core\Messenger\MessengerInterface::messagesByType() instead.
*/
function drupal_get_messages($type = NULL, $clear_queue = TRUE) {
- if ($messages = drupal_set_message()) {
+ @trigger_error('drupal_get_message() is deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0. Use \Drupal\Core\Messenger\MessengerInterface::all() or \Drupal\Core\Messenger\MessengerInterface::messagesByType() instead. See https://www.drupal.org/node/2774931', E_USER_DEPRECATED);
+ $messenger = \Drupal::messenger();
+ if ($messages = $messenger->all()) {
if ($type) {
if ($clear_queue) {
- unset($_SESSION['messages'][$type]);
+ $messenger->deleteByType($type);
}
if (isset($messages[$type])) {
return [$type => $messages[$type]];
}
else {
if ($clear_queue) {
- unset($_SESSION['messages']);
+ $messenger->deleteAll();
}
return $messages;
}
/**
* Returns the time zone of the current user.
+ *
+ * @return string
+ * The name of the current user's timezone or the name of the default timezone.
*/
function drupal_get_user_timezone() {
$user = \Drupal::currentUser();
* @param $message
* The error message.
* @param $filename
- * The filename that the error was raised in.
+ * (optional) The filename that the error was raised in.
* @param $line
- * The line number the error was raised at.
+ * (optional) The line number the error was raised at.
* @param $context
- * An array that points to the active symbol table at the point the error
- * occurred.
+ * (optional) An array that points to the active symbol table at the point the
+ * error occurred.
*/
-function _drupal_error_handler($error_level, $message, $filename, $line, $context) {
+function _drupal_error_handler($error_level, $message, $filename = NULL, $line = NULL, $context = NULL) {
require_once __DIR__ . '/errors.inc';
_drupal_error_handler_real($error_level, $message, $filename, $line, $context);
}
else {
$profile = BootstrapConfigStorageFactory::getDatabaseStorage()->read('core.extension')['profile'];
}
-
- // A BC layer just in in case this only exists in Settings. Introduced in
- // Drupal 8.3.x and will be removed before Drupal 9.0.0.
- if (empty($profile)) {
- $profile = Settings::get('install_profile');
- }
}
return $profile;
* internally and should not be passed in; use drupal_static_reset() instead.
* (This function's return value should not be used when TRUE is passed in.)
*
- * @return
+ * @return array
* Returns a variable by reference.
*
* @see drupal_static_reset()
* Formats text for emphasized display in a placeholder inside a sentence.
*
* @deprecated in Drupal 8.0.0, will be removed before Drupal 9.0.0. Use
- * \Drupal\Component\Utility\SafeMarkup::format() or Twig's "placeholder"
- * filter instead. Note this method should not be used to simply emphasize a
- * string and therefore has few valid use-cases. Note also, that this method
- * does not mark the string as safe.
+ * \Drupal\Component\Render\FormattableMarkup or Twig's "placeholder" filter
+ * instead. Note this method should not be used to simply emphasize a string
+ * and therefore has few valid use-cases. Note also, that this method does not
+ * mark the string as safe.
*
* @see https://www.drupal.org/node/2302363
*/
* Wrapper for register_shutdown_function() that catches thrown exceptions to
* avoid "Exception thrown without a stack frame in Unknown".
*
- * @param $callback
+ * @param callable $callback
* The shutdown function to register.
* @param ...
* Additional arguments to pass to the shutdown function.
*
- * @return
+ * @return array
* Array of shutdown functions to be executed.
*
* @see register_shutdown_function()
chdir(DRUPAL_ROOT);
try {
- while (list($key, $callback) = each($callbacks)) {
+ reset($callbacks);
+ // Do not use foreach() here because it is possible that the callback will
+ // add to the $callbacks array via drupal_register_shutdown_function().
+ while ($callback = current($callbacks)) {
call_user_func_array($callback['callback'], $callback['arguments']);
+ next($callbacks);
}
}
// PHP 7 introduces Throwable, which covers both Error and