system.module 72.4 KB
Newer Older
1 2
<?php

3 4 5 6 7
/**
 * @file
 * Configuration system that lets administrators modify the workings of the site.
 */

8 9
use Drupal\Core\Cache\CacheBackendInterface;
use Drupal\Core\Cache\Cache;
10
use Drupal\Core\Language\Language;
11
use Drupal\Core\Extension\ExtensionDiscovery;
12
use Drupal\Core\Utility\ModuleInfo;
13
use Drupal\block\BlockPluginInterface;
14
use Drupal\menu_link\MenuLinkInterface;
15
use Drupal\user\UserInterface;
16
use Symfony\Component\HttpFoundation\JsonResponse;
17
use Symfony\Component\HttpFoundation\RedirectResponse;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\HttpFoundation\Request;
20 21
use Guzzle\Http\Exception\BadResponseException;
use Guzzle\Http\Exception\RequestException;
22

23 24 25
/**
 * Maximum age of temporary files in seconds.
 */
26
const DRUPAL_MAXIMUM_TEMP_FILE_AGE = 21600;
27

28 29 30
/**
 * New users will be set to the default time zone at registration.
 */
31
const DRUPAL_USER_TIMEZONE_DEFAULT = 0;
32 33 34 35

/**
 * New users will get an empty time zone at registration.
 */
36
const DRUPAL_USER_TIMEZONE_EMPTY = 1;
37 38 39 40

/**
 * New users will select their own timezone at registration.
 */
41
const DRUPAL_USER_TIMEZONE_SELECT = 2;
42

43 44 45
 /**
 * Disabled option on forms and settings
 */
46
const DRUPAL_DISABLED = 0;
47 48 49 50

/**
 * Optional option on forms and settings
 */
51
const DRUPAL_OPTIONAL = 1;
52 53 54 55

/**
 * Required option on forms and settings
 */
56
const DRUPAL_REQUIRED = 2;
57

58
/**
59
 * Return only visible regions.
60 61
 *
 * @see system_region_list()
62
 */
63
const REGIONS_VISIBLE = 'visible';
64 65

/**
66
 * Return all regions.
67 68
 *
 * @see system_region_list()
69
 */
70
const REGIONS_ALL = 'all';
71

72 73 74 75 76 77 78 79 80 81 82 83
/**
 * Defines the max length for an email address
 *
 * The maximum length of an e-mail address is 254 characters. RFC 3696
 * specifies a total length of 320 characters, but mentions that
 * addresses longer than 256 characters are not normally useful. Erratum
 * 1690 was then released which corrected this value to 254 characters.
 * @see http://tools.ietf.org/html/rfc3696#section-3
 * @see http://www.rfc-editor.org/errata_search.php?rfc=3696&eid=1690
 */
const EMAIL_MAX_LENGTH = 254;

Dries's avatar
Dries committed
84
/**
85
 * Implements hook_help().
Dries's avatar
Dries committed
86
 */
