system.module 63.1 KB
Newer Older
Dries's avatar
 
Dries committed
1 2
<?php

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

8
use Drupal\Core\Cache\Cache;
9
use Drupal\Core\Language\Language;
10
use Drupal\Core\Extension\Extension;
11
use Drupal\Core\Extension\ExtensionDiscovery;
12
use Drupal\block\BlockPluginInterface;
13
use Drupal\user\UserInterface;
14
use Symfony\Component\HttpFoundation\RedirectResponse;
15
use GuzzleHttp\Exception\RequestException;
16
use Symfony\Component\HttpFoundation\Request;
17

18 19 20
/**
 * New users will be set to the default time zone at registration.
 */
21
const DRUPAL_USER_TIMEZONE_DEFAULT = 0;
22 23 24 25

/**
 * New users will get an empty time zone at registration.
 */
26
const DRUPAL_USER_TIMEZONE_EMPTY = 1;
27 28 29 30

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

33
/**
34 35
 * Disabled option on forms and settings
 */
36
const DRUPAL_DISABLED = 0;
37 38 39 40

/**
 * Optional option on forms and settings
 */
41
const DRUPAL_OPTIONAL = 1;
42 43 44 45

/**
 * Required option on forms and settings
 */
46
const DRUPAL_REQUIRED = 2;
47

48
/**
49
 * Return only visible regions.
50 51
 *
 * @see system_region_list()
52
 */
53
const REGIONS_VISIBLE = 'visible';
54 55

/**
56
 * Return all regions.
57 58
 *
 * @see system_region_list()
59
 */
60
const REGIONS_ALL = 'all';
61

62 63 64 65 66 67 68 69 70 71 72 73
/**
 * 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
74
/**
75
 * Implements hook_help().
Dries's avatar
 
Dries committed
76
 */
77
function system_help($route_name, Request $request) {
78 79
  global $base_url;

80 81
  switch ($route_name) {
    case 'help.page.system':
82 83
      $output = '';
      $output .= '<h3>' . t('About') . '</h3>';
84
      $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>';
85 86 87
      $output .= '<h3>' . t('Uses') . '</h3>';
      $output .= '<dl>';
      $output .= '<dt>' . t('Managing modules') . '</dt>';
88
      $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>';
89 90 91 92 93
      $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>';
94
      $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>';
95
      $output .= '<dt>' . t('Configuring basic site settings') . '</dt>';
96
      $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>';
97
      $output .= '</dl>';
98
      return $output;
99 100

    case 'system.admin_index':
101
      return '<p>' . t('This page shows you all available administration tasks for each module.') . '</p>';
102 103

    case 'system.themes_page':
104
      $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>';
105
      return $output;
106 107

    case 'system.theme_settings_theme':
108
      $theme_list = list_themes();
109
      $theme = $theme_list[$request->attributes->get('theme')];
110
      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>';
111 112

    case 'system.theme_settings':
113
      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>';
114 115

    case 'system.modules_list':
116
      $output = '<p>' . t('Download additional <a href="@modules">contributed modules</a> to extend Drupal\'s functionality.', array('@modules' => 'http://drupal.org/project/modules')) . '</p>';
117
      if (\Drupal::moduleHandler()->moduleExists('update')) {
118
        if (update_manager_access()) {
119
          $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>';
120 121
        }
        else {
122
          $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>';
123 124 125
        }
      }
      else {
126
        $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>';
127
      }
128
      return $output;
129 130

    case 'system.modules_uninstall':
131
      return '<p>' . t('The uninstall process removes all data related to a module.') . '</p>';
132 133 134

    case 'block.admin_edit':
      if (($block = $request->attributes->get('block')) && $block->get('plugin') == 'system_powered_by_block') {
135
        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>';
136
      }
137
      break;
138 139 140 141 142 143 144 145

    case 'block.admin_add':
      if ($request->attributes->get('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':
146
      if (\Drupal::currentUser()->id() == 1) {
147
        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>';
148
      }
149
      break;
150 151

    case 'system.status':
152
      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>';
153
  }
Dries's avatar
 
Dries committed
154 155
}

156
/**
157
 * Implements hook_theme().
158
 */
159
function system_theme() {
160
  return array_merge(drupal_common_theme(), array(
161 162 163 164 165 166 167 168
    // 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',
    ),
169
    'system_themes_page' => array(
170
      'variables' => array(
171 172
        'theme_groups' => array(),
        'theme_group_titles' => array(),
173
      ),
174
      'file' => 'system.admin.inc',
175
      'template' => 'system-themes-page',
176
    ),
177
    'system_config_form' => array(
178
      'render element' => 'form',
179 180
    ),
    'confirm_form' => array(
181
      'render element' => 'form',
182
      'template' => 'confirm-form',
183
    ),
184
    'system_modules_details' => array(
185
      'render element' => 'form',
186
      'file' => 'system.admin.inc',
187 188
    ),
    'system_modules_uninstall' => array(
189
      'render element' => 'form',
190
      'file' => 'system.admin.inc',
191 192
    ),
    'status_report' => array(
193
      'variables' => array('requirements' => NULL),
194
      'file' => 'system.admin.inc',
195
      'template' => 'status-report',
196 197
    ),
    'admin_page' => array(
198
      'variables' => array('blocks' => NULL),
199
      'file' => 'system.admin.inc',
200
      'template' => 'admin-page',
201 202
    ),
    'admin_block' => array(
203
      'variables' => array('block' => NULL),
204
      'file' => 'system.admin.inc',
205
      'template' => 'admin-block',
206 207
    ),
    'admin_block_content' => array(
208
      'variables' => array('content' => NULL),
209
      'file' => 'system.admin.inc',
210
      'template' => 'admin-block-content',
211
    ),
212
    'system_admin_index' => array(
213
      'variables' => array('menu_items' => NULL),
214
      'file' => 'system.admin.inc',
215
      'template' => 'system-admin-index',
216
    ),
217 218
    'system_compact_link' => array(
      'variables' => array(),
219
    ),
220 221
  ));
}
222

Dries's avatar
 
Dries committed
223
/**
224
 * Implements hook_permission().
Dries's avatar
 
Dries committed
225
 */
226
function system_permission() {
227
  return array(
228 229 230
    'administer modules' => array(
      'title' => t('Administer modules'),
    ),
231 232
    'administer site configuration' => array(
      'title' => t('Administer site configuration'),
233
      'restrict access' => TRUE,
234
    ),
235 236 237
    'administer themes' => array(
      'title' => t('Administer themes'),
    ),
238
    'administer software updates' => array(
239 240
      'title' => t('Administer software updates'),
      'restrict access' => TRUE,
241
    ),
242
    'access administration pages' => array(
243
      'title' => t('Use the administration pages and help'),
244
    ),
245
    'access site in maintenance mode' => array(
246
      'title' => t('Use the site in maintenance mode'),
247
    ),
248 249
    'view the administration theme' => array(
      'title' => t('View the administration theme'),
250
      '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'))),
251
    ),
