1 system.admin.inc system_site_information_settings($form, &$form_state)

Form builder; The general site information form.

Related topics

File

core/modules/system/system.admin.inc, line 1244
Admin page callbacks for the System module.

Code

function system_site_information_settings($form, &$form_state) {
  $site_config = config('system.core');
  $site_mail = $site_config->get('site_mail');
  if (empty($site_mail)) {
    $site_mail = ini_get('sendmail_from');
  }

  $form['#config'] = 'system.core';
  $form['site_information'] = array(
    '#type' => 'fieldset',
    '#title' => t('Site details'),
  );
  $form['site_information']['site_name'] = array(
    '#type' => 'textfield',
    '#title' => t('Site name'),
    '#default_value' => $site_config->get('site_name'),
    '#required' => TRUE
  );

  // Logo settings
  $form['logo'] = array(
    '#type' => 'fieldset',
    '#title' => t('Logo settings'),
    '#attributes' => array('class' => array('theme-settings-bottom')),
  );
  $form['logo']['site_logo_theme'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use the logo supplied by the active theme'),
    '#default_value' => $site_config->get('site_logo_theme'),
    '#tree' => FALSE,
  );
  $form['logo']['settings'] = array(
    '#type' => 'container',
    '#states' => array(
      // Hide the logo settings when using the default logo.
      'invisible' => array(
        'input[name="site_logo_theme"]' => array('checked' => TRUE),
      ),
    ),
  );
  $form['logo']['settings']['site_logo_upload'] = array(
    '#type' => 'file',
    '#title' => t('Upload logo'),
    '#maxlength' => 60,
  );
  $form['logo']['settings']['site_logo_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to custom logo'),
    '#default_value' => $site_config->get('site_logo_path'),
  );

  $form['favicon'] = array(
    '#type' => 'fieldset',
    '#title' => t('Shortcut icon settings'),
    '#description' => t("Your shortcut icon, or 'favicon', is displayed in the address bar and bookmarks of most browsers."),
  );
  $form['favicon']['site_favicon_theme'] = array(
    '#type' => 'checkbox',
    '#title' => t('Use the shortcut icon supplied by the active theme'),
    '#default_value' => $site_config->get('site_favicon_theme'),
  );
  $form['favicon']['settings'] = array(
    '#type' => 'container',
    '#states' => array(
      // Hide the favicon settings when using the default favicon.
      'invisible' => array(
        'input[name="site_favicon_theme"]' => array('checked' => TRUE),
      ),
    ),
  );
  $form['favicon']['settings']['site_favicon_upload'] = array(
    '#type' => 'file',
    '#title' => t('Upload icon'),
    '#maxlength' => 60,
  );
  $form['favicon']['settings']['site_favicon_path'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to custom icon'),
    '#default_value' => $site_config->get('site_favicon_path'),
  );

  $form['site_information']['site_slogan'] = array(
    '#type' => 'textfield',
    '#title' => t('Slogan'),
    '#default_value' => $site_config->get('site_slogan'),
    '#description' => t("How this is used depends on your site's theme."),
  );

  $form['site_information']['site_mail'] = array(
    '#type' => 'email',
    '#title' => t('Email address'),
    '#default_value' => $site_mail,
    '#description' => t("The <em>From</em> address in automated emails sent during registration and new password requests, and other notifications. (Use an address ending in your site's domain to help prevent this email being flagged as spam.)"),
    '#required' => TRUE,
  );

  $form['front_page'] = array(
    '#type' => 'fieldset',
    '#title' => t('Home page'),
  );
  $form['front_page']['site_frontpage'] = array(
    '#type' => 'textfield',
    '#title' => t('Path to use for the home page'),
    '#required' => TRUE,
    '#default_value' => backdrop_get_path_alias($site_config->get('site_frontpage')),
    '#size' => 40,
    '#field_prefix' => url(NULL, array('absolute' => TRUE)) . ($site_config->get('clean_url') ? '' : '?q='),
    '#autocomplete_path' => 'path-autocomplete',
  );
  $form['front_page']['default_nodes_main'] = array(
    '#type' => 'select',
    '#title' => t('Number of posts on home page'),
    '#default_value' => $site_config->get('default_nodes_main'),
    '#options' => backdrop_map_assoc(array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 15, 20, 25, 30)),
    '#description' => t('The maximum number of posts displayed on overview pages such as the home page.'),
    '#access' => ($site_config->get('site_frontpage') == 'node'),
  );
  $form['error_page'] = array(
    '#type' => 'fieldset',
    '#title' => t('Error pages'),
  );
  $form['error_page']['site_403'] = array(
    '#type' => 'textfield',
    '#title' => t('Default 403 (access denied) page'),
    '#default_value' => ($site_config->get('site_403') != '' ? backdrop_get_path_alias($site_config->get('site_403')) : ''),
    '#size' => 40,
    '#description' => t('This page is displayed when the requested document is denied to the current user. Leave blank to display a generic "access denied" page.'),
    '#field_prefix' => url(NULL, array('absolute' => TRUE)) . ($site_config->get('clean_url') ? '' : '?q='),
    '#autocomplete_path' => 'path-autocomplete',
  );
  $form['error_page']['site_404'] = array(
    '#type' => 'textfield',
    '#title' => t('Default 404 (not found) page'),
    '#default_value' => ($site_config->get('site_404') != '' ? backdrop_get_path_alias($site_config->get('site_404')) : ''),
    '#size' => 40,
    '#description' => t('This page is displayed when no other content matches the requested document. Leave blank to display a generic "page not found" page.'),
    '#field_prefix' => url(NULL, array('absolute' => TRUE)) . ($site_config->get('clean_url') ? '' : '?q='),
    '#autocomplete_path' => 'path-autocomplete',
  );

  $form['#validate'][] = 'system_site_information_settings_validate';
  $form['#submit'][] = 'system_site_information_settings_submit';

  // Inject human-friendly form element descriptions for logo and favicon.
  foreach (array('logo' => 'logo.png', 'favicon' => 'favicon.ico') as $type => $default) {
    if (isset($form[$type]['settings']['site_' . $type . '_path'])) {
      $element = &$form[$type]['settings']['site_' . $type . '_path'];

      // If path is a public:// URI, display the path relative to the files
      // directory; stream wrappers are not end-user friendly.
      $original_path = $element['#default_value'];
      $friendly_path = NULL;
      if (file_uri_scheme($original_path) == 'public') {
        $friendly_path = file_uri_target($original_path);
        $element['#default_value'] = $friendly_path;
      }

      // Prepare local file path for description.
      if ($original_path && isset($friendly_path)) {
        $local_file = strtr($original_path, array('public:/' => $site_config->get('file_public_path')));
      }
      else {
        $local_file = path_to_theme() . '/' . $default;
      }

      $element['#description'] = t('Examples: <code>@implicit-public-file</code> (for a file in the public filesystem), <code>@explicit-file</code>, or <code>@local-file</code>.', array(
        '@implicit-public-file' => isset($friendly_path) ? $friendly_path : $default,
        '@explicit-file' => file_uri_scheme($original_path) !== FALSE ? $original_path : 'public://' . $default,
        '@local-file' => $local_file,
      ));
    }
  }

  return system_settings_form($form);
}