87
function system_help($path, $arg) {
88 89
  global $base_url;

90
  switch ($path) {
91
    case 'admin/help#system':
92 93
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
94
      $output .= '<p>' . t('The System module is integral to the site, and provides basic but extensible functionality for use by other modules and themes. Some integral elements of Drupal are contained in and managed by the System module, including caching, enabling and disabling modules and themes, preparing and displaying the administrative page, and configuring fundamental site settings. A number of key system maintenance operations are also part of the System module. For more information, see the online handbook entry for <a href="@system">System module</a>.', array('@system' => 'http://drupal.org/documentation/modules/system')) . '</p>';
95 96 97
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Managing modules') . '</dt>';
98
      $output .= '<dd>' . t('The System module allows users with the appropriate permissions to enable and disable modules on the <a href="@modules">Modules administration page</a>. Drupal comes with a number of core modules, and each module provides a discrete set of features and may be enabled or disabled depending on the needs of the site. Many additional modules contributed by members of the Drupal community are available for download at the <a href="@drupal-modules">Drupal.org module page</a>.', array('@modules' => url('admin/modules'), '@drupal-modules' => 'http://drupal.org/project/modules')) . '</dd>';
99 100 101 102 103
      $output .= '<dt>' . t('Managing themes') . '</dt>';
      $output .= '<dd>' . t('The System module allows users with the appropriate permissions to enable and disable themes on the <a href="@themes">Appearance administration page</a>. Themes determine the design and presentation of your site. Drupal comes packaged with several core themes, and additional contributed themes are available at the <a href="@drupal-themes">Drupal.org theme page</a>.', array('@themes' => url('admin/appearance'), '@drupal-themes' => 'http://drupal.org/project/themes')) . '</dd>';
      $output .= '<dt>' . t('Managing caching') . '</dt>';
      $output .= '<dd>' . t("The System module allows users with the appropriate permissions to manage caching on the <a href='@cache-settings'>Performance settings page</a>. Drupal has a robust caching system that allows the efficient re-use of previously-constructed web pages and web page components. Pages requested by anonymous users are stored in a compressed format; depending on your site configuration and the amount of your web traffic tied to anonymous visitors, the caching system may significantly increase the speed of your site.", array('@cache-settings' => url('admin/config/development/performance'))) . '</dd>';
      $output .= '<dt>' . t('Performing system maintenance') . '</dt>';
104
      $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. The System module manages this task by making use of a system cron job. You can verify the status of cron tasks by visiting the <a href="@status">Status report page</a>. For more information, see the online handbook entry for <a href="@handbook">configuring cron jobs</a>. You can set up cron job by visiting <a href="@cron">Cron configuration</a> page', array('@status' => url('admin/reports/status'), '@handbook' => 'http://drupal.org/cron', '@cron' => url('admin/config/system/cron'))) . '</dd>';
105
      $output .= '<dt>' . t('Configuring basic site settings') . '</dt>';
106
      $output .= '<dd>' . t('The System module also handles basic configuration options for your site, including <a href="@date-time-settings">Date and time settings</a>, <a href="@file-system">File system settings</a>, <a href="@site-info">Site name and other information</a>, and a <a href="@maintenance-mode">Maintenance mode</a> for taking your site temporarily offline.', array('@date-time-settings' => url('admin/config/regional/date-time'), '@file-system' => url('admin/config/media/file-system'), '@site-info' => url('admin/config/system/site-information'), '@maintenance-mode' => url('admin/config/development/maintenance'))) . '</dd>';
107
      $output .= '</dl>';
108
      return $output;
109
    case 'admin/index':
110
      return '<p>' . t('This page shows you all available administration tasks for each module.') . '</p>';
111
    case 'admin/appearance':
112
      $output = '<p>' . t('Set and configure the default theme for your website.  Alternative <a href="@themes">themes</a> are available.', array('@themes' => 'http://drupal.org/project/themes')) . '</p>';
113
      return $output;
114
    case 'admin/appearance/settings/' . $arg[3]:
115 116 117
      $theme_list = list_themes();
      $theme = $theme_list[$arg[3]];
      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>';
118
    case 'admin/appearance/settings':
119
      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>';
120
    case 'admin/modules':
121
      $output = '<p>' . t('Download additional <a href="@modules">contributed modules</a> to extend Drupal\'s functionality.', array('@modules' => 'http://drupal.org/project/modules')) . '</p>';
122
      if (\Drupal::moduleHandler()->moduleExists('update')) {
123
        if (update_manager_access()) {
124
          $output .= '<p>' . t('Regularly review and install <a href="@updates">available updates</a> to maintain a secure and current site. Always run the <a href="@update-php">update script</a> each time a module is updated.', array('@update-php' => $base_url . '/core/update.php', '@updates' => url('admin/reports/updates'))) . '</p>';
125 126
        }
        else {
127
          $output .= '<p>' . t('Regularly review <a href="@updates">available updates</a> to maintain a secure and current site. Always run the <a href="@update-php">update script</a> each time a module is updated.', array('@update-php' => $base_url . '/core/update.php', '@updates' => url('admin/reports/updates'))) . '</p>';
128 129 130
        }
      }
      else {
131
        $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 Update Manager module to update and install modules and themes.', array('@update-php' => $base_url . '/core/update.php')) . '</p>';
132
      }
133
      return $output;
134
    case 'admin/modules/uninstall':
135
      return '<p>' . t('The uninstall process removes all data related to a module.') . '</p>';
136
    case 'admin/structure/block/manage':
137
      if ($arg[4] == 'system' && $arg[5] == 'powered-by') {
138
        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>';
139
      }
140
      break;
141
    case 'admin/config/development/maintenance':
142
      if (\Drupal::currentUser()->id() == 1) {
143
        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>';
144
      }
145
      break;
146
    case 'admin/reports/status':
147
      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' => 'http://drupal.org/requirements')) . '</p>';
148
  }
149 150
}

151
/**
152
 * Implements hook_theme().
153
 */
154
function system_theme() {
155
  return array_merge(drupal_common_theme(), array(
156 157 158 159 160 161 162 163
    // Normally theme suggestion templates are only picked up when they are in
    // themes. We explicitly define the block__system_branding_block theme
    // suggestion here so that the template in core/modules/system/templates
    // is picked up.
    'block__system_branding_block' => array(
      'base hook' => 'block',
      'template' => 'block--system-branding-block',
    ),
164
    'system_themes_page' => array(
165 166 167 168
      'variables' => array(
        'theme_groups' => NULL,
        'theme_group_titles' => NULL,
      ),
169
      'file' => 'system.admin.inc',
170
    ),
171
    'system_config_form' => array(
172
      'render element' => 'form',
173 174
    ),
    'confirm_form' => array(
175
      'render element' => 'form',
176
    ),
177
    'system_modules_details' => array(
178
      'render element' => 'form',
179
      'file' => 'system.admin.inc',
180
    ),
181
    'system_modules_incompatible' => array(
182
      'variables' => array('message' => NULL),
183
      'file' => 'system.admin.inc',
184
    ),
185
    'system_modules_uninstall' => array(
186
      'render element' => 'form',
187
      'file' => 'system.admin.inc',
188 189
    ),
    'status_report' => array(
190
      'variables' => array('requirements' => NULL),
191
      'file' => 'system.admin.inc',
192
      'template' => 'status-report',
193 194
    ),
    'admin_page' => array(
195
      'variables' => array('blocks' => NULL),
196
      'file' => 'system.admin.inc',
197 198
    ),
    'admin_block' => array(
199
      'variables' => array('block' => NULL),
200
      'file' => 'system.admin.inc',
201 202
    ),
    'admin_block_content' => array(
203
      'variables' => array('content' => NULL),
204
      'file' => 'system.admin.inc',
205
      'template' => 'admin-block-content',
206
    ),
207
    'system_admin_index' => array(
208
      'variables' => array('menu_items' => NULL),
209
      'file' => 'system.admin.inc',
210
    ),
211 212
    'system_compact_link' => array(
      'variables' => array(),
213
    ),
214 215
  ));
}
216