252
    'access site reports' => array(
253
      'title' => t('View site reports'),
254
      'restrict access' => TRUE,
255
    ),
256
  );
Dries's avatar
 
Dries committed
257 258
}

259
/**
260
 * Implements hook_hook_info().
261 262 263 264 265
 */
function system_hook_info() {
  $hooks['token_info'] = array(
    'group' => 'tokens',
  );
266 267 268
  $hooks['token_info_alter'] = array(
    'group' => 'tokens',
  );
269 270 271
  $hooks['tokens'] = array(
    'group' => 'tokens',
  );
272 273 274 275
  $hooks['tokens_alter'] = array(
    'group' => 'tokens',
  );

276 277 278
  return $hooks;
}

279
/**
280
 * Implements hook_element_info().
281
 */
282 283
function system_element_info() {
  // Top level elements.
284 285 286 287 288 289 290 291
  $types['html'] = array(
    '#theme' => 'html',
    '#pre_render' => array('drupal_pre_render_html'),
    // HTML5 Shiv
    '#attached' => array(
      'library' => array('core/html5shiv'),
    ),
  );
292
  $types['form'] = array(
293 294
    '#method' => 'post',
    '#action' => request_uri(),
295
    '#theme_wrappers' => array('form'),
296
  );
297
  $types['page'] = array(
298
    '#show_messages' => TRUE,
299
    '#pre_render' => array('drupal_pre_render_page'),
300
    '#theme' => 'page',
301
    '#title' => '',
302
  );
303
  // By default, we don't want Ajax commands being rendered in the context of an
304 305
  // 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
306
  // debugging page that displays rather than executes Ajax commands).
307 308 309 310
  $types['ajax'] = array(
    '#header' => TRUE,
    '#commands' => array(),
    '#error' => NULL,
311
  );
312
  $types['html_tag'] = array(
313
    '#pre_render' => array('drupal_pre_render_conditional_comments', 'drupal_pre_render_html_tag'),
314 315 316
    '#attributes' => array(),
    '#value' => NULL,
  );
317 318 319 320
  $types['styles'] = array(
    '#items' => array(),
    '#pre_render' => array('drupal_pre_render_styles'),
  );
321 322 323 324
  $types['scripts'] = array(
    '#items' => array(),
    '#pre_render' => array('drupal_pre_render_scripts'),
  );
325

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

548
  // Form structure.
549 550 551
  $types['label'] = array(
    '#theme' => 'form_element_label',
  );
552
  $types['item'] = array(
553 554 555 556 557 558
    // 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,
559
    '#markup' => '',
560
    '#theme_wrappers' => array('form_element'),
561
  );
562
  $types['hidden'] = array(
563
    '#input' => TRUE,
564
    '#process' => array('ajax_process_form'),
565 566 567 568 569 570 571
    '#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',
572
  );
573
  $types['value'] = array(
574 575
    '#input' => TRUE,
  );
576
  $types['link'] = array(
577
    '#pre_render' => array('drupal_pre_render_link'),
578
  );
579
  $types['fieldset'] = array(
580
    '#value' => NULL,
581 582
    '#process' => array('form_process_group', 'ajax_process_form'),
    '#pre_render' => array('form_pre_render_group'),
583 584
    '#theme_wrappers' => array('fieldset'),
  );
585 586 587
  $types['fieldgroup'] = $types['fieldset'] + array(
    '#attributes' => array('class' => array('fieldgroup')),
  );
588
  $types['details'] = array(
589
    '#open' => FALSE,
590
    '#value' => NULL,
591 592
    '#process' => array('form_process_group', 'ajax_process_form'),
    '#pre_render' => array('form_pre_render_details', 'form_pre_render_group'),
593
    '#theme_wrappers' => array('details'),
594
  );
595
  $types['vertical_tabs'] = array(
596 597
    '#default_tab' => '',
    '#process' => array('form_process_vertical_tabs'),
598 599
    '#pre_render' => array('form_pre_render_vertical_tabs'),
    '#theme_wrappers' => array('vertical_tabs', 'form_element'),
600
  );
601 602
  $types['dropbutton'] = array(
    '#pre_render' => array('drupal_pre_render_dropbutton'),
603
    '#theme' => 'links__dropbutton',
604 605 606
  );
  $types['operations'] = array(
    '#pre_render' => array('drupal_pre_render_dropbutton'),
607
    '#theme' => 'links__dropbutton__operations',
608
  );
609 610

  $types['container'] = array(
611 612
    '#process' => array('form_process_group', 'form_process_container'),
    '#pre_render' => array('form_pre_render_group'),
613
    '#theme_wrappers' => array('container'),
614
  );
615
  $types['actions'] = array(
616
    '#process' => array('form_pre_render_actions_dropbutton', 'form_process_actions', 'form_process_container'),
617
    '#weight' => 100,
618
    '#theme_wrappers' => array('container'),
619 620
  );

621 622 623 624 625 626 627 628
  $types['table'] = array(
    '#header' => array(),
    '#rows' => array(),
    '#empty' => '',
    // Properties for tableselect support.
    '#input' => TRUE,
    '#tree' => TRUE,
    '#tableselect' => FALSE,
629 630
    '#sticky' => FALSE,
    '#responsive' => TRUE,
631 632 633 634 635 636
    '#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.
637 638 639 640
    // 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()
641 642 643 644 645 646
    '#tabledrag' => array(),
    // Render properties.
    '#pre_render' => array('drupal_pre_render_table'),
    '#theme' => 'table',
  );

647
  return $types;
648 649
}

