Example #1
0
/**
 * Add the installation task list to the current page.
 */
function install_task_list($active = NULL)
{
    // Default list of tasks.
    $tasks = array('profile-select' => st('Choose profile'), 'locale-select' => st('Choose language'), 'requirements' => st('Verify requirements'), 'database' => st('Set up database'), 'profile-install-batch' => st('Install profile'), 'locale-initial-batch' => st('Set up translations'), 'configure' => st('Configure site'));
    $profiles = install_find_profiles();
    $profile = isset($_GET['profile']) && isset($profiles[$_GET['profile']]) ? $_GET['profile'] : '.';
    $locales = install_find_locales($profile);
    // If we have only one profile, remove 'Choose profile'
    // and rename 'Install profile'.
    if (count($profiles) == 1) {
        unset($tasks['profile-select']);
        $tasks['profile-install-batch'] = st('Install site');
    }
    // Add tasks defined by the profile.
    if ($profile) {
        $function = $profile . '_profile_task_list';
        if (function_exists($function)) {
            $result = $function();
            if (is_array($result)) {
                $tasks += $result;
            }
        }
    }
    if (count($locales) < 2 || empty($_GET['locale']) || $_GET['locale'] == 'en') {
        // If not required, remove translation import from the task list.
        unset($tasks['locale-initial-batch']);
    } else {
        // If required, add remaining translations import task.
        $tasks += array('locale-remaining-batch' => st('Finish translations'));
    }
    // Add finished step as the last task.
    $tasks += array('finished' => st('Finished'));
    // Let the theming function know that 'finished' and 'done'
    // include everything, so every step is completed.
    if (in_array($active, array('finished', 'done'))) {
        $active = NULL;
    }
    drupal_set_content('left', theme_task_list($tasks, $active));
}
Example #2
0
/**
 * Installation task; select which locale to use for the current profile.
 *
 * @param $install_state
 *   An array of information about the current installation state. The chosen
 *   locale will be added here, if it was not already selected previously, as
 *   will a list of all available locales.
 * @return
 *   For interactive installations, a form or other page output allowing the
 *   locale to be selected or providing information about locale selection, if
 *   a locale has not been chosen. Otherwise, an exception is thrown if a
 *   locale cannot be chosen automatically.
 */
function install_select_locale(&$install_state)
{
    // Find all available locales.
    $profilename = $install_state['parameters']['profile'];
    $locales = install_find_locales($profilename);
    $install_state['locales'] += $locales;
    if (empty($install_state['parameters']['locale'])) {
        // If only the built-in (English) language is available, and we are using
        // the default profile and performing an interactive installation, inform
        // the user that the installer can be localized. Otherwise we assume the
        // user knows what he is doing.
        if (count($locales) == 1) {
            if ($profilename == 'default' && $install_state['interactive']) {
                drupal_set_title(st('Choose language'));
                if (!empty($install_state['parameters']['localize'])) {
                    $output = '<p>' . st('With the addition of an appropriate translation package, this installer is capable of proceeding in another language of your choice. To install and use Drupal in a language other than English:') . '</p>';
                    $output .= '<ul><li>' . st('Determine if <a href="@translations" target="_blank">a translation of this Drupal version</a> is available in your language of choice. A translation is provided via a translation package; each translation package enables the display of a specific version of Drupal in a specific language. Not all languages are available for every version of Drupal.', array('@translations' => 'http://drupal.org/project/translations')) . '</li>';
                    $output .= '<li>' . st('If an alternative translation package of your choice is available, download and extract its contents to your Drupal root directory.') . '</li>';
                    $output .= '<li>' . st('Return to choose language using the second link below and select your desired language from the displayed list. Reloading the page allows the list to automatically adjust to the presence of new translation packages.') . '</li>';
                    $output .= '</ul><p>' . st('Alternatively, to install and use Drupal in English, or to defer the selection of an alternative language until after installation, select the first link below.') . '</p>';
                    $output .= '<p>' . st('How should the installation continue?') . '</p>';
                    $output .= '<ul><li><a href="install.php?profile=' . $profilename . '&amp;locale=en">' . st('Continue installation in English') . '</a></li><li><a href="install.php?profile=' . $profilename . '">' . st('Return to choose a language') . '</a></li></ul>';
                } else {
                    $output = '<ul><li><a href="install.php?profile=' . $profilename . '&amp;locale=en">' . st('Install Drupal in English') . '</a></li><li><a href="install.php?profile=' . $profilename . '&amp;localize=true">' . st('Learn how to install Drupal in other languages') . '</a></li></ul>';
                }
                return $output;
            }
            // One language, but not the default profile or not an interactive
            // installation. Assume the user knows what he is doing.
            $locale = current($locales);
            $install_state['parameters']['locale'] = $locale->name;
            return;
        } else {
            // Allow profile to pre-select the language, skipping the selection.
            $function = $profilename . '_profile_details';
            if (function_exists($function)) {
                $details = $function();
                if (isset($details['language'])) {
                    foreach ($locales as $locale) {
                        if ($details['language'] == $locale->name) {
                            $install_state['parameters']['locale'] = $locale->name;
                            return;
                        }
                    }
                }
            }
            if (!empty($_POST['locale'])) {
                foreach ($locales as $locale) {
                    if ($_POST['locale'] == $locale->name) {
                        $install_state['parameters']['locale'] = $locale->name;
                        return;
                    }
                }
            }
            // We still don't have a locale, so display a form for selecting one.
            // Only do this in the case of interactive installations, since this is
            // not a real form with submit handlers (the database isn't even set up
            // yet), rather just a convenience method for setting parameters in the
            // URL.
            if ($install_state['interactive']) {
                drupal_set_title(st('Choose language'));
                include_once DRUPAL_ROOT . '/includes/form.inc';
                return drupal_render(drupal_get_form('install_select_locale_form', $locales));
            } else {
                throw new Exception(st('Sorry, you must select a language to continue the installation.'));
            }
        }
    }
}