Dries's avatar
Dries committed
217
/**
218
 * Implements hook_permission().
Dries's avatar
Dries committed
219
 */
220
function system_permission() {
221
  return array(
222 223 224
    'administer modules' => array(
      'title' => t('Administer modules'),
    ),
225 226
    'administer site configuration' => array(
      'title' => t('Administer site configuration'),
227
      'restrict access' => TRUE,
228
    ),
229 230 231
    'administer themes' => array(
      'title' => t('Administer themes'),
    ),
232
    'administer software updates' => array(
233 234
      'title' => t('Administer software updates'),
      'restrict access' => TRUE,
235
    ),
236
    'access administration pages' => array(
237
      'title' => t('Use the administration pages and help'),
238
    ),
239
    'access site in maintenance mode' => array(
240
      'title' => t('Use the site in maintenance mode'),
241
    ),
242 243
    'view the administration theme' => array(
      'title' => t('View the administration theme'),
244
      'description' => t('This is only used when the site is configured to use a separate administration theme on the <a href="@appearance-url">Appearance</a> page.', array('@appearance-url' => url('admin/appearance'))),
245
    ),
246
    'access site reports' => array(
247
      'title' => t('View site reports'),
248
    ),
249
  );
Dries's avatar
Dries committed
250 251
}

252
/**
253
 * Implements hook_hook_info().
254 255 256 257 258
 */
function system_hook_info() {
  $hooks['token_info'] = array(
    'group' => 'tokens',
  );
259 260 261
  $hooks['token_info_alter'] = array(
    'group' => 'tokens',
  );
262 263 264
  $hooks['tokens'] = array(
    'group' => 'tokens',
  );
265 266 267 268
  $hooks['tokens_alter'] = array(
    'group' => 'tokens',
  );

269 270 271
  return $hooks;
}

272
/**
273
 * Implements hook_element_info().
274
 */
275 276 277
function system_element_info() {
  // Top level elements.
  $types['form'] = array(
278 279
    '#method' => 'post',
    '#action' => request_uri(),
280
    '#theme_wrappers' => array('form'),
281
  );
282
  $types['page'] = array(
283 284 285
    '#show_messages' => TRUE,
    '#theme' => 'page',
  );
286
  // By default, we don't want Ajax commands being rendered in the context of an
287 288
  // HTML page, so we don't provide defaults for #theme or #theme_wrappers.
  // However, modules can set these properties (for example, to provide an HTML
289
  // debugging page that displays rather than executes Ajax commands).
290 291 292 293
  $types['ajax'] = array(
    '#header' => TRUE,
    '#commands' => array(),
    '#error' => NULL,
294
  );
295
  $types['html_tag'] = array(
296
    '#pre_render' => array('drupal_pre_render_conditional_comments', 'drupal_pre_render_html_tag'),
297 298 299
    '#attributes' => array(),
    '#value' => NULL,
  );
300 301 302 303
  $types['styles'] = array(
    '#items' => array(),
    '#pre_render' => array('drupal_pre_render_styles'),
  );
304 305 306 307
  $types['scripts'] = array(
    '#items' => array(),
    '#pre_render' => array('drupal_pre_render_scripts'),
  );
308

309 310
  // Input elements.
  $types['submit'] = array(
311 312
    '#input' => TRUE,
    '#name' => 'op',
313
    '#is_button' => TRUE,
314
    '#executes_submit_callback' => TRUE,
315
    '#limit_validation_errors' => FALSE,
316
    '#process' => array('form_process_button', 'ajax_process_form'),
317 318
    '#pre_render' => array('form_pre_render_button'),
    '#theme_wrappers' => array('input__submit'),
319
  );
320
  $types['button'] = array(
321 322
    '#input' => TRUE,
    '#name' => 'op',
323
    '#is_button' => TRUE,
324
    '#executes_submit_callback' => FALSE,
325
    '#limit_validation_errors' => FALSE,
326
    '#process' => array('form_process_button', 'ajax_process_form'),
327 328
    '#pre_render' => array('form_pre_render_button'),
    '#theme_wrappers' => array('input__button'),
329
  );
330
  $types['image_button'] = array(
331
    '#input' => TRUE,
332
    '#is_button' => TRUE,
333
    '#executes_submit_callback' => TRUE,
334
    '#limit_validation_errors' => FALSE,
335
    '#process' => array('form_process_button', 'ajax_process_form'),
336 337 338
    '#return_value' => TRUE,
    '#has_garbage_value' => TRUE,
    '#src' => NULL,
339 340
    '#pre_render' => array('form_pre_render_image_button'),
    '#theme_wrappers' => array('input__image_button'),
341
  );
342
  $types['textfield'] = array(
343 344 345
    '#input' => TRUE,
    '#size' => 60,
    '#maxlength' => 128,
346
    '#autocomplete_route_name' => FALSE,
347 348
    '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern', 'form_process_group'),
    '#pre_render' => array('form_pre_render_textfield', 'form_pre_render_group'),
349
    '#theme' => 'input__textfield',
350
    '#theme_wrappers' => array('form_element'),
351
  );