650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 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
/**
 * 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;
}

698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
/**
 * Implements hook_theme_suggestions_HOOK().
 */
function system_theme_suggestions_field(array $variables) {
  $suggestions = array();
  $element = $variables['element'];

  $suggestions[] = 'field__' . $element['#field_type'];
  $suggestions[] = 'field__' . $element['#field_name'];
  $suggestions[] = 'field__' . $element['#entity_type'] . '__' . $element['#bundle'];
  $suggestions[] = 'field__' . $element['#entity_type'] . '__' . $element['#field_name'];
  $suggestions[] = 'field__' . $element['#entity_type'] . '__' . $element['#field_name'] . '__' . $element['#bundle'];

  return $suggestions;
}

714
/**
715
 * Implements hook_stream_wrappers().
716 717
 */
function system_stream_wrappers() {
718
  $wrappers = array(
719 720
    'public' => array(
      'name' => t('Public files'),
webchick's avatar
webchick committed
721
      'class' => 'Drupal\Core\StreamWrapper\PublicStream',
722
      'description' => t('Public local files served by the webserver.'),
723
      'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
724 725 726
    ),
    'temporary' => array(
      'name' => t('Temporary files'),
webchick's avatar
webchick committed
727
      'class' => 'Drupal\Core\StreamWrapper\TemporaryStream',
728
      'description' => t('Temporary local files for upload and previews.'),
729
      'type' => STREAM_WRAPPERS_LOCAL_HIDDEN,
730
    ),
731
  );
732 733

  // Only register the private file stream wrapper if a file path has been set.
734
  if (\Drupal::config('system.file')->get('path.private')) {
735 736
    $wrappers['private'] = array(
      'name' => t('Private files'),
webchick's avatar
webchick committed
737
      'class' => 'Drupal\Core\StreamWrapper\PrivateStream',
738
      'description' => t('Private local files served by Drupal.'),
739
      'type' => STREAM_WRAPPERS_LOCAL_NORMAL,
740 741 742 743
    );
  }

  return $wrappers;
744 745
}

746
/**
747
 * Menu item access callback - only enabled themes can be accessed.
748 749
 */
function _system_themes_access($theme) {
750
  return user_access('administer themes') && drupal_theme_access($theme);