use Symfony\Component\HttpFoundation\RedirectResponse;
use GuzzleHttp\Exception\RequestException;
/**
* New users will be set to the default time zone at registration.
*/
const DRUPAL_USER_TIMEZONE_DEFAULT = 0;
/**
* New users will get an empty time zone at registration.
*/
const DRUPAL_USER_TIMEZONE_EMPTY = 1;
/**
* New users will select their own timezone at registration.
*/
const DRUPAL_USER_TIMEZONE_SELECT = 2;
/**
* Disabled option on forms and settings
*/
const DRUPAL_DISABLED = 0;
/**
* Optional option on forms and settings
*/
const DRUPAL_OPTIONAL = 1;
/**
* Required option on forms and settings
*/
const DRUPAL_REQUIRED = 2;
/**
* Return only visible regions.
*
* @see system_region_list()
*/
const REGIONS_VISIBLE = 'visible';
/**
* Return all regions.
*
* @see system_region_list()
*/
const REGIONS_ALL = 'all';
/**
* Implements hook_help().
*/
function system_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.system':
$output = '';
$output .= '<h3>' . t('About') . '</h3>';
$output .= '<p>' . t('The System module is integral to the site: it provides user interfaces for many core systems and settings, as well as the basic administrative menu structure. For more information, see the <a href="!system">online documentation for the System module</a>.', array('!system' => 'https://www.drupal.org/documentation/modules/system')) . '</p>';
$output .= '<dd>' . t('Users with appropriate permission can install and uninstall modules from the <a href="!modules">Extend page</a>. Depending on which distribution or installation profile you choose when you install your site, several modules are installed and others are provided but not installed. Each module provides a discrete set of features; modules may be installed or uninstalled depending on the needs of the site. Many additional modules contributed by members of the Drupal community are available for download from the <a href="!drupal-modules">Drupal.org module page</a>. Note that uninstalling a module is a destructive action: when you uninstall a module, you will permanently lose all data connected to the module.', array('!modules' => \Drupal::url('system.modules_list'), '!drupal-modules' => 'https://www.drupal.org/project/modules')) . '</dd>';
$output .= '<dd>' . t('Users with appropriate permission can install and uninstall themes on the <a href="!themes">Appearance page</a>. Themes determine the design and presentation of your site. Depending on which distribution or installation profile you choose when you install your site, a default theme is installed, and possibly a different theme for administration pages. Other themes are provided but not installed, and additional contributed themes are available at the <a href="!drupal-themes">Drupal.org theme page</a>.', array('!themes' => \Drupal::url('system.themes_page'), '!drupal-themes' => 'https://www.drupal.org/project/themes')) . '</dd>';
$output .= '<dd>' . t('The default drag-and-drop user interface for ordering tables in the administrative interface presents a challenge for some users, including users of screen readers and other assistive technology. The drag-and-drop interface can be disabled in a table by clicking a link labeled "Show row weights" above the table. The replacement interface allows users to order the table by choosing numerical weights instead of dragging table rows.') . '</dd>';
$output .= '<dt>' . t('Configuring basic site settings') . '</dt>';
$output .= '<dd>' . t('The System module provides pages for managing basic site configuration, including <a href="!date-time-settings">Date and time formats</a> and basic <a href="!site-info">Site information</a> (site name, email address to send mail from, home page, and error pages). Additional configuration pages are listed on the main <a href="!config">Configuration page</a>.', array('!date-time-settings' => \Drupal::url('entity.date_format.collection'), '!site-info' => \Drupal::url('system.site_information_settings'), '!config' => \Drupal::url('system.admin_config'))) . '</dd>';
$output .= '<dd>' . t('When you are performing site maintenance, you can prevent non-administrative users (including anonymous visitors) from viewing your site by putting it in <a href="!maintenance-mode">Maintenance mode</a>. This will prevent unauthorized users from making changes to the site while you are performing maintenance, or from seeing a broken site while updates are in progress.', array('!maintenance-mode' => \Drupal::url('system.site_maintenance_mode'))) . '</dd>';
$output .= '<dt>' . t('Configuring for performance') . '</dt>';
$output .= '<dd>' . t('On the <a href="!performance-page">Performance page</a>, the site can be configured to aggregate CSS and JavaScript files, making the total request size smaller. Note that, for small- to medium-sized websites, the <a href="!page-cache">Internal Page Cache module</a> should be installed so that pages are efficiently cached and reused.', array('!performance-page' => \Drupal::url('system.performance_settings'), '!page-cache' => (\Drupal::moduleHandler()->moduleExists('page_cache')) ? \Drupal::url('help.page', array('name' => 'page_cache')) : '#')) . '</dd>';
$output .= '<dd>' . t('In order for the site and its modules to continue to operate well, a set of routine administrative operations must run on a regular basis; these operations are known as <em>cron</em> tasks. On the <a href="!cron">Cron page</a>, you can configure cron to run periodically as part of normal page requests, or you can turn this off and trigger cron from an outside process on your web server. You can verify the status of cron tasks by visiting the <a href="!status">Status report page</a>. For more information, see the <a href="!handbook">online documentation for configuring cron jobs</a>.', array('!status' => \Drupal::url('system.status'), '!handbook' => 'https://www.drupal.org/cron', '!cron' => \Drupal::url('system.cron_settings'))) . '</dd>';
$output .= '<dt>' . t('Configuring the file system') . '</dt>';
$output .= '<dd>' . t('Your site has several file directories, which are used to store and process uploaded and generated files. The <em>public</em> file directory, which is configured in your settings.php file, is the default place for storing uploaded files. Links to files in this directory contain the direct file URL, so when the files are requested, the web server will send them directly without invoking your site code. This means that the files can be downloaded by anyone with the file URL, so requests are not access-controlled but they are efficient. The <em>private</em> file directory, also configured in your settings.php file and ideally located outside the site web root, is access controlled. Links to files in this directory are not direct, so requests to these files are mediated by your site code. This means that your site can check file access permission for each file before deciding to fulfill the request, so the requests are more secure, but less efficient. You should only use the private storage for files that need access control, not for files like your site logo and background images used on every page. The <em>temporary</em> file directory is used internally by your site code for various operations, and is configured on the <a href="!file-system">File system settings</a> page. You can also see the configured public and private file directories on this page, and choose whether public or private should be the default for uploaded files.', array('!file-system' => \Drupal::url('system.file_system_settings'))) . '</dd>';
$output .= '<dt>' . t('Configuring the image toolkit') . '</dt>';
$output .= '<dd>' . t('On the <a href="!toolkit">Image toolkit page</a>, you can select and configure the PHP toolkit used to manipulate images. Depending on which distribution or installation profile you choose when you install your site, the GD2 toolkit and possibly others are included; other toolkits may be provided by contributed modules.', array('!toolkit' => \Drupal::url('system.image_toolkit_settings'))) . '</dd>';
$output .= '</dl>';
return $output;
case 'system.admin_index':
return '<p>' . t('This page shows you all available administration tasks for each module.') . '</p>';
case 'system.themes_page':
$output = '<p>' . t('Set and configure the default theme for your website. Alternative <a href="!themes">themes</a> are available.', array('!themes' => 'https://www.drupal.org/project/themes')) . '</p>';
if (\Drupal::moduleHandler()->moduleExists('block')) {
$output .= '<p>' . t('You can place blocks for each theme on the <a href="@blocks">block layout</a> page.', array('@blocks' => \Drupal::url('block.admin_display'))) . '</p>';
return '<p>' . t('These options control the display settings for the %name theme. When your site is displayed using this theme, these settings will be used.', array('%name' => $theme->info['name'])) . '</p>';
case 'system.theme_settings':
return '<p>' . t('These options control the default display settings for your entire site, across all themes. Unless they have been overridden by a specific theme, these settings will be used.') . '</p>';
case 'system.modules_list':
$output = '<p>' . t('Download additional <a href="!modules">contributed modules</a> to extend your site\'s functionality.', array('!modules' => 'https://www.drupal.org/project/modules')) . '</p>';
$output .= '<p>' . t('Regularly review available updates to maintain a secure and current site. Always run the <a href="!update-php">update script</a> each time a module is updated. Enable the <a href="!update-manager">Update Manager module</a> to update and install modules and themes.', array('!update-php' => \Drupal::url('system.db_update'), '!update-manager' => \Drupal::url('system.modules_list', [], ['fragment' => 'module-update']))) . '</p>';
return '<p>' . t('The uninstall process removes all data related to a module.') . '</p>';
case 'entity.block.edit_form':
if (($block = $route_match->getParameter('block')) && $block->getPluginId() == 'system_powered_by_block') {
return '<p>' . t('The <em>Powered by Drupal</em> block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') . '</p>';
}
break;
case 'block.admin_add':
if ($route_match->getParameter('plugin_id') == 'system_powered_by_block') {
return '<p>' . t('The <em>Powered by Drupal</em> block is an optional link to the home page of the Drupal project. While there is absolutely no requirement that sites feature this link, it may be used to show support for Drupal.') . '</p>';
}
break;
case 'system.site_maintenance_mode':
if (\Drupal::currentUser()->id() == 1) {
return '<p>' . t('Use maintenance mode when making major updates, particularly if the updates could disrupt visitors or the update process. Examples include upgrading, importing or exporting content, modifying a theme, modifying content types, and making backups.') . '</p>';
}
break;
case 'system.status':
return '<p>' . t("Here you can find a short overview of your site's parameters as well as any problems detected with your installation. It may be useful to copy and paste this information into support requests filed on Drupal.org's support forums and project issue queues. Before filing a support request, ensure that your web server meets the <a href=\"!system-requirements\">system requirements.</a>", array('!system-requirements' => 'https://www.drupal.org/requirements')) . '</p>';
}
}
/**
* Implements hook_theme().
*/
function system_theme() {
return array_merge(drupal_common_theme(), array(
// Normally theme suggestion templates are only picked up when they are in
// themes. We explicitly define theme suggestions here so that the block
// templates in core/modules/system/templates are picked up.
'block__system_branding_block' => array(
'render element' => 'elements',
'base hook' => 'block',
),
'block__system_messages_block' => array(
'base hook' => 'block',
),
'block__system_menu_block' => array(
'render element' => 'elements',
'base hook' => 'block',
),
'system_themes_page' => array(
'variables' => array(
'theme_groups' => array(),
'theme_group_titles' => array(),
),
'file' => 'system.admin.inc',
),
'system_config_form' => array(
'render element' => 'form',
),
'confirm_form' => array(
'render element' => 'form',
),
'system_modules_details' => array(
'render element' => 'form',
'file' => 'system.admin.inc',
'function' => 'theme_system_modules_details',
),
'system_modules_uninstall' => array(
'render element' => 'form',
'file' => 'system.admin.inc',
'function' => 'theme_system_modules_uninstall',
),
'status_report' => array(
'variables' => array('requirements' => NULL),
'file' => 'system.admin.inc',
),
'admin_page' => array(
'variables' => array('blocks' => NULL),
'file' => 'system.admin.inc',
),
'admin_block' => array(
'variables' => array('block' => NULL),
'file' => 'system.admin.inc',
),
'admin_block_content' => array(
'variables' => array('content' => NULL),
'file' => 'system.admin.inc',
),
'system_admin_index' => array(
'variables' => array('menu_items' => NULL),
'file' => 'system.admin.inc',
),
));
}
/**
* Implements hook_hook_info().
*/
function system_hook_info() {
$hooks['token_info'] = array(
'group' => 'tokens',
);
$hooks['token_info_alter'] = array(
'group' => 'tokens',
);
$hooks['tokens'] = array(
'group' => 'tokens',
);
$hooks['tokens_alter'] = array(
'group' => 'tokens',
);
return $hooks;
}
/**
* Implements hook_theme_suggestions_HOOK().
*/
function system_theme_suggestions_html(array $variables) {
if (\Drupal::service('path.matcher')->isFrontPage()) {
function system_check_directory($form_element, FormStateInterface $form_state) {
$directory = $form_element['#value'];
if (strlen($directory) == 0) {
return $form_element;
}
$logger = \Drupal::logger('file system');
if (!is_dir($directory) && !drupal_mkdir($directory, NULL, TRUE)) {
// If the directory does not exists and cannot be created.
$form_state->setErrorByName($form_element['#parents'][0], t('The directory %directory does not exist and could not be created.', array('%directory' => $directory)));
$logger->error('The directory %directory does not exist and could not be created.', array('%directory' => $directory));
}
if (is_dir($directory) && !is_writable($directory) && !drupal_chmod($directory)) {
// If the directory is not writable and cannot be made so.
$form_state->setErrorByName($form_element['#parents'][0], t('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory)));
$logger->error('The directory %directory exists but is not writable and could not be made writable.', array('%directory' => $directory));
}
elseif (is_dir($directory)) {
if ($form_element['#name'] == 'file_public_path') {
// Create public .htaccess file.
file_save_htaccess($directory, FALSE);
}
else {
// Create private .htaccess file.
file_save_htaccess($directory);
}
}
return $form_element;
}
/**
* Returns an array of information about enabled modules or themes.
*
* This function returns the contents of the .info.yml file for each installed
* module or theme.
*
* @param $type
* Either 'module' or 'theme'.
* @param $name
* (optional) The name of a module or theme whose information shall be
* returned. If omitted, all records for the provided $type will be returned.
* If $name does not exist in the provided $type or is not enabled, an empty
* array will be returned.
*
* @return
* An associative array of module or theme information keyed by name, or only
* information for $name, if given. If no records are available, an empty