352 353 354 355
  $types['tel'] = array(
    '#input' => TRUE,
    '#size' => 30,
    '#maxlength' => 128,
356
    '#autocomplete_route_name' => FALSE,
357
    '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'),
358 359
    '#pre_render' => array('form_pre_render_tel'),
    '#theme' => 'input__tel',
360 361
    '#theme_wrappers' => array('form_element'),
  );
362 363 364
  $types['email'] = array(
    '#input' => TRUE,
    '#size' => 60,
365
    '#maxlength' => EMAIL_MAX_LENGTH,
366
    '#autocomplete_route_name' => FALSE,
367
    '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'),
368
    '#element_validate' => array('form_validate_email'),
369 370
    '#pre_render' => array('form_pre_render_email'),
    '#theme' => 'input__email',
371 372
    '#theme_wrappers' => array('form_element'),
  );
373 374 375 376
  $types['url'] = array(
    '#input' => TRUE,
    '#size' => 60,
    '#maxlength' => 255,
377
    '#autocomplete_route_name' => FALSE,
378
    '#process' => array('form_process_autocomplete', 'ajax_process_form', 'form_process_pattern'),
379
    '#element_validate' => array('form_validate_url'),
380 381
    '#pre_render' => array('form_pre_render_url'),
    '#theme' => 'input__url',
382 383
    '#theme_wrappers' => array('form_element'),
  );
384 385 386 387
  $types['search'] = array(
    '#input' => TRUE,
    '#size' => 60,
    '#maxlength' => 128,
388
    '#autocomplete_route_name' => FALSE,
389
    '#process' => array('form_process_autocomplete', 'ajax_process_form'),
390 391
    '#pre_render' => array('form_pre_render_search'),
    '#theme' => 'input__search',
392 393
    '#theme_wrappers' => array('form_element'),
  );
394 395 396 397 398
  $types['number'] = array(
    '#input' => TRUE,
    '#step' => 1,
    '#process' => array('ajax_process_form'),
    '#element_validate' => array('form_validate_number'),
399 400
    '#pre_render' => array('form_pre_render_number'),
    '#theme' => 'input__number',
401 402
    '#theme_wrappers' => array('form_element'),
  );
403 404 405 406 407 408 409
  $types['range'] = array(
    '#input' => TRUE,
    '#step' => 1,
    '#min' => 0,
    '#max' => 100,
    '#process' => array('ajax_process_form'),
    '#element_validate' => array('form_validate_number'),
410 411
    '#pre_render' => array('form_pre_render_range'),
    '#theme' => 'input__range',
412 413
    '#theme_wrappers' => array('form_element'),
  );
414 415 416 417
  $types['color'] = array(
    '#input' => TRUE,
    '#process' => array('ajax_process_form'),
    '#element_validate' => array('form_validate_color'),
418 419
    '#pre_render' => array('form_pre_render_color'),
    '#theme' => 'input__color',
420 421
    '#theme_wrappers' => array('form_element'),
  );
422 423 424 425 426 427
  $types['machine_name'] = array(
    '#input' => TRUE,
    '#default_value' => NULL,
    '#required' => TRUE,
    '#maxlength' => 64,
    '#size' => 60,
428
    '#autocomplete_route_name' => FALSE,
429
    '#process' => array('form_process_machine_name', 'form_process_autocomplete', 'ajax_process_form'),
430
    '#element_validate' => array('form_validate_machine_name'),
431 432
    '#pre_render' => array('form_pre_render_textfield'),
    '#theme' => 'input__textfield',
433 434
    '#theme_wrappers' => array('form_element'),
  );
435
  $types['password'] = array(
436 437 438
    '#input' => TRUE,
    '#size' => 60,
    '#maxlength' => 128,
439
    '#process' => array('ajax_process_form', 'form_process_pattern'),
440 441
    '#pre_render' => array('form_pre_render_password'),
    '#theme' => 'input__password',
442
    '#theme_wrappers' => array('form_element'),
443
  );
444
  $types['password_confirm'] = array(
445
    '#input' => TRUE,
446
    '#process' => array('form_process_password_confirm', 'user_form_process_password_confirm'),
447
    '#theme_wrappers' => array('form_element'),
448
  );
449
  $types['textarea'] = array(
450 451 452
    '#input' => TRUE,
    '#cols' => 60,
    '#rows' => 5,
453
    '#resizable' => 'vertical',
454 455
    '#process' => array('ajax_process_form', 'form_process_group'),
    '#pre_render' => array('form_pre_render_group'),
456
    '#theme' => 'textarea',
457
    '#theme_wrappers' => array('form_element'),
458
  );
