Chris@0: listInfo() instead. Chris@18: * Chris@18: * @see https://www.drupal.org/node/2709919 Chris@0: * @see \Drupal\Core\Extension\ThemeHandler::listInfo() Chris@0: */ Chris@0: function system_list($type) { Chris@18: @trigger_error('system_list() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. Use \Drupal::service(\'theme_handler\')->listInfo() instead. See https://www.drupal.org/node/2709919', E_USER_DEPRECATED); Chris@18: Chris@18: $lists = [ Chris@18: 'theme' => \Drupal::service('theme_handler')->listInfo(), Chris@18: 'filepaths' => [], Chris@18: ]; Chris@18: foreach ($lists['theme'] as $name => $theme) { Chris@18: $lists['filepaths'][] = [ Chris@18: 'type' => 'theme', Chris@18: 'name' => $name, Chris@18: 'filepath' => $theme->getPathname(), Chris@18: ]; Chris@0: } Chris@0: return $lists[$type]; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Resets all system_list() caches. Chris@18: * Chris@18: * @deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. There Chris@18: * is no direct replacement. Call each Chris@18: * \Drupal::service('extension.list.TYPE')->reset() as necessary. Chris@18: * Chris@18: * @see https://www.drupal.org/node/2709919 Chris@0: */ Chris@0: function system_list_reset() { Chris@18: @trigger_error("system_list_reset() is deprecated in Drupal 8.7.0 and will be removed before Drupal 9.0.0. There is no direct replacement. Call each \Drupal::service('extension.list.TYPE')->reset() as necessary. See https://www.drupal.org/node/2709919.", E_USER_DEPRECATED); Chris@18: \Drupal::service('extension.list.profile')->reset(); Chris@17: \Drupal::service('extension.list.module')->reset(); Chris@18: \Drupal::service('extension.list.theme_engine')->reset(); Chris@18: \Drupal::service('extension.list.theme')->reset(); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Registers an extension in runtime registries for execution. Chris@0: * Chris@0: * @param string $type Chris@0: * The extension type; e.g., 'module' or 'theme'. Chris@0: * @param string $name Chris@0: * The internal name of the extension; e.g., 'node'. Chris@0: * @param string $uri Chris@0: * The relative URI of the primary extension file; e.g., Chris@0: * 'core/modules/node/node.module'. Chris@0: */ Chris@0: function system_register($type, $name, $uri) { Chris@0: drupal_get_filename($type, $name, $uri); Chris@0: drupal_classloader_register($name, dirname($uri)); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Loads a module's installation hooks. Chris@0: * Chris@0: * @param $module Chris@0: * The name of the module (without the .module extension). Chris@0: * Chris@0: * @return Chris@0: * The name of the module's install file, if successful; FALSE otherwise. Chris@0: */ Chris@0: function module_load_install($module) { Chris@0: // Make sure the installation API is available Chris@0: include_once __DIR__ . '/install.inc'; Chris@0: Chris@0: return module_load_include('install', $module); Chris@0: } Chris@0: Chris@0: /** Chris@0: * Loads a module include file. Chris@0: * Chris@0: * Examples: Chris@0: * @code Chris@0: * // Load node.admin.inc from the node module. Chris@0: * module_load_include('inc', 'node', 'node.admin'); Chris@0: * // Load content_types.inc from the node module. Chris@0: * module_load_include('inc', 'node', 'content_types'); Chris@0: * @endcode Chris@0: * Chris@0: * Do not use this function to load an install file, use module_load_install() Chris@0: * instead. Do not use this function in a global context since it requires Chris@0: * Drupal to be fully bootstrapped, use require_once DRUPAL_ROOT . '/path/file' Chris@0: * instead. Chris@0: * Chris@0: * @param $type Chris@0: * The include file's type (file extension). Chris@0: * @param $module Chris@0: * The module to which the include file belongs. Chris@0: * @param $name Chris@0: * (optional) The base file name (without the $type extension). If omitted, Chris@0: * $module is used; i.e., resulting in "$module.$type" by default. Chris@0: * Chris@0: * @return Chris@0: * The name of the included file, if successful; FALSE otherwise. Chris@0: * Chris@0: * @todo The module_handler service has a loadInclude() method which performs Chris@0: * this same task but only for enabled modules. Figure out a way to move this Chris@0: * functionality entirely into the module_handler while keeping the ability to Chris@0: * load the files of disabled modules. Chris@0: */ Chris@0: function module_load_include($type, $module, $name = NULL) { Chris@0: if (!isset($name)) { Chris@0: $name = $module; Chris@0: } Chris@0: Chris@0: if (function_exists('drupal_get_path')) { Chris@0: $file = DRUPAL_ROOT . '/' . drupal_get_path('module', $module) . "/$name.$type"; Chris@0: if (is_file($file)) { Chris@0: require_once $file; Chris@0: return $file; Chris@0: } Chris@0: } Chris@0: return FALSE; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Returns an array of modules required by core. Chris@0: */ Chris@0: function drupal_required_modules() { Chris@0: $listing = new ExtensionDiscovery(\Drupal::root()); Chris@0: $files = $listing->scan('module'); Chris@0: $required = []; Chris@0: Chris@0: // Unless called by the installer, an installation profile is required and Chris@0: // must always be loaded. drupal_get_profile() also returns the installation Chris@0: // profile in the installer, but only after it has been selected. Chris@0: if ($profile = drupal_get_profile()) { Chris@0: $required[] = $profile; Chris@0: } Chris@0: Chris@0: foreach ($files as $name => $file) { Chris@0: $info = \Drupal::service('info_parser')->parse($file->getPathname()); Chris@0: if (!empty($info) && !empty($info['required']) && $info['required']) { Chris@0: $required[] = $name; Chris@0: } Chris@0: } Chris@0: Chris@0: return $required; Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sets weight of a particular module. Chris@0: * Chris@0: * The weight of uninstalled modules cannot be changed. Chris@0: * Chris@0: * @param string $module Chris@0: * The name of the module (without the .module extension). Chris@0: * @param int $weight Chris@0: * An integer representing the weight of the module. Chris@0: */ Chris@0: function module_set_weight($module, $weight) { Chris@0: $extension_config = \Drupal::configFactory()->getEditable('core.extension'); Chris@0: if ($extension_config->get("module.$module") !== NULL) { Chris@0: // Pre-cast the $weight to an integer so that we can save this without using Chris@0: // schema. This is a performance improvement for module installation. Chris@0: $extension_config Chris@0: ->set("module.$module", (int) $weight) Chris@0: ->set('module', module_config_sort($extension_config->get('module'))) Chris@0: ->save(TRUE); Chris@0: Chris@0: // Prepare the new module list, sorted by weight, including filenames. Chris@0: // @see \Drupal\Core\Extension\ModuleInstaller::install() Chris@0: $module_handler = \Drupal::moduleHandler(); Chris@0: $current_module_filenames = $module_handler->getModuleList(); Chris@0: $current_modules = array_fill_keys(array_keys($current_module_filenames), 0); Chris@0: $current_modules = module_config_sort(array_merge($current_modules, $extension_config->get('module'))); Chris@0: $module_filenames = []; Chris@0: foreach ($current_modules as $name => $weight) { Chris@0: $module_filenames[$name] = $current_module_filenames[$name]; Chris@0: } Chris@0: // Update the module list in the extension handler. Chris@0: $module_handler->setModuleList($module_filenames); Chris@0: return; Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * Sorts the configured list of enabled modules. Chris@0: * Chris@0: * The list of enabled modules is expected to be ordered by weight and name. Chris@0: * The list is always sorted on write to avoid the overhead on read. Chris@0: * Chris@0: * @param array $data Chris@0: * An array of module configuration data. Chris@0: * Chris@0: * @return array Chris@0: * An array of module configuration data sorted by weight and name. Chris@0: */ Chris@0: function module_config_sort($data) { Chris@0: // PHP array sorting functions such as uasort() do not work with both keys and Chris@0: // values at the same time, so we achieve weight and name sorting by computing Chris@0: // strings with both information concatenated (weight first, name second) and Chris@0: // use that as a regular string sort reference list via array_multisort(), Chris@0: // compound of "[sign-as-integer][padded-integer-weight][name]"; e.g., given Chris@0: // two modules and weights (spaces added for clarity): Chris@0: // - Block with weight -5: 0 0000000000000000005 block Chris@0: // - Node with weight 0: 1 0000000000000000000 node Chris@0: $sort = []; Chris@0: foreach ($data as $name => $weight) { Chris@0: // Prefix negative weights with 0, positive weights with 1. Chris@0: // +/- signs cannot be used, since + (ASCII 43) is before - (ASCII 45). Chris@0: $prefix = (int) ($weight >= 0); Chris@0: // The maximum weight is PHP_INT_MAX, so pad all weights to 19 digits. Chris@0: $sort[] = $prefix . sprintf('%019d', abs($weight)) . $name; Chris@0: } Chris@0: array_multisort($sort, SORT_STRING, $data); Chris@0: return $data; Chris@0: }