459
  $types['radios'] = array(
460
    '#input' => TRUE,
461
    '#process' => array('form_process_radios'),
462
    '#theme_wrappers' => array('radios'),
463
    '#pre_render' => array('form_pre_render_conditional_form_element'),
464
  );
465
  $types['radio'] = array(
466 467
    '#input' => TRUE,
    '#default_value' => NULL,
468
    '#process' => array('ajax_process_form'),
469 470
    '#pre_render' => array('form_pre_render_radio'),
    '#theme' => 'input__radio',
471
    '#theme_wrappers' => array('form_element'),
472
    '#title_display' => 'after',
473
  );
474
  $types['checkboxes'] = array(
475
    '#input' => TRUE,
476
    '#process' => array('form_process_checkboxes'),
477
    '#pre_render' => array('form_pre_render_conditional_form_element'),
478
    '#theme_wrappers' => array('checkboxes'),
479
  );
480
  $types['checkbox'] = array(
481 482
    '#input' => TRUE,
    '#return_value' => 1,
483 484
    '#process' => array('form_process_checkbox', 'ajax_process_form', 'form_process_group'),
    '#pre_render' => array('form_pre_render_checkbox', 'form_pre_render_group'),
485
    '#theme' => 'input__checkbox',
486
    '#theme_wrappers' => array('form_element'),
487
    '#title_display' => 'after',
488
  );
489
  $types['select'] = array(
490 491
    '#input' => TRUE,
    '#multiple' => FALSE,
492
    '#process' => array('form_process_select', 'ajax_process_form'),
493
    '#theme' => 'select',
494
    '#theme_wrappers' => array('form_element'),
495
    '#options' => array(),
496
  );
497 498
  $types['language_select'] = array(
    '#input' => TRUE,
499
    '#default_value' => Language::LANGCODE_NOT_SPECIFIED,
500
  );
501
  $types['weight'] = array(
502 503 504
    '#input' => TRUE,
    '#delta' => 10,
    '#default_value' => 0,
505
    '#process' => array('form_process_weight', 'ajax_process_form'),
506
  );
507
  $types['date'] = array(
508
    '#input' => TRUE,
509
    '#theme' => 'date',
510
    '#theme_wrappers' => array('form_element'),
511
  );
512
  $types['file'] = array(
513
    '#input' => TRUE,
514 515
    '#multiple' => FALSE,
    '#process' => array('form_process_file'),
516
    '#size' => 60,
517 518
    '#pre_render' => array('form_pre_render_file'),
    '#theme' => 'input__file',
519
    '#theme_wrappers' => array('form_element'),
520
  );
521
  $types['tableselect'] = array(
522 523 524 525 526 527
    '#input' => TRUE,
    '#js_select' => TRUE,
    '#multiple' => TRUE,
    '#process' => array('form_process_tableselect'),
    '#options' => array(),
    '#empty' => '',
528
    '#theme' => 'tableselect',
529
  );
530

531
  // Form structure.
532 533 534
  $types['label'] = array(
    '#theme' => 'form_element_label',
  );
535
  $types['item'] = array(
536 537 538 539 540 541
    // Forms that show author fields to both anonymous and authenticated users
    // need to dynamically switch between #type 'textfield' and #type 'item' to
    // automatically take over the authenticated user's information. Therefore,
    // we allow #type 'item' to receive input, which is internally assigned by
    // Form API based on the #default_value or #value properties.
    '#input' => TRUE,
542
    '#markup' => '',
543
    '#theme_wrappers' => array('form_element'),
544
  );
545
  $types['hidden'] = array(
546
    '#input' => TRUE,
547
    '#process' => array('ajax_process_form'),
548 549 550 551 552 553 554
    '#pre_render' => array('form_pre_render_hidden'),
    '#theme' => 'input__hidden',
  );
  $types['token'] = array(
    '#input' => TRUE,
    '#pre_render' => array('form_pre_render_hidden'),
    '#theme' => 'input__hidden',
555
  );
556
  $types['value'] = array(
557 558
    '#input' => TRUE,
  );
559
  $types['link'] = array(
560
    '#pre_render' => array('drupal_pre_render_link'),
561
  );
562
  $types['fieldset'] = array(
563
    '#value' => NULL,
564 565
    '#process' => array('form_process_group', 'ajax_process_form'),
    '#pre_render' => array('form_pre_render_group'),
566 567
    '#theme_wrappers' => array('fieldset'),
  );
568 569 570
  $types['fieldgroup'] = $types['fieldset'] + array(
    '#attributes' => array('class' => array('fieldgroup')),
  );
571
  $types['details'] = array(
572
    '#open' => FALSE,
573
    '#value' => NULL,
574 575
    '#process' => array('form_process_group', 'ajax_process_form'),
    '#pre_render' => array('form_pre_render_details', 'form_pre_render_group'),
576
    '#theme_wrappers' => array('details'),
577
  );
578
  $types['vertical_tabs'] = array(
579 580
    '#default_tab' => '',
    '#process' => array('form_process_vertical_tabs'),
581 582
    '#pre_render' => array('form_pre_render_vertical_tabs'),
    '#theme_wrappers' => array('vertical_tabs', 'form_element'),
583
  );
584 585
  $types['dropbutton'] = array(
    '#pre_render' => array('drupal_pre_render_dropbutton'),
586
    '#theme' => 'links__dropbutton',
587 588 589
  );
  $types['operations'] = array(
    '#pre_render' => array('drupal_pre_render_dropbutton'),
590
    '#theme' => 'links__dropbutton__operations',
591
  );
592 593

  $types['container'] = array(
594 595
    '#process' => array('form_process_group', 'form_process_container'),
    '#pre_render' => array('form_pre_render_group'),
596
    '#theme_wrappers' => array('container'),
597
  );
598
  $types['actions'] = array(
599
    '#process' => array('form_pre_render_actions_dropbutton', 'form_process_actions', 'form_process_container'),
600
    '#weight' => 100,
601
    '#theme_wrappers' => array('container'),
602 603
  );

604 605 606 607 608 609 610 611 612 613 614 615 616 617
  $types['table'] = array(
    '#header' => array(),
    '#rows' => array(),
    '#empty' => '',
    // Properties for tableselect support.
    '#input' => TRUE,
    '#tree' => TRUE,
    '#tableselect' => FALSE,
    '#multiple' => TRUE,
    '#js_select' => TRUE,
    '#value_callback' => 'form_type_table_value',
    '#process' => array('form_process_table'),
    '#element_validate' => array('form_validate_table'),
    // Properties for tabledrag support.
618 619 620 621
    // The value is a list of arrays that are passed to
    // drupal_attach_tabledrag(). drupal_pre_render_table() prepends the HTML ID
    // of the table to each set of options.
    // @see drupal_attach_tabledrag()
622 623 624 625 626 627
    '#tabledrag' => array(),
    // Render properties.
    '#pre_render' => array('drupal_pre_render_table'),
    '#theme' => 'table',
  );

628 629 630 631 632 633
  // Other elements.
  $types['render_cache_placeholder'] = array(
    '#callback' => '',
    '#context' => array(),
  );

634
  return $types;
635 636
}

637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659
/**
 * Implements hook_menu_link_defaults().
 */
function system_menu_link_defaults() {
  $items['system.admin'] = array(
    'link_title' => 'Administration',
    'route_name' => 'system.admin',
    'weight' => 9,
    'menu_name' => 'admin',
  );

  // Menu items that are basically just menu blocks.
  $items['system.admin.structure'] = array(
    'route_name' => 'system.admin_structure',
    'parent' => 'system.admin',
    'description' => 'Administer blocks, content types, menus, etc.',
    'link_title' => 'Structure',
    'weight' => -8,
  );
  // Appearance.
  $items['system.admin.appearance'] = array(
    'route_name' => 'system.themes_page',
    'link_title' => 'Appearance',
660
    'description' => 'Select and configure your themes.',
661 662 663 664 665 666
    'parent' => 'system.admin',
    'weight' => -6,
  );
  // Modules.
  $items['system.admin.modules'] = array(
    'link_title' => 'Extend',
667
    'description' => 'Add and enable modules to extend site functionality.',
668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
    'parent' => 'system.admin',
    'route_name' => 'system.modules_list',
    'weight' => -2,
  );
  // Configuration.
  $items['system.admin.config'] = array(
    'link_title' => 'Configuration',
    'parent' => 'system.admin',
    'description' => 'Administer settings.',
    'route_name' => 'system.admin_config',
    'weight' => 0,
  );

  // Media settings.
  $items['system.admin.config.media'] = array(
    'route_name' => 'system.admin_config_media',
    'parent' => 'system.admin.config',
    'link_title' => 'Media',
    'weight' => -10,
  );
  $items['system.admin.config.media.file-system'] = array(
    'link_title' => 'File system',
    'description' => 'Tell Drupal where to store uploaded files and how they are accessed.',
    'parent' => 'system.admin.config.media',
    'route_name' => 'system.file_system_settings',
  );
  $items['system.admin.config.media.image-toolkit'] = array(
    'link_title' => 'Image toolkit',
    'parent' => 'system.admin.config.media',
    'route_name' => 'system.image_toolkit_settings',
    'description' => 'Choose which image toolkit to use if you have installed optional toolkits.',
    'weight' => 20,
  );

  // Service settings.
  $items['system.admin.config.services'] = array(
    'link_title' => 'Web services',
    'parent' => 'system.admin.config',
    'route_name' => 'system.admin_config_services',
  );
  $items['system.admin.config.services.rss-publishing'] = array(
    'link_title' => 'RSS publishing',
    'parent' => 'system.admin.config.services',
    'description' => 'Configure the site description, the number of items per feed and whether feeds should be titles/teasers/full-text.',
    'route_name' => 'system.rss_feeds_settings',
  );

  // Development settings.
  $items['system.admin.config.development'] = array(
    'route_name' => 'system.admin_config_development',
    'parent' => 'system.admin.config',
    'link_title' => 'Development',
    'description' => 'Development tools.',
    'weight' => -10,
  );
  $items['system.admin.config.development.maintenance'] = array(
    'link_title' => 'Maintenance mode',
    'parent' => 'system.admin.config.development',
    'description' => 'Take the site offline for maintenance or bring it back online.',
    'route_name' => 'system.site_maintenance_mode',
    'weight' => -10,
  );
  $items['system.admin.config.development.performance'] = array(
    'link_title' => 'Performance',
    'parent' => 'system.admin.config.development',
    'description' => 'Enable or disable page caching for anonymous users and set CSS and JS bandwidth optimization options.',
    'route_name' => 'system.performance_settings',
    'weight' => -20,
  );
  $items['system.admin.config.development.logging'] = array(
    'link_title' => 'Logging and errors',
    'parent' => 'system.admin.config.development',
    'description' => "Settings for logging and alerts modules. Various modules can route Drupal's system events to different destinations, such as syslog, database, email, etc.",
    'route_name' => 'system.logging_settings',
    'weight' => -15,
  );

  // Regional and date settings.
  $items['system.admin.config.regional'] = array(
    'route_name' => 'system.admin_config_regional',
    'link_title' => 'Regional and language',
    'parent' => 'system.admin.config',
    'description' => 'Regional settings, localization and translation.',
    'weight' => -5,
  );
  $items['system.admin.config.regional.settings'] = array(
    'link_title' => 'Regional settings',
    'parent' => 'system.admin.config.regional',
    'description' => "Settings for the site's default time zone and country.",
    'route_name' => 'system.regional_settings',
    'weight' => -20,
  );
  $items['system.admin.config.regional.date-time'] = array(
    'link_title' => 'Date and time formats',
    'parent' => 'system.admin.config.regional',
    'description' => 'Configure display format strings for date and time.',
    'route_name' => 'system.date_format_list',
    'weight' => -9,
  );

  // Search settings.
  $items['system.admin.config.search'] = array(
    'link_title' => 'Search and metadata',
    'route_name' => 'system.admin_config_search',
    'parent' => 'system.admin.config',
    'description' => 'Local site search, metadata and SEO.',
    'weight' => -10,
  );

  // System settings.
  $items['system.admin.config.system'] = array(
    'link_title' => 'System',
    'route_name' => 'system.admin_config_system',
    'parent' => 'system.admin.config',
    'description' => 'General system related configuration.',
    'weight' => -20,
  );
  $items['system.admin.config.system.site-information'] = array(
    'link_title' => 'Site information',
    'parent' => 'system.admin.config.system',
    'description' => 'Change site name, e-mail address, slogan, default front page, and number of posts per page, error pages.',
    'route_name' => 'system.site_information_settings',
    'weight' => -20,
  );
  $items['system.admin.config.system.cron'] = array(
    'link_title' => 'Cron',
    'parent' => 'system.admin.config.system',
    'description' => 'Manage automatic site maintenance tasks.',
    'route_name' => 'system.cron_settings',
    'weight' => 20,
  );
  // Additional categories
  $items['system.admin.config.user-interface'] = array(
    'link_title' => 'User interface',
    'route_name' => 'system.admin_config_ui',
    'parent' => 'system.admin.config',
    'description' => 'Tools that enhance the user interface.',
    'weight' => -15,
  );
  $items['system.admin.config.workflow'] = array(
    'link_title' => 'Workflow',
    'route_name' => 'system.admin_config_workflow',
    'parent' => 'system.admin.config',
    'description' => 'Content workflow, editorial workflow tools.',
    'weight' => 5,
  );
  $items['system.admin.config.content'] = array(
    'link_title' => 'Content authoring',
    'route_name' => 'system.admin_config_content',
    'parent' => 'system.admin.config',
    'description' => 'Settings related to formatting and authoring content.',
    'weight' => -15,
  );

  // Reports.
  $items['system.admin.reports'] = array(
    'link_title' => 'Reports',
    'route_name' => 'system.admin_reports',
    'parent' => 'system.admin',
    'description' => 'View reports, updates, and errors.',
    'weight' => 5,
  );
  $items['system.admin.reports.status'] = array(
    'link_title' => 'Status report',
    'parent' => 'system.admin.reports',
    'description' => "Get a status report about your site's operation and any detected problems.",
    'route_name' => 'system.status',
  );

  return $items;
}

840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887
/**
 * Implements hook_theme_suggestions_HOOK().
 */
function system_theme_suggestions_html(array $variables) {
  return theme_get_suggestions(arg(), 'html');
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function system_theme_suggestions_page(array $variables) {
  return theme_get_suggestions(arg(), 'page');
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function system_theme_suggestions_maintenance_page(array $variables) {
  $suggestions = array();

  // Dead databases will show error messages so supplying this template will
  // allow themers to override the page and the content completely.
  $offline = defined('MAINTENANCE_MODE');
  try {
    drupal_is_front_page();
  }
  catch (Exception $e) {
    // The database is not yet available.
    $offline = TRUE;
  }
  if ($offline) {
    $suggestions[] = 'maintenance_page__offline';
  }

  return $suggestions;
}

/**
 * Implements hook_theme_suggestions_HOOK().
 */
function system_theme_suggestions_region(array $variables) {
  $suggestions = array();
  if (!empty($variables['elements']['#region'])) {
    $suggestions[] = 'region__' . $variables['elements']['#region'];
  }
  return $suggestions;
}

888
/**
889
 * Implements hook_stream_wrappers().
890 891
 */
function system_stream_wrappers() {
892
  $wrappers = array(
893 894
    'public' => array(
      'name' => t('Public files'),
webchick's avatar
webchick committed
895
      'class' => 'Drupal\Core\StreamWrapper\PublicStream',
896
      'description' => t('Public local files served by the webserver.'),
897
      'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
898 899 900
    ),
    'temporary' => array(
      'name' => t('Temporary files'),
webchick's avatar
webchick committed
901
      'class' => 'Drupal\Core\StreamWrapper\TemporaryStream',
902
      'description' => t('Temporary local files for upload and previews.'),
903
      'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
904
    ),
905
  );
906 907

  // Only register the private file stream wrapper if a file path has been set.
908
  if (\Drupal::config('system.file')->get('path.private')) {
909 910
    $wrappers['private'] = array(
      'name' => t('Private files'),
webchick's avatar
webchick committed
911
      'class' => 'Drupal\Core\StreamWrapper\PrivateStream',
912
      'description' => t('Private local files served by Drupal.'),
913
      'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
914 915 916 917
    );
  }

  return $wrappers;
918 919
}

920
/**
921
 * Menu item access callback - only enabled themes can be accessed.
922 923
 */
function _system_themes_access($theme) {
924
  return user_access('administer themes') && drupal_theme_access($theme);
925 926
}

927
/**
928 929 930
 * @defgroup authorize Authorized operations
 * @{
 * Functions to run operations with elevated privileges via authorize.php.
931
 *
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951
 * Because of the Update manager functionality included in Drupal core, there
 * is a mechanism for running operations with elevated file system privileges,
 * the top-level authorize.php script. This script runs at a reduced Drupal
 * bootstrap level so that it is not reliant on the entire site being
 * functional. The operations use a FileTransfer class to manipulate code
 * installed on the system as the user that owns the files, not the user that
 * the httpd is running as.
 *
 * The first setup is to define a callback function that should be authorized
 * to run with the elevated privileges. This callback should take a
 * FileTransfer as its first argument, although you can define an array of
 * other arguments it should be invoked with. The callback should be placed in
 * a separate .inc file that will be included by authorize.php.
 *
 * To run the operation, certain data must be saved into the SESSION, and then
 * the flow of control should be redirected to the authorize.php script. There
 * are two ways to do this, either to call system_authorized_run() directly,
 * or to call system_authorized_init() and then redirect to authorize.php,
 * using the URL from system_authorized_get_url(). Redirecting yourself is
 * necessary when your authorized operation is being triggered by a form
952
 * submit handler, since calling redirecting in a submit handler is a bad
953 954 955 956 957 958 959 960 961 962 963
 * idea, and you should instead set $form_state['redirect'].
 *
 * Once the SESSION is setup for the operation and the user is redirected to
 * authorize.php, they will be prompted for their connection credentials (core
 * provides FTP and SSH by default, although other connection classes can be
 * added via contributed modules). With valid credentials, authorize.php will
 * instantiate the appropriate FileTransfer object, and then invoke the
 * desired operation passing in that object. The authorize.php script can act
 * as a Batch API processing page, if the operation requires a batch.
 *
 * @see authorize.php
964
 * @see \Drupal\Core\FileTransfer\FileTransfer
965
 * @see hook_filetransfer_info()
966 967 968 969 970
 */

/**
 * Setup a given callback to run via authorize.php with elevated privileges.
 *
971 972 973 974 975 976 977 978 979
 * To use authorize.php, certain variables must be stashed into $_SESSION. This
 * function sets up all the necessary $_SESSION variables. The calling function
 * should then redirect to authorize.php, using the full path returned by
 * system_authorized_get_url(). That initiates the workflow that will eventually
 * lead to the callback being invoked. The callback will be invoked at a low
 * bootstrap level, without all modules being invoked, so it needs to be careful
 * not to assume any code exists. Example (system_authorized_run()):
 * @code
 *   system_authorized_init($callback, $file, $arguments, $page_title);
980
 *   return new RedirectResponse(system_authorized_get_url());
981 982 983 984 985 986 987 988
 * @endcode
 * Example (update_manager_install_form_submit()):
 * @code
 *  system_authorized_init('update_authorize_run_install',
 *    drupal_get_path('module', 'update') . '/update.authorize.inc',
 *    $arguments, t('Update manager'));
 *  $form_state['redirect'] = system_authorized_get_url();
 * @endcode
989 990
 *
 * @param $callback
991
 *   The name of the function to invoke once the user authorizes the operation.
992 993 994 995 996 997 998 999 1000
 * @param $file
 *   The full path to the file where the callback function is implemented.
 * @param $arguments
 *   Optional array of arguments to pass into the callback when it is invoked.
 *   Note that the first argument to the callback is always the FileTransfer
 *   object created by authorize.php when the user authorizes the operation.
 * @param